cardcode.js 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. let itemid = $("#item-id").val();
  6. if (itemid > 0) {
  7. Table.api.init({
  8. extend: {
  9. index_url: 'pickup/cardcode/index/ids/' + itemid + location.search,
  10. add_url: 'pickup/cardcode/add/gpid/' + itemid,
  11. edit_url: 'pickup/cardcode/edit/gpid/' + itemid,
  12. batchcreate_url: 'pickup/cardcode/batchcreate/gpid/' + itemid,
  13. batchexport_url: 'pickup/cardcode/batchexport/gpid/' + itemid,
  14. del_url: 'pickup/cardcode/del/',
  15. multi_url: 'pickup/cardcode/multi',
  16. table: 'gift_cardcode',
  17. },
  18. pageSize: 30,
  19. pageList: [30, 50, 100, 'All'],
  20. });
  21. } else {
  22. Table.api.init({
  23. extend: {
  24. index_url: 'pickup/cardcode/index' + location.search,
  25. add_url: 'pickup/cardcode/add',
  26. edit_url: 'pickup/cardcode/edit',
  27. batchcreate_url: 'pickup/cardcode/batchcreate',
  28. batchexport_url: 'pickup/cardcode/batchexport',
  29. del_url: 'pickup/cardcode/del',
  30. multi_url: 'pickup/cardcode/multi',
  31. table: 'gift_cardcode',
  32. },
  33. pageSize: 30,
  34. pageList: [30, 50, 100, 'All'],
  35. });
  36. }
  37. var table = $("#table");
  38. // 初始化表格
  39. table.bootstrapTable({
  40. url: $.fn.bootstrapTable.defaults.extend.index_url,
  41. pk: 'id',
  42. sortName: 'id',
  43. columns: [
  44. [
  45. {checkbox: true},
  46. {field: 'id', title: __('Id')},
  47. // {field: 'gp_id', title: __('Gp_id')},
  48. {field: 'card_id', title: __('Card_id')},
  49. {field: 'card_pwd', title: __('Card_pwd')},
  50. {field: 'card_status', title: __('Card_status'), searchList: {"1": __('Card_status 1'), "2": __('Card_status 2'), "3": __('Card_status 3'), "4": __('Card_status 4')}, formatter: Table.api.formatter.status},
  51. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  52. {field: 'usedtime', title: __('Usedtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  53. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  54. ]
  55. ]
  56. });
  57. // 为表格绑定事件
  58. Table.api.bindevent(table);
  59. // 添加按钮事件
  60. $(".toolbar").on('click', ".btn-batchcreate", function () {
  61. var ids = Table.api.selectedids(table);
  62. var url = $.fn.bootstrapTable.defaults.extend.batchcreate_url;
  63. Fast.api.open(url, __('卡密批量生成'), $(this).data() || {});
  64. });
  65. },
  66. add: function () {
  67. Controller.api.bindevent();
  68. },
  69. edit: function () {
  70. Controller.api.bindevent();
  71. },
  72. batchcreate: function () {
  73. Controller.api.bindevent();
  74. },
  75. api: {
  76. bindevent: function () {
  77. Form.api.bindevent($("form[role=form]"));
  78. }
  79. }
  80. };
  81. return Controller;
  82. });