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 = '
';
// 商品图片
var imageUrl = row.image || '/assets/img/goods-default.png';
html += '
';
html += '

';
html += '
';
// 商品信息
html += '
';
// 商品标题
var goodsTitle = row.title || '-';
html += '
';
// 商品副标题/描述
if (row.subtitle) {
html += '
' + row.subtitle + '
';
}
// 商品分类或其他信息
html += '
';
html += 'ID: ' + row.id;
if (row.category_name) {
html += ' | ' + row.category_name;
}
html += '
';
html += '
';
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 '不参与';
}
var participateStatus = row.commission_goods.status;
if (participateStatus == 0) {
return '不参与';
}
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 '' + text + '';
}},
{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 '' + status.text + '';
}},
{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;
});