var layer, eTbl, pId, unbindTbl; layui.use(['table', 'layer', 'element'], function () { var table = layui.table; var element = layui.element; layer = layui.layer; pId = QueryString("pId"); // document.querySelector('#macprocess').src = 'processwithmac.html?pId=' + pId; //第一个实例 eTbl = table.render({ elem: '#tbl', height: 600, url: '/mes/api/machine', //数据接口 page: true, //开启分页 toolbar: '#toolbar', cols: [[ //表头 { checkbox: true }, { field: 'fCode', title: '代码', sort: true }, { field: 'fName', title: '名称', sort: true }, { field: 'fModel', title: '机型', sort: true, templet: function (d) { return d.fModelName; } }, { field: 'imsIp', title: 'IMS程序所在电脑IP' }, { field: 'rectime', title: '录入日期', sort: true, templet: function (d) { return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime); } }, { field: 'remark', title: '备注' } ]], where: { filter: " and a.id not in (select macid from MacTProcess) " } }); table.on('toolbar(machine)', function (obj) { layer.confirm('您确定要这样做吗?', function (index) { 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); if (obj.event == 'add') { $.ajax({ url: '/mes/api/tprocess/bindmac', type: 'post', contentType: 'application/json', dataType: 'json', data: JSON.stringify({ pId: pId, macIds: ids }), success: function (res) { if (res.code == 1) { layer.msg('操作成功', { icon: 1, anim: 0 }); unbindTbl.reload(true); eTbl.reload(true); } else { layer.msg(res.message, { icon: 2, anim: 6 }); } } }) } layer.close(index); }); }); table.on('rowDouble(machine)', function (obj) { console.log(obj); layer.open({ type: 2, content: 'machineAdd.html?id=' + obj.data.id, area: ['800px', '475px'] }); }); table.on('sort(machine)', function (obj) { eTbl.reload({ initSort: obj, where: { sort: obj.field, order: obj.type } }) }); unbindTbl = table.render({ elem: '#albindtbl', url: '/mes/api/mactprocess', //数据接口 page: true, //开启分页 toolbar: '#unbindtoolbar', cols: [[ //表头 { checkbox: true }, // { type: 'numbers' }, { field: 'macCode', title: '机台代码', sort: true }, { field: 'macName', title: '机台名称', sort: true }, { field: 'macModelName', title: '机型', sort: true, templet: function (d) { return d.macModelName; } }, { field: 'processCode', title: '制程代码', sort: true }, { field: 'processName', title: '制程名称', sort: true }, ]], where: { poCode: pId }, }) table.on('toolbar(albindmachine)', function (obj) { if (obj.event == "delete") { layer.confirm('您确定要这样做吗?', function (index) { var checkStatus = table.checkStatus('albindtbl'); 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/mactprocess/delete', type: 'post', contentType: 'application/json', dataType: 'text', data: JSON.stringify(ids), success: function (res) { if (res == '1') { layer.msg('操作成功', { icon: 1, anim: 0 }); eTbl.reload(true); unbindTbl.reload(true); } else { layer.msg('操作失败', { icon: 2, anim: 6 }); } } }); }); } }); table.on('sort(albindmachine)', function (obj) { eTbl.reload({ initSort: obj, where: { poCode: pId, sort: obj.field, order: obj.type } }) }); }); function reloadTable() { eTbl.reload(); }