goods.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: 'shop_goods',
  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. sortable: true,
  23. sort: 'desc',
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('ID'), width: 80},
  28. {field: 'title', title: __('商品信息'), operate: 'LIKE', width: 350, formatter: function(value, row, index) {
  29. var html = '<div style="display: flex; align-items: center; padding: 5px 0;">';
  30. // 商品图片
  31. var imageUrl = row.image || '/assets/img/goods-default.png';
  32. html += '<div style="margin-right: 12px; flex-shrink: 0;">';
  33. html += '<img src="' + imageUrl + '" style="width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #e9ecef;" />';
  34. html += '</div>';
  35. // 商品信息
  36. html += '<div style="flex: 1; min-width: 0;">';
  37. // 商品标题
  38. var goodsTitle = row.title || '-';
  39. html += '<div style="color: #337ab7; font-weight: bold; margin-bottom: 4px; line-height: 1.4;">';
  40. html += '<a href="javascript:;" class="goods-title" style="color: #337ab7; text-decoration: none;">';
  41. html += goodsTitle;
  42. html += '</a></div>';
  43. // 商品副标题/描述
  44. if (row.subtitle) {
  45. html += '<div style="color: #6c757d; font-size: 12px; margin-bottom: 4px; line-height: 1.2;">' + row.subtitle + '</div>';
  46. }
  47. // 商品分类或其他信息
  48. html += '<div style="color: #999; font-size: 11px;">';
  49. html += 'ID: ' + row.id;
  50. if (row.category_name) {
  51. html += ' | ' + row.category_name;
  52. }
  53. html += '</div>';
  54. html += '</div></div>';
  55. return html;
  56. }},
  57. {field: 'price', title: __('价格'), operate: 'BETWEEN', width: 100},
  58. {field: 'commission_goods.rule_type', title: __('分销规则'), width: 120, formatter: function(value, row, index) {
  59. // 如果没有分销配置,默认为不参与
  60. if (!row.commission_goods) {
  61. return '<span class="label label-danger">不参与</span>';
  62. }
  63. var participateStatus = row.commission_goods.status;
  64. if (participateStatus == 0) {
  65. return '<span class="label label-danger">不参与</span>';
  66. }
  67. var ruleTypeList = Config.commission_goods_rule_type_list || {
  68. '0': '默认规则',
  69. '1': '独立规则',
  70. '2': '批量规则'
  71. };
  72. var colorMap = {
  73. '0': 'info',
  74. '1': 'success',
  75. '2': 'warning'
  76. };
  77. var text = ruleTypeList[value] || '默认规则';
  78. var color = colorMap[value] || 'info';
  79. return '<span class="label label-' + color + '">' + text + '</span>';
  80. }},
  81. {field: 'status', title: __('商品状态'), width: 100, formatter: function(value, row, index) {
  82. var statusMap = {
  83. 'normal': {text: '上架中', color: 'success'},
  84. 'hidden': {text: '下架', color: 'danger'},
  85. 'pulloff': {text: '下架', color: 'danger'}
  86. };
  87. var status = statusMap[value] || {text: '未知', color: 'default'};
  88. return '<span class="label label-' + status.color + '">' + status.text + '</span>';
  89. }},
  90. {field: 'operate', title: __('操作'), table: table, events: Table.api.events.operate, width: 150,
  91. buttons: [
  92. {
  93. name: 'detail',
  94. text: __('详情'),
  95. title: __('商品详情'),
  96. classname: 'btn btn-xs btn-primary',
  97. icon: 'fa fa-list',
  98. click: function (data) {
  99. Fast.api.open('commission/goods/detail?id=' + data.id, '商品详情', {
  100. area: ['90%', '90%']
  101. });
  102. }
  103. },
  104. {
  105. name: 'edit',
  106. text: __('设置佣金'),
  107. title: __('设置佣金'),
  108. classname: 'btn btn-xs btn-success',
  109. icon: 'fa fa-edit',
  110. click: function (data) {
  111. Fast.api.open('commission/goods/edit?ids=' + data.id, '设置佣金', {
  112. area: ['90%', '90%'],
  113. callback: function(data) {
  114. table.bootstrapTable('refresh');
  115. }
  116. });
  117. }
  118. }
  119. ],
  120. formatter: Table.api.formatter.operate}
  121. ]
  122. ]
  123. });
  124. // 为表格绑定事件
  125. Table.api.bindevent(table);
  126. // 批量设置佣金
  127. $(document).on('click', '.btn-batch-commission', function() {
  128. var ids = Table.api.selectedids(table);
  129. if (ids.length == 0) {
  130. Toastr.error('请先选择要设置的商品');
  131. return false;
  132. }
  133. Fast.api.open('commission/goods/edit?ids=' + ids.join(','), '批量设置佣金', {
  134. area: ['90%', '90%'],
  135. callback: function(data) {
  136. table.bootstrapTable('refresh');
  137. }
  138. });
  139. });
  140. },
  141. detail: function () {
  142. Controller.api.bindevent();
  143. },
  144. edit: function () {
  145. Controller.api.bindevent();
  146. },
  147. api: {
  148. bindevent: function () {
  149. Form.api.bindevent($("form[role=form]"));
  150. // 绑定独立设置变化事件
  151. $(document).on('change', 'input[name="row[self_rules]"]', function() {
  152. var value = $(this).val();
  153. var commissionConfigContainer = $('.commission-config-container');
  154. if (value == '1') {
  155. commissionConfigContainer.show();
  156. } else {
  157. commissionConfigContainer.hide();
  158. }
  159. });
  160. }
  161. }
  162. };
  163. return Controller;
  164. });