define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数 Table.api.init({ extend: { index_url: 'commission/identity/index', add_url: 'commission/identity/add', edit_url: 'commission/identity/edit', del_url: 'commission/identity/del', multi_url: 'commission/identity/multi', table: 'shop_commission_identity', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'weigh', sortOrder: 'asc', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id'), sortable: true}, {field: 'name', title: __('Name'), operate: 'LIKE', formatter: Table.api.formatter.search}, {field: 'level', title: __('Level'), sortable: true}, {field: 'agent_type_text', title: __('Agent type'), searchList: {"normal": "普通代理商", "province": "省级代理商", "city": "市级代理商", "district": "区域代理商"}, formatter: function(value, row, index) { var colorMap = { 'province': 'danger', // 省级-红色 'city': 'warning', // 市级-橙色 'district': 'info', // 区域-蓝色 'normal': 'default' // 普通-默认 }; var color = colorMap[row.agent_type] || 'default'; return '' + value + ''; }}, {field: 'regional_commission_rate', title: __('Regional rate'), operate: false, formatter: function(value, row, index) { // 区域代理商(非normal类型)显示分佣比例 if (['province', 'city', 'district'].indexOf(row.agent_type) !== -1) { return (value || 0) + '%'; } return '-'; }}, {field: 'description', title: __('Description'), operate: 'LIKE'}, {field: 'status', title: __('Status'), searchList: {"0": __('Hidden'), "1": __('Shown')}, formatter: Table.api.formatter.status}, {field: 'weigh', title: __('Weigh'), sortable: true, operate: false}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); // 代理商类型切换事件 $(document).on('change', 'input[name="row[agent_type]"]', function() { var agentType = $(this).val(); var rateGroup = $('#regional-rate-group'); var regionalTypes = ['province', 'city', 'district']; if (regionalTypes.indexOf(agentType) !== -1) { rateGroup.show(); rateGroup.find('input').attr('data-rule', 'required;range(0~100)'); } else { rateGroup.hide(); rateGroup.find('input').removeAttr('data-rule'); rateGroup.find('input').val('0.00'); } }); // 页面加载时初始化显示状态 var checkedAgentType = $('input[name="row[agent_type]"]:checked').val(); var regionalTypes = ['province', 'city', 'district']; if (regionalTypes.indexOf(checkedAgentType) !== -1) { $('#regional-rate-group').show(); $('#regional-rate-group').find('input').attr('data-rule', 'required;range(0~100)'); } else { $('#regional-rate-group').hide(); $('#regional-rate-group').find('input').removeAttr('data-rule'); } } } }; return Controller; });