define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var stateList = {}; var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'inspection/factory/index' + location.search, add_url: 'inspection/factory/add', edit_url: 'inspection/factory/edit', del_url: 'inspection/factory/del', multi_url: 'inspection/factory/multi', import_url: 'inspection/factory/import', table: 'factory', } }); var table = $("#table"); var statusSearchList = {}; if (Config.statusSearchList) { try { if (typeof Config.statusSearchList === 'string') { statusSearchList = JSON.parse(Config.statusSearchList); } else { statusSearchList = Config.statusSearchList; } } catch (e) { console.error('Parse statusSearchList error:', e); } } for (var key in statusSearchList) { if (statusSearchList.hasOwnProperty(key)) { stateList[key] = { text: statusSearchList[key], class: key == 1 ? 'label-success' : 'label-info', icon: key == 1 ? 'fa fa-check' : 'fa fa-close' }; } } // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'name', title: __('Name'), operate: 'LIKE'}, {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'contact_person', title: __('Contact_person'), operate: 'LIKE'}, {field: 'contact_phone', title: __('Contact_phone'), operate: 'LIKE'}, {field: 'status', title: __('Status'),searchList: statusSearchList, formatter: Controller.api.formatter.status}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'updatetime', title: __('Updatetime'), 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); }, recyclebin: function () { // 初始化表格参数配置 Table.api.init({ extend: { 'dragsort_url': '' } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: 'inspection/factory/recyclebin' + location.search, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'name', title: __('Name'), align: 'left'}, { field: 'deletetime', title: __('Deletetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime }, { field: 'operate', width: '140px', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [ { name: 'Restore', text: __('Restore'), classname: 'btn btn-xs btn-info btn-ajax btn-restoreit', icon: 'fa fa-rotate-left', url: 'inspection/factory/restore', refresh: true }, { name: 'Destroy', text: __('Destroy'), classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit', icon: 'fa fa-times', url: 'inspection/factory/destroy', refresh: true } ], 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]")); }, formatter: { status: function(value, row, index) { var state = stateList[value] || {}; return ' ' + (state.text || value) + ''; }, } } }; return Controller; });