coupon.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'coupon/index' + location.search,
  8. add_url: 'coupon/add',
  9. edit_url: 'coupon/edit',
  10. del_url: 'coupon/del',
  11. multi_url: 'coupon/multi',
  12. import_url: 'coupon/import',
  13. send_url: 'coupon/send',
  14. table: 'coupon',
  15. }
  16. });
  17. var table = $("#table");
  18. var extend = $.fn.bootstrapTable.defaults.extend;
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'name', title: __('名称'), operate:'like'},
  29. {field: 'type', title: __('类型'),searchList:types,formatter: Table.api.formatter.label},
  30. {field: 'amount', title: __('金额'), operate:'BETWEEN'},
  31. {field: 'amount_full', title: __('金额'), operate:'BETWEEN'},
  32. {field: 'num', title: __('Num')},
  33. {field: 'num_send', title: __('Num_send')},
  34. {field: 'time_start', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  35. {field: 'time_end', title: __('过期时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  36. {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  37. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  38. ]
  39. ]
  40. });
  41. // 为表格绑定事件
  42. Table.api.bindevent(table);
  43. $('.btn-add').data('area',["100%","100%"])
  44. $('.btn-send').click(function (){
  45. let id=[]
  46. table.bootstrapTable('getSelections').forEach(item=>{
  47. id.push(item.id)
  48. })
  49. Fast.api.open(extend.send_url+`/ids/${id.join(',')}`,$(this).text())
  50. })
  51. },
  52. add: function () {
  53. Controller.api.bindevent();
  54. //$('.couponType').find('input').eq(0).trigger('click')
  55. $('.couponType').find('input[type="radio"]').change(function (){
  56. if(this.value==1){
  57. $('.amountFull').show()
  58. }else{
  59. $('.amountFull').hide()
  60. }
  61. })
  62. },
  63. edit: function () {
  64. Controller.api.bindevent();
  65. },
  66. send(){
  67. Controller.api.bindevent();
  68. },
  69. api: {
  70. bindevent: function () {
  71. Form.api.bindevent($("form[role=form]"));
  72. }
  73. }
  74. };
  75. return Controller;
  76. });