123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数
- Table.api.init({
- extend: {
- index_url: 'commission/goods/index' + location.search,
- add_url: '',
- edit_url: 'commission/goods/edit',
- del_url: 'commission/goods/del',
- multi_url: 'commission/goods/multi',
- import_url: 'commission/goods/import',
- table: 'shop_goods',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- sortable: true,
- sort: 'desc',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('ID'), width: 80},
- {field: 'title', title: __('商品信息'), operate: 'LIKE', width: 350, formatter: function(value, row, index) {
- var html = '<div style="display: flex; align-items: center; padding: 5px 0;">';
-
- // 商品图片
- var imageUrl = row.image || '/assets/img/goods-default.png';
- html += '<div style="margin-right: 12px; flex-shrink: 0;">';
- html += '<img src="' + imageUrl + '" style="width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #e9ecef;" />';
- html += '</div>';
-
- // 商品信息
- html += '<div style="flex: 1; min-width: 0;">';
-
- // 商品标题
- var goodsTitle = row.title || '-';
- html += '<div style="color: #337ab7; font-weight: bold; margin-bottom: 4px; line-height: 1.4;">';
- html += '<a href="javascript:;" class="goods-title" style="color: #337ab7; text-decoration: none;">';
- html += goodsTitle;
- html += '</a></div>';
-
- // 商品副标题/描述
- if (row.subtitle) {
- html += '<div style="color: #6c757d; font-size: 12px; margin-bottom: 4px; line-height: 1.2;">' + row.subtitle + '</div>';
- }
-
- // 商品分类或其他信息
- html += '<div style="color: #999; font-size: 11px;">';
- html += 'ID: ' + row.id;
- if (row.category_name) {
- html += ' | ' + row.category_name;
- }
- html += '</div>';
-
- html += '</div></div>';
- return html;
- }},
- {field: 'price', title: __('价格'), operate: 'BETWEEN', width: 100},
- {field: 'commission_goods.rule_type', title: __('分销规则'), width: 120, formatter: function(value, row, index) {
- // 如果没有分销配置,默认为不参与
- if (!row.commission_goods) {
- return '<span class="label label-danger">不参与</span>';
- }
-
- var participateStatus = row.commission_goods.status;
- if (participateStatus == 0) {
- return '<span class="label label-danger">不参与</span>';
- }
-
- var ruleTypeList = Config.commission_goods_rule_type_list || {
- '0': '默认规则',
- '1': '独立规则',
- '2': '批量规则'
- };
- var colorMap = {
- '0': 'info',
- '1': 'success',
- '2': 'warning'
- };
- var text = ruleTypeList[value] || '默认规则';
- var color = colorMap[value] || 'info';
- return '<span class="label label-' + color + '">' + text + '</span>';
- }},
- {field: 'status', title: __('商品状态'), width: 100, formatter: function(value, row, index) {
- var statusMap = {
- 'normal': {text: '上架中', color: 'success'},
- 'hidden': {text: '下架', color: 'danger'},
- 'pulloff': {text: '下架', color: 'danger'}
- };
- var status = statusMap[value] || {text: '未知', color: 'default'};
- return '<span class="label label-' + status.color + '">' + status.text + '</span>';
- }},
- {field: 'operate', title: __('操作'), table: table, events: Table.api.events.operate, width: 150,
- buttons: [
- {
- name: 'detail',
- text: __('详情'),
- title: __('商品详情'),
- classname: 'btn btn-xs btn-primary',
- icon: 'fa fa-list',
- click: function (data) {
- Fast.api.open('commission/goods/detail?id=' + data.id, '商品详情', {
- area: ['90%', '90%']
- });
- }
- },
- {
- name: 'edit',
- text: __('设置佣金'),
- title: __('设置佣金'),
- classname: 'btn btn-xs btn-success',
- icon: 'fa fa-edit',
- click: function (data) {
- Fast.api.open('commission/goods/edit?ids=' + data.id, '设置佣金', {
- area: ['90%', '90%'],
- callback: function(data) {
- table.bootstrapTable('refresh');
- }
- });
- }
- }
- ],
- formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
-
- // 批量设置佣金
- $(document).on('click', '.btn-batch-commission', function() {
- var ids = Table.api.selectedids(table);
- if (ids.length == 0) {
- Toastr.error('请先选择要设置的商品');
- return false;
- }
-
- Fast.api.open('commission/goods/edit?ids=' + ids.join(','), '批量设置佣金', {
- area: ['90%', '90%'],
- callback: function(data) {
- table.bootstrapTable('refresh');
- }
- });
- });
- },
- detail: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
-
- // 绑定独立设置变化事件
- $(document).on('change', 'input[name="row[self_rules]"]', function() {
- var value = $(this).val();
- var commissionConfigContainer = $('.commission-config-container');
- if (value == '1') {
- commissionConfigContainer.show();
- } else {
- commissionConfigContainer.hide();
- }
- });
- }
- }
- };
- return Controller;
- });
|