layui.use(['form', 'table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var form = layui.form; /** * 物料信息管理 */ var MaterialInfo = { tableId: "materialInfoTable" }; /** * 订单信息 */ var salesOrderChild = { tableId: "salesOrderChildTable" }; /** * 初始化表格的列 */ MaterialInfo.initColumn = function () { return [[ {field: 'id', hide: true, title: '主键id'}, {field: 'salesOrderCode', sort: true, title: '订单编号',width: 160}, {field: 'customerNo', sort: true, title: '客户编号',width: 120}, {field: 'cargoNo', sort: true, title: '货号',width: 120}, {field: 'productCode', sort: true, title: '产品编号',width: 160}, {field: 'productName', sort: true, title: '产品名称',width: 160}, {field: 'planNumber', sort: true, title: '计划数量',width: 120}, {field: 'planStartTime', sort: true, title: '计划开始时间',width: 160}, {field: 'planEndTime', sort: true, title: '计划结束时间',width: 160}, {field: 'workshopCode', sort: true, title: '车间编码',width: 120}, {field: 'lineCode', sort: true, title: '产线编码',width: 120}, {field: 'deliveryTime', sort: true, title: '交货时间',width: 160}, {field: 'state', sort: true, title: '状态'}, {field: 'orderSource', sort: true, title: '订单来源',width: 120}, {field: 'createUser', sort: true, title: '创建用户',width: 120}, {field: 'createTime', sort: true, title: '创建时间',width: 160}, {field: 'updateUser', sort: true, title: '更改用户',width: 120}, {field: 'updateTime', sort: true, title: '更改时间',width: 160}, ]]; }; //获取信息 var ajax = new $ax(Feng.ctxPath + "/salesOrder/list?id=" + Feng.getUrlParam("id")); var result = ajax.start(); var orderRes = result.data; let salesOrderCode = result.data[0].salesOrderCode; let planNumber = result.data[0].planNumber; $('#salesOrderCode').val(salesOrderCode); $('#cargoNo').val(result.data[0].cargoNo); $('#productCode').val(result.data[0].productCode); $('#planNumber').val(result.data[0].planNumber); let state = result.data[0].state; if(result.data[0].state === "2"){ $('#residueNumber').val(0); }else { $('#residueNumber').val(result.data[0].planNumber); } // 拆分按钮点击事件 $('#splitbtn').click(function () { let splitNumber = $('#splitNumber').val(); var ajax1 = new $ax(Feng.ctxPath + "/salesOrderChild/getPlanNumberTotal?salesOrderCode=" +salesOrderCode); var result1 = ajax1.start(); let test = parseInt(splitNumber); if(result1.data+test>planNumber){ Feng.error("超出订单计划总数无法拆分!") return } $('#residueNumber').val($('#residueNumber').val()-splitNumber); var ajax = new $ax(Feng.ctxPath + "/salesOrderChild/addItem?salesOrderCode=" +salesOrderCode+"&splitNumber="+splitNumber); var result = ajax.start(); salesOrderChildTableResult.reload(); }); // 渲染表格 var salesOrderChildTableResult = table.render({ elem: '#' + salesOrderChild.tableId, url: Feng.ctxPath + '/salesOrderChild/list?salesOrderCode='+ salesOrderCode, page: true, cellMinWidth: 100, cols: MaterialInfo.initColumn() }); $('#cancel').click(function(){ if(state === "1"){ var ajax = new $ax(Feng.ctxPath + "/salesOrderChild/deleteBySalesOrderCode?salesOrderCode=" +salesOrderCode); var result = ajax.start(); } window.location.href = Feng.ctxPath + '/salesOrder' }); $('#btnSubmit').click(function(){ if(state === "2"){ Feng.error("订单已拆分完成,请勿提交!") return } console.log($('#residueNumber').val()); let residuePas = parseInt($('#residueNumber').val()); if(residuePas !== 0){ Feng.error("未拆分完毕禁止提交订单!") return } var ajax = new $ax(Feng.ctxPath + "/salesOrder/updateBySalesOrderId", function (data) { }, function (data) { Feng.error("更新失败!" + data.responseJSON.message) }); ajax.set('id',Feng.getUrlParam("id")); ajax.start(); window.location.href = Feng.ctxPath + '/salesOrder' }); });