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": "普通代理商", "regional": "区域代理商"}, formatter: function(value, row, index) { if (row.agent_type === 'regional') { return '' + value + ''; } else { return '' + value + ''; } }}, {field: 'regional_commission_rate', title: __('Regional rate'), operate: false, formatter: function(value, row, index) { if (row.agent_type === 'regional' && value > 0) { return value + '%'; } return row.agent_type === 'regional' ? '0.00%' : '-'; }}, {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'); if (agentType === 'regional') { 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(); if (checkedAgentType === 'regional') { $('#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; });