define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var feedbackTypeList = {}; var processStatusList = {}; var statusList = {}; var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'feedback/index' + location.search, add_url: 'feedback/add', edit_url: 'feedback/edit', del_url: 'feedback/del', multi_url: 'feedback/multi', import_url: 'feedback/import', table: 'shop_feedback', } }); var table = $("#table"); feedbackTypeList = JSON.parse(Config.feedbackTypeSearchList); processStatusList = JSON.parse(Config.processStatusSearchList); statusList = JSON.parse(Config.statusSearchList); console.log(feedbackTypeList); console.log(processStatusList); console.log(statusList); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, { field: 'user.username', title: __('User_id'), operate: false, formatter: function (value, row, index) { // 显示用户头像和用户名 var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png'; var username = row.user && row.user.username ? row.user.username : '游客'; return '
' + '' + '' + username + '' + '
'; } }, {field: 'type', title: __('Type'), searchList: feedbackTypeList,formatter: Controller.api.formatter.type}, {field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, {field: 'phone', title: __('Phone'), operate: 'LIKE'}, {field: 'process_status', title: __('Process_status'), searchList: processStatusList,formatter:Controller.api.formatter.process_status}, {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.remark}, {field: 'status', title: __('Status'), searchList: statusList, formatter:Table.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: 'feedback/recyclebin' + location.search, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, { 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: 'feedback/restore', refresh: true }, { name: 'Destroy', text: __('Destroy'), classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit', icon: 'fa fa-times', url: 'feedback/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: { type: function(value, row, index) { var type = feedbackTypeList[value] || value; var cssClass = ''; // 根据不同类型设置不同的样式 if (value === 'PRODUCT_FUNCTION_FEEDBACK') { cssClass = 'success'; // 绿色 } else if (value === 'PRODUCT_BUG_FEEDBACK') { cssClass = 'danger'; // 红色 } else if (value === 'OTHER_FEEDBACK') { cssClass = 'info'; // 蓝色 } return '' + type + ''; }, process_status: function(value, row, index) { var processStatus = processStatusList[value] || value; var cssClass = value == 1 ? 'warning' : 'success'; return '' + processStatus + ''; } } } }; return Controller; });