var layer, eTbl; layui.use(['table', 'layer', 'element', 'form'], function () { var table = layui.table; layer = layui.layer; var element = layui.element; var form = layui.form; //第一个实例 eTbl = table.render({ elem: '#tbl', url: '/mes/api/tprocess', //数据接口 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: '备注' }, { fixed: 'right', width: 150, align: 'center', toolbar: '#barDemo' } ]], done: () => { $.ajaxSettings.async = false; } }); table.on('toolbar(macmodel)', function (obj) { if (obj.event == 'add') { layer.open({ type: 2, title: '新增制程', content: 'processAdd.html', area: ['800px', '400px'] }); } 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/tprocess/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('tool(macmodel)', function (obj) { var data = obj.data; var event = obj.event; if (event == 'bind') { console.log(data); layer.open({ type: 2, title: '绑定机台', content: 'choosemac.html?pId=' + data.fCode, area: ['1250px', '800px'] }); } }); table.on('rowDouble(macmodel)', function (obj) { console.log(obj); layer.open({ type: 2, content: 'processAdd.html?id=' + obj.data.id, area: ['800px', '400px'] }); }); table.on('sort(macmodel)', function (obj) { eTbl.reload({ initSort: obj, where: { sort: obj.field, order: obj.type } }) }); }); function reloadTable() { eTbl.reload(); }