var layer, eTbl; layui.use(['table', 'layer', 'form'], function () { var table = layui.table; layer = layui.layer; var form = layui.form; //第一个实例 eTbl = table.render({ elem: '#tbl', url: '/mes/api/mesexception', //数据接口 page: true, //开启分页 toolbar: '#toolbar', cols: [[ //表头 { checkbox: true }, { field: 'fcode', title: '代码', width: 160, sort: true }, { field: 'fname', title: '名称', width: 120, sort: true }, { field: 'rectime', title: '录入日期', width: 240, sort: true, templet: function (d) { return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime); } }, { field: 'remark', title: '备注', width: 380 } ]], done: () => { $.ajaxSettings.async = false; } }); table.on('toolbar(macmodel)', function (obj) { if (obj.event == 'add') { layer.open({ type: 2, content: 'exceptionAdd.html', area: ['1000px', '700px'] }); } else if (obj.event == 'delete') { var checkStatus = table.checkStatus('tbl'); console.log(checkStatus); if (checkStatus.data.length === 0) { layer.msg('请先选中需要操作的异常代码!', { icon: 2, anim: 6 }); return; } var ids = ''; for (var i = 0; i < checkStatus.data.length; i++) { ids += checkStatus.data[i].id + ','; } ids = ids.substr(0, ids.length - 1); $.ajax({ url: '/mes/api/mesexception/delete', type: 'post', contentType: 'application/json', dataType: 'text', data: JSON.stringify(ids), success: function (res) { if (res) { layer.msg('操作成功', { icon: 1, anim: 0 }); eTbl.reload(true); } else { layer.msg('操作失败', { icon: 2, anim: 6 }); } } }); } else if (obj.event == 'search') { showToast(); var fcode = $('input[name=fcode]').val(); var fname = $('input[name=fname]').val(); eTbl.reload({ where: { fcode: fcode, fname: fname }, done: () => { form.val('searchForm', { fcode: fcode, fname: fname }); layer.closeAll('loading'); } }); } else if (obj.event == 'all') { showToast(); $('input[name=fcode]').val(''); $('input[name=fname]').val(''); eTbl.reload({ where: { fcode: fcode, fname: fname }, done: () => { layer.closeAll('loading'); } }); } }); table.on('rowDouble(macmodel)', function (obj) { console.log(obj); layer.open({ type: 2, content: 'exceptionAdd.html?id=' + obj.data.id + '&exCode=' + obj.data.fcode, area: ['1000px', '650px'] }); }) table.on('sort(macmodel)', function (obj) { eTbl.reload({ initSort: obj, where: { sort: obj.field, order: obj.type } }) }); }); function reloadTable() { eTbl.reload(); }