coupon.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. table: 'coupon',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'coupon_type', title: __('Coupon_type'), searchList: {"1":__('Coupon_type 1'),"2":__('Coupon_type 2'),"3":__('Coupon_type 3')}, formatter: Table.api.formatter.normal},
  27. {field: 'coupon_name', title: __('Coupon_name'), searchList: {"1":__('Coupon_name 1'),"2":__('Coupon_name 2')}, formatter: Table.api.formatter.normal},
  28. {field: 'coupon_price', title: __('Coupon_price'), operate:'BETWEEN'},
  29. {field: 'limit_price', title: __('Limit_price'), operate:'BETWEEN'},
  30. {field: 'expiration', title: __('Expiration'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  31. {field: 'coupon_status', title: __('Coupon_status'), searchList: {"0":__('Coupon_status 0'),"1":__('Coupon_status 1')}, formatter: Table.api.formatter.status},
  32. {field: 'buttons',
  33. title: __('发放优惠券'),
  34. table: table,
  35. events: Table.api.events.operate,
  36. formatter: function (value, data) {
  37. return '<a data-area=["80%","80%"] href="coupon/issue_user?ids=' + data.id + '" title="发放" class="btn btn-xs btn-success btn-dialog"> 发放 </a>';
  38. }
  39. },
  40. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  41. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
  42. var that = $.extend({}, this);
  43. var table = $(that.table).clone(true);
  44. $(table).data("operate-del", null);
  45. that.table = table;
  46. return Table.api.formatter.operate.call(that, value, row, index);
  47. }}
  48. ]
  49. ]
  50. });
  51. // 为表格绑定事件
  52. Table.api.bindevent(table);
  53. },
  54. add: function () {
  55. Controller.api.bindevent();
  56. },
  57. edit: function () {
  58. Controller.api.bindevent();
  59. },
  60. issue_user: function () {
  61. Controller.api.bindevent();
  62. },
  63. api: {
  64. bindevent: function () {
  65. Form.api.bindevent($("form[role=form]"));
  66. }
  67. }
  68. };
  69. return Controller;
  70. });