layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect', 'laydate'], function () { let $ = layui.jquery, table = layui.table, xmSelect = layui.xmSelect, miniTab = layui.miniTab, laydate = layui.laydate, form = layui.form; /**** index begin ***/ if ($('.location-index-page').length > 0) { miniTab.listen(); // 渲染表格 let listUrl = $('#table-container').data('url'); let insTb = table.render({ elem: '#table-container', title: '优惠卷管理列表', defaultToolbar: ['filter', 'exports', { title: '搜索' , layEvent: 'search' , icon: 'layui-icon-search' }], toolbar: '#toolbar-tpl', method: 'POST', url: listUrl, page: true, limit: 20, limits: [20,50,100,200,500,1000], request: { pageName: 'page', limitName: 'size', }, parseData: function (res) { return { "code": res.code, //解析接口状态 "msg": res.msg, //解析提示文本 "count": res.data.total, //解析数据长度 "data": res.data.list //解析数据列表 }; }, cols: [[ {type: 'checkbox'}, {field: 'name', title: '名称', width: 150}, {field: 'type_text', title: '类型', width: 100}, {field: 'require_cost', title: '消费金额/元', width: 120, templet: function (d) { let requireCost = d.condition / 100; return ''+requireCost+''; } }, {field: 'deduct_cost', title: '优惠额度/元', width: 120, templet: function (d) { let deductCost = d.amount / 100; return ''+deductCost+''; } }, {field: 'use_range_at', title: '有效期', minWidth: 200, templet: function (d) { return ''+d.begin_at+' ~ '+d.end_at+''; }, align: 'center' }, {field: 'total', title: '发行总量', width: 150, edit: true}, {field: 'receive', title: '已领数量', width: 150}, {field: 'created_at', title: '创建日期', minWidth: 100}, {templet: '#row-operate', width: 140, fixed: 'right', align: 'center', title: '操作'} ]], done: function () { Tools.setInsTb(insTb); } }); let modifyUrl = $('#row-modify').data('url'); table.on('edit(table-container)', function (obj) { let id = obj.data.id; $.ajax(modifyUrl, { data: {"id": id, "field": obj.field, "value": obj.value} ,dataType : 'json' ,type: 'POST' }) .done(function (res) { if (res.code === 0) { insTb.reload(); } else { layer.msg(res.msg, {time:2000, icon: 2}, function () { insTb.reload(); }); } }) }); //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('toolbar(table-container)', function (obj) { let layEvent = obj.event; let insTb = Tools.getInsTb(); let url = $($(this).context).data('href') let title = $($(this).context).data('title') let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; if (layEvent === 'refresh') { insTb.reload(); return false; } if (layEvent == 'add') { openLayer(url, title, width, height); return false; } if (layEvent === 'del') { let checkStatus = table.checkStatus('table-container'); if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } let selected = checkStatus.data; let ids = []; let url = $($(this).context).data('href') $.each(selected, function (index, val) { ids.push(val.id); }) del(url, ids); return false; } }) //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('tool(table-container)', function (obj) { let layEvent = obj.event; let data = obj.data; let insTb = Tools.getInsTb(); let url = $($(this).context).data('href') let title = $($(this).context).data('title') let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; if (layEvent == 'hasList') { openLayer(url, title, width, height); return false; } if (layEvent == 'del') { let url = $($(this).context).data('href'); $.post(url, {id: data.id}, function (res) { layer.msg(res.msg) if (res.code === 0) { insTb.reload(); } }) return false; } }); table.on('edit(table-container)', function (obj) { let id = obj.data.id; $.ajax(modifyUrl, { data: {"id": id, "field": obj.field, "value": obj.value} ,dataType : 'json' ,type: 'POST' }) .done(function (res) { if (res.code === 0) { insTb.reload(); } else { layer.msg(res.msg, {time:2000, icon: 2}, function () { insTb.reload(); }); } }) }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { //执行搜索重载 table.reload('table-container', { page: {curr: 1} , where: data.field }, 'data'); return false; }); } /*** index end ***/ // 发行期限 laydate.render({ elem: '#receive-start-at', type: 'datetime', }); laydate.render({ elem: '#receive-end-at', type: 'datetime', }); // 优惠有效期限 laydate.render({ elem: '#deduct-start-at', type: 'datetime', }); laydate.render({ elem: '#deduct-end-at', type: 'datetime', }); /** add **/ if ($('.location-operate-page').length > 0) { } });