layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () { let table = layui.table; let $ = layui.jquery; let admin = layui.madmin; let layer = layui.layer; let form = layui.form; let common = layui.common; let mhttp = layui.mhttp; admin.getConfig(); let cols = [ [ { title: 'UID', field: 'uid', align: 'center' }, { title: '扣量方式', field: '', align: 'center', templet: function (d) { return d.deduction_method === 1 ? '首单扣量' : '回充扣量'; } }, { title: '扣量规则', field: 'title', align: 'center', templet: function (d) { return d.deduction_rule === 1 ? '订单扣量' : '金额扣量'; } }, { title: '所属应用', field: 'app_name', align: 'center', }, { title: '扣量价格', field: 'deduction_price', align: 'center' }, { title: '扣量比例', field: 'deduction_pro', align: 'center', }, { title: '操作', align: 'center', toolbar: '#deduction-bar' } ] ]; let search = httpRequestPostData({ deduction_type:'cps', }); table.render({ elem: '#deduction-table', method: 'POST', request: { pageName: 'page', limitName: 'page_size' }, async: false, headers: { "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? '' }, contentType: 'application/json', url: getMyApiUrl('/deduction/lists'), limit: 20, limits: [20, 30, 40, 50, 80, 100], parseData: function (res) { return httpRequestPagesParseData(res); }, response: { "statusCode": 200, }, where:search, done: function (data, page, total) { var intCode = parseInt(data.code); if (intCode === 403) { cbRespnseRedirectLogin(data); } else if (intCode === 401) { // 仅仅是过期了,这里可以有其他逻辑补偿. // 暂时跳到登陆页面 cbRespnse401(data); } onloadRender(); }, error: function (obj, message) { cbRespnseReloadPage(obj, message); }, page: true, cols: cols, skin: 'line', toolbar: '#deduction-toolbar', defaultToolbar: [{ title: '刷新', layEvent: 'refresh', icon: 'layui-icon-refresh', }, 'filter', 'print', 'exports'] }); table.on('toolbar(deduction-table)', function (obj) { if (obj.event === 'add') { window.add(); } else if (obj.event === 'refresh') { window.refresh(); } }); window.add = function () { layer.open({ id: 'deduction_create', type: 2, title: '添加', shade: 0.1, offset: '20px', area: ['410px', '450px'], maxWidth: 500, maxHeight: 600, scrollbar: true, content: 'deduction_cps_create.html', }); } // 表单内 table.on('tool(deduction-table)', function (obj) { if (obj.event === 'remove') { window.remove(obj); } else if (obj.event === 'edit') { window.edit(obj); } }); window.edit = function (obj) { layer.open({ id: 'deduction-edit', type: 2, title: '修改', shade: 0.1, offset: '20px', area: ['410px', '500px'], maxWidth: 500, maxHeight: 600, scrollbar: true, content: 'deduction_cps_edit.html?uid=' + obj.data.uid, }); } // 删除 window.remove = function (obj) { layer.confirm('确定要删除:' + obj.data.uid + '?', { icon: 3, title: '提示' }, function () { let deleteLoading = layer.msg('操作数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false}); let postData = { uid: obj.data.uid }; let ret = mhttp.ajax({ url: '/deduction/delete', data: postData, }); ret.then((data) => { layer.close(deleteLoading); if (data.code === 200) { layer.msg(data.message, {icon: 1, time: 1000}); obj.del(); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); }); } // 删除 window.refresh = function (param) { table.reload('deduction-table'); } })