define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], function ($, undefined, Backend, Table, Form, Format) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'fc/coupon/index' + location.search, add_url: 'fc/coupon/add', edit_url: 'fc/coupon/edit', del_url: 'fc/coupon/del', multi_url: 'fc/coupon/multi', table: 'fc_coupon', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'sort', columns: [ [ {checkbox: true}, {field: 'id', title: __('SerialNo'), operate: false, sortable: false, align: 'center', width: '70px', class: 'fc-serial', table: table, formatter: Format.serial}, { field: 'name', title: __('优惠券名称'), operate: 'LIKE', // 双保险:服务端 add/edit 已 strip_tags,这里再做一次 HTML 转义, // 避免历史脏数据(含标签的旧记录)被当成 HTML 渲染成存储型 XSS formatter: function (value) { return $('
').text(value == null ? '' : value).html(); } }, { field: 'type', title: __('优惠券类型'), searchList: {fixed: '满减券', discount: '折扣券'}, formatter: function (value) { var m = {fixed: '满减券', discount: '折扣券'}; return m[value] !== undefined ? m[value] : value; } }, { field: 'amount', title: __('面额/折扣'), operate: false, formatter: function (value, row) { return row.type === 'discount' ? value + ' 折' : '¥' + value; } }, { field: 'min_amount', title: __('使用门槛'), operate: false, formatter: function (value) { return value > 0 ? '满 ¥' + value + ' 可用' : '无门槛'; } }, { field: 'total', title: __('发放总量'), operate: false, formatter: function (value) { return value > 0 ? value + ' 张' : '不限量'; } }, {field: 'received', title: __('已领取'), operate: false}, { field: 'days', title: __('有效天数'), operate: false, formatter: function (value) { return value > 0 ? value + ' 天' : '永久有效'; } }, { field: 'enabled', title: __('是否启用'), searchList: {0: '否', 1: '是'}, formatter: Format.statusFormatter({0: '否', 1: '是'}, {0: 'default', 1: 'success'}) }, {field: 'sort', title: __('排序')}, {field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'updatetime', title: __('更新时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible: false}, {field: 'operate', title: __('操作'), 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]")); } } }; return Controller; });