goods.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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: 'commission/goods/index' + location.search,
  8. add_url: '',
  9. edit_url: 'commission/goods/edit',
  10. del_url: 'commission/goods/del',
  11. multi_url: 'commission/goods/multi',
  12. import_url: 'commission/goods/import',
  13. table: 'commission_goods',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'goods_id',
  21. sortName: 'goods_id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'goods_id', title: __('商品ID'), width: 80},
  26. {field: 'title', title: __('商品名称'), operate: 'LIKE'},
  27. {field: 'image', title: __('商品图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  28. {field: 'price', title: __('商品价格'), operate: 'BETWEEN'},
  29. {field: 'commission_goods.status', title: __('分销状态'), searchList: {
  30. "0": __('不参与分销'),
  31. "1": __('参与分销')
  32. }, formatter: function(value, row, index) {
  33. var statusMap = {
  34. '0': {text: '不参与分销', color: 'danger'},
  35. '1': {text: '参与分销', color: 'success'}
  36. };
  37. var status = statusMap[value] || {text: '不参与分销', color: 'danger'};
  38. return '<span class="label label-' + status.color + '">' + status.text + '</span>';
  39. }},
  40. {field: 'commission_goods.self_rules', title: __('独立设置'), formatter: function(value, row, index) {
  41. var selfRulesMap = {
  42. '0': {text: '否', color: 'info'},
  43. '1': {text: '是', color: 'success'}
  44. };
  45. var selfRules = selfRulesMap[value] || {text: '否', color: 'info'};
  46. return '<span class="label label-' + selfRules.color + '">' + selfRules.text + '</span>';
  47. }},
  48. {field: 'commission_goods.commission_order_status', title: __('是否计入业绩'), formatter: function(value, row, index) {
  49. var orderStatusMap = {
  50. '0': {text: '否', color: 'danger'},
  51. '1': {text: '是', color: 'success'}
  52. };
  53. var orderStatus = orderStatusMap[value] || {text: '是', color: 'success'};
  54. return '<span class="label label-' + orderStatus.color + '">' + orderStatus.text + '</span>';
  55. }},
  56. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  57. buttons: [
  58. {
  59. name: 'detail',
  60. text: __('详情'),
  61. title: __('商品详情'),
  62. classname: 'btn btn-xs btn-primary btn-dialog',
  63. icon: 'fa fa-list',
  64. url: 'commission/goods/detail',
  65. callback: function (data) {
  66. table.bootstrapTable('refresh');
  67. }
  68. },
  69. {
  70. name: 'edit',
  71. text: __('设置佣金'),
  72. title: __('设置佣金'),
  73. classname: 'btn btn-xs btn-success btn-editone',
  74. icon: 'fa fa-edit',
  75. url: 'commission/goods/edit',
  76. callback: function (data) {
  77. table.bootstrapTable('refresh');
  78. }
  79. }
  80. ],
  81. formatter: Table.api.formatter.operate}
  82. ]
  83. ]
  84. });
  85. // 为表格绑定事件
  86. Table.api.bindevent(table);
  87. },
  88. detail: function () {
  89. Controller.api.bindevent();
  90. },
  91. edit: function () {
  92. Controller.api.bindevent();
  93. },
  94. api: {
  95. bindevent: function () {
  96. Form.api.bindevent($("form[role=form]"));
  97. // 绑定独立设置变化事件
  98. $(document).on('change', 'input[name="row[self_rules]"]', function() {
  99. var value = $(this).val();
  100. var commissionConfigContainer = $('.commission-config-container');
  101. if (value == '1') {
  102. commissionConfigContainer.show();
  103. } else {
  104. commissionConfigContainer.hide();
  105. }
  106. });
  107. }
  108. }
  109. };
  110. return Controller;
  111. });