// 用于添加标签 function addItem(obj) { } // 用于删除标签 function deleteItem(obj) { } // 用于加载物料选择菜单 function selectMaterialForLocation() { } // 用于通过物料名称获取物料 function selectMaterialByNameForLocation() { } // 用于编码查询 function selectCodeForLocation(obj) { } // 用于扫描物料编码 function scanMaterialCodeForTaking() { } // 用于二次渲染页面 function Coverpage() { } // 用于计算盘点结果 function calculate(obj) { } // 用于监听下拉框变化 function changeSelectValueForUnit(obj){ } // 用于监听下拉框变化 function changeSelectValueForProducedDate(obj){ } // 用于暂存卡片个数 let params = []; // 用于卡片编号 var NewIdNumber = 1; let needToUpdate = {}; layui.use(['form', 'step', 'flow', 'laydate', 'inputTag'], function () { var $ = layui.$, form = layui.form, step = layui.step; // 实现卡片添加 addItem = function (obj) { // 获取父元素id var parentId = obj.parentNode.id; NewIdNumber = NewIdNumber + 1; var materialItem = `

`; // 获取当前高度 var height = parseInt(($("#stepForm1").css('height')).split("px")[0]); params.push(NewIdNumber); // $("#form1").css("height", height + 682 + 'px'); $("#stepForm1").css("height", height + 625 + 'px'); $("#" + parentId).after(materialItem); }; // 实现卡片删除 deleteItem = function (obj) { // 获取父节点 var parent = obj.parentNode; var parentId = parent.id; parentId = parseInt(parentId.split("InventoryDetails")[1]); // 获取祖父节点 var reparent = parent.parentNode; var height = parseInt(($("#stepForm1").css('height')).split("px")[0]); $("#stepForm1").css("height", height - 625 + 'px'); params = remove(params, parentId); reparent.removeChild(parent); }; //删除数组中指定元素 function remove(arr, item) { var result = []; for (let i = 0; i < arr.length; i++) { if (arr[i] === item) { continue; } result.push(arr[i]); } return result; } // 用于打开物料树形菜单 selectMaterialForLocation = function (obj) { if (depositoryId !== undefined && departmentManagerIdForLocation !== undefined && departmentManagerIdForLocation !== "") { var parent = obj.parentNode.parentNode.parentNode.parentNode; var parentId = parent.id; // 物料编码父级 var codeChildren = parent.childNodes[7]; // 物料名称父级 var materialChildren = parent.childNodes[5]; // 物料类型父级 var typeChildren = parent.childNodes[9]; // 材质父级 var textureChildren = parent.childNodes[11]; // 规格型号父级 var versionChildren = parent.childNodes[13]; // 计量单位父级 var unitChildren = parent.childNodes[15]; // 库存数量父级 var inventoryChildren = parent.childNodes[19]; // 编码条目 var codeItem = codeChildren.childNodes[3].childNodes[1]; // 具体条码 var codeValue = codeItem.childNodes[1]; // 物料条目 var materialItem = materialChildren.childNodes[3].childNodes; // 物料名称 var materialName = materialItem[1].childNodes[1]; // 物料编码 var materialId = materialItem[3]; // 输入的物料名称 var mname = materialName.value; // 物料种类条目 var materialTypeItem = typeChildren.childNodes[3].childNodes; layer.open({ type: 2, title: '弹窗内容', skin: 'layui-layer-rim', maxmin: true, shadeClose: true, //点击遮罩关闭层 area: ['70%', '70%'], move: '.layui-layer-title', fixed: false, content: '/getMaterialAll?mname=' + mname + '&type=3&clickObj=' + parentId + '&placeId=' + placeId + '&depositoryId=' + depositoryId, success: function (layero, index) { var children = layero.children(); var content = $(children[1]); var iframeChildren = $(content.children()); content.css('height', '100%'); iframeChildren.css('height', '100%'); }, end: function () { var mid = materialId.value; if (mid !== '') { $.ajax({ url: "/material/findInventoryByIdAndPid?mid=" + mid + "&pid=" + placeId, type: "get", dataType: 'json', contentType: "application/json;charset=utf-8", success: function (d) { var material = d.data.materialById; var code = material.code; if (code === undefined) { code = ""; } codeValue.value = code; materialTypeItem[1].value = material.typeName; materialTypeItem[3].value = material.typeId; textureChildren.childNodes[3].childNodes[1].value = material.texture === null || material.texture === undefined ? '' : material.texture; versionChildren.childNodes[3].childNodes[1].value = material.version === null || material.version === undefined ? '' : material.version; inventoryChildren.childNodes[3].childNodes[1].value = material.quantity; var materialAndBarCodeList = material.materialAndBarCodeList; var idNumber = materialId.name.split("mid")[1]; let unitItem = $("#unit" + idNumber); unitItem.empty(); unitItem.append(new Option(material.unit, "-1")); let splitInfoList = material.splitInfoList; if (splitInfoList.length > 0) { $.each(splitInfoList, function (index, item) { unitItem.append(new Option(item.newUnit, item.newUnit)); }) } form.render(); var shelfLife = material.shelfLife; if (shelfLife !== null && shelfLife !== undefined) { $("#" + "producedDateItem" + idNumber).show(); var producedDateList = d.data['producedDateList']; if (producedDateList !== null && producedDateList !== undefined && producedDateList.length > 0) { $.each(producedDateList, function (index, item) { $("#" + "producedDate" + idNumber).append(new Option(item, item)); }) } form.render(); } else { $("#" + "producedDateItem" + idNumber).hide(); form.render(); } } }); } } }); } else { layer.msg("请先选择盘点位置或负责人", { icon: 0, time: 500 }) } }; // 用于实现通过编码查询物料 selectCodeForLocation = function (obj) { if (depositoryId !== undefined && departmentManagerIdForLocation !== undefined && departmentManagerIdForLocation !== "") { // 输入code var code = obj.value; if(code.trim() !== ""){ var parent = obj.parentNode.parentNode.parentNode.parentNode; // 物料编码父级 var codeChildren = parent.childNodes[7]; // 物料名称父级 var materialChildren = parent.childNodes[5]; // 物料类型父级 var typeChildren = parent.childNodes[9]; // 材质父级 var textureChildren = parent.childNodes[11]; // 规格型号父级 var versionChildren = parent.childNodes[13]; // 计量单位父级 var unitChildren = parent.childNodes[15]; // 库存数量父级 var inventoryChildren = parent.childNodes[19]; // 编码条目 var codeItem = codeChildren.childNodes[3].childNodes[1]; // 物料条目 var materialItem = materialChildren.childNodes[3].childNodes; // 物料名称 var materialName = materialItem[1].childNodes[1]; // 物料编码 var materialId = materialItem[3]; // 物料种类条目 var materialTypeItem = typeChildren.childNodes[3].childNodes; // 获取对应元素 var req = {}; req.code = code; req.depositoryId = depositoryId; req.placeId = placeId; $.ajax({ url: "/material/findMatrialByCodeForTaking", type: "post", dataType: 'json', data: JSON.stringify(req), contentType: "application/json;charset=utf-8", success: function (d) { var d = d.data; if (d == null) { layer.msg("该位置暂未该物品,请确认是否输入正确"); materialName.value = ""; materialId.value = ""; obj.value = ""; materialTypeItem[1].value = ""; materialTypeItem[3].value = ""; textureChildren.childNodes[3].childNodes[1].value = ""; versionChildren.childNodes[3].childNodes[1].value = ""; unitChildren.childNodes[3].childNodes[1].value = ""; inventoryChildren.childNodes[3].childNodes[1].value = ""; } else { materialName.value = d.mname; materialId.value = d.id; materialTypeItem[1].value = d.typeName; materialTypeItem[3].value = d.typeId; textureChildren.childNodes[3].childNodes[1].value = d.texture === null || d.texture === undefined ? '' : d.texture; versionChildren.childNodes[3].childNodes[1].value = d.version === null || d.version === undefined ? '' : d.version; inventoryChildren.childNodes[3].childNodes[1].value = d.quantity; // 获取物料与条形码的对应关系 var materialAndBarCodeList = d["materialAndBarCodeList"]; var idNumber = materialId.name.split("mid")[1]; let unit = $("#unit" + idNumber); unit.empty(); unit.append(new Option(d.baseUnit, "-1")); if (d.splitInfoList !== null && d.splitInfoList.length > 0) { $.each(d.splitInfoList, function (index, item) { unit.append(new Option(item.newUnit, item.newUnit));//往下拉菜单里添加元素 }); form.render(); } var producedDateItem = $("#producedDate" + idNumber); if (producedDateItem.length > 0) { producedDateItem.empty(); } var shelfLife = d.shelfLife; if (shelfLife !== null && shelfLife !== undefined) { $("#" + "producedDateItem" + idNumber).show(); var producedDateList = d['producedDateList']; if (producedDateList != null && producedDateList != undefined && producedDateList.length > 0) { $.each(producedDateList, function (index, item) { $("#" + "producedDate" + idNumber).append(new Option(item, item)); }) } form.render(); } else { $("#" + "producedDateItem" + idNumber).hide(); form.render(); } } } }); } } else { layer.msg("请先选择盘点位置或负责人", { icon: 0, time: 500 },function () { obj.value = ""; }) } }; // 通过物料名称获取物料 selectMaterialByNameForLocation = function (obj) { if (depositoryId !== undefined && departmentManagerIdForLocation !== undefined && departmentManagerIdForLocation !== "") { // 如果已经选择盘点的位置 // 输入物料名称 var data = obj.value; var parent = obj.parentNode.parentNode.parentNode.parentNode; var parentId = parent.id; // 物料编码父级 var codeChildren = parent.childNodes[7]; // 物料名称父级 var materialChildren = parent.childNodes[5]; // 物料类型父级 var typeChildren = parent.childNodes[9]; // 材质父级 var textureChildren = parent.childNodes[11]; // 规格型号父级 var versionChildren = parent.childNodes[13]; // 计量单位父级 var unitChildren = parent.childNodes[15]; // 库存数量父级 var inventoryChildren = parent.childNodes[19]; // 编码条目 var codeItem = codeChildren.childNodes[3].childNodes[1]; // 具体条码 var codeValue = codeItem.childNodes[1]; // 物料条目 var materialItem = materialChildren.childNodes[3].childNodes; // 物料名称 var materialName = materialItem[1].childNodes[1]; // 物料编码 var materialId = materialItem[3]; // 物料种类条目 var materialTypeItem = typeChildren.childNodes[3].childNodes; var req = {}; data = data.split(",")[0]; if(data !== ""){ req.mname = data; req.depositoryId = depositoryId; req.placeId = placeId; $.ajax({ url: "/material/findMaterialForTaking", type: "post", dataType: 'json', data: JSON.stringify(req), contentType: "application/json;charset=utf-8", success: function (d) { if (d.count > 1) { layer.msg("请点击右侧搜索确定物品"); materialId.value = ""; codeValue.value = ""; textureChildren.childNodes[3].childNodes[1].value = ""; versionChildren.childNodes[3].childNodes[1].value = ""; unitChildren.childNodes[3].childNodes[1].value = ""; inventoryChildren.childNodes[3].childNodes[1].value = ""; return false; } else if (d.count === 0) { layer.msg("没有该物品,请确认输入是否正确"); materialId.value = ""; codeValue.value = ""; materialName.value = ""; materialTypeItem[1].value = ''; materialTypeItem[3].value = ""; textureChildren.childNodes[3].childNodes[1].value = ""; versionChildren.childNodes[3].childNodes[1].value = ""; unitChildren.childNodes[3].childNodes[1].value = ""; inventoryChildren.childNodes[3].childNodes[1].value = ""; return false; } else { var material = d.data; materialName.value = material.mname; materialId.value = material.id; codeValue.value = material.code; materialTypeItem[1].value = material.typeName; materialTypeItem[3].value = material.typeId; textureChildren.childNodes[3].childNodes[1].value = material.texture === null || material.texture === undefined ? '' : material.texture; versionChildren.childNodes[3].childNodes[1].value = material.version === null || material.version === undefined ? '' : material.version; inventoryChildren.childNodes[3].childNodes[1].value = material.baseUnitQuantity; var idNumber = materialId.name.split("mid")[1]; // 获取物料与条形码的对应关系 let unitItem = $("#unit" + idNumber); unitItem.empty(); unitItem.append(new Option(material.baseUnit, "-1")); let splitInfoList = material.splitInfoList; if (splitInfoList.length > 0) { $.each(splitInfoList, function (index, item) { unitItem.append(new Option(item.newUnit, item.newUnit)); }) } var shelfLife = d.shelfLife; if (shelfLife !== null && shelfLife !== undefined) { $("#" + "producedDateItem" + idNumber).show(); var producedDateList = d['producedDateList']; if (producedDateList !== null && producedDateList !== undefined && producedDateList.length > 0) { $.each(producedDateList, function (index, item) { $("#" + "producedDate" + idNumber).append(new Option(item, item)); }) } form.render(); } else { $("#" + "producedDateItem" + idNumber).hide(); form.render(); } } } }); } } else { layer.msg("请先选择盘点位置或负责人", { icon: 0, time: 500 },function () { obj.value = ""; }) } }; // 用于二次渲染页面 Coverpage = function (num, obj) { // 获取待添加父类 NewIdNumber = num; if (num === 0) { // 如果是第一个 NewIdNumber = ""; } var texture = obj.texture === null || obj.texture === undefined ? "" : obj.texture; var version = obj.version === null || obj.version === undefined ? "" : obj.version; var unit = obj.unit === null || obj.unit === undefined ? "" : obj.unit; var materialItem = `

`; // 获取当前高度 var height = parseInt(($("#stepForm1").css('height')).split("px")[0]); if (NewIdNumber !== "") { params.push(NewIdNumber) } $("#stepForm1").css("height", height + 682 + 'px'); var oldIdNumber = NewIdNumber - 1; if (oldIdNumber === 0) { oldIdNumber = ""; } $("#InventoryDetails" + oldIdNumber).after(materialItem); }; // 用于扫描物料编码 scanMaterialCodeForTaking = function (obj) { if (depositoryId !== undefined && departmentManagerIdForLocation !== undefined && departmentManagerIdForLocation !== "") { parent.wx.scanQRCode({ desc: 'scanQRCode desc', needResult: 1, // 默认为0,扫描结果由企业微信处理,1则直接返回扫描结果, scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是条形码(一维码),默认二者都有 success: function (res) { // 回调 var result = res.resultStr;//当needResult为1时返回处理结果 var req = {}; req.qrCode = result; req.placeId = placeId; req.depositoryId = depositoryId; req.codeFlag = 2; $.ajax({ url: "/material/qywxStockTakingScanQrCode", type: "post", dataType: 'json', data: JSON.stringify(req), contentType: "application/json;charset=utf-8", success: function (d) { var data = d.data; if (data == null) { layer.msg("对于编码:" + result + ",并未发现对应的物料", { icon: 0, time: 1000 //0.5秒关闭(如果不配置,默认是3秒) }, function () { }) } else { var parent = obj.parentNode.parentNode.parentNode.parentNode; var parentId = parent.id; // 物料编码父级 var codeChildren = parent.childNodes[7]; // 物料名称父级 var materialChildren = parent.childNodes[5]; // 物料类型父级 var typeChildren = parent.childNodes[9]; // 材质父级 var textureChildren = parent.childNodes[11]; // 规格型号父级 var versionChildren = parent.childNodes[13]; // 计量单位父级 var unitChildren = parent.childNodes[15]; // 库存数量父级 var inventoryChildren = parent.childNodes[19]; // 编码条目 var codeItem = codeChildren.childNodes[3].childNodes[1]; // 具体条码 var codeValue = codeItem.childNodes[1]; // 物料条目 var materialItem = materialChildren.childNodes[3].childNodes; // 物料名称 var materialName = materialItem[1].childNodes[1]; // 物料编码 var materialId = materialItem[3]; // 物料种类条目 var materialTypeItem = typeChildren.childNodes[3].childNodes; materialName.value = data.mname; materialId.value = data.id; materialTypeItem[1].value = data.typeName; materialTypeItem[3].value = data.typeId; codeValue.value = data.code; textureChildren.childNodes[3].childNodes[1].value = data.texture === null || data.texture === undefined ? '' : data.texture; versionChildren.childNodes[3].childNodes[1].value = data.version === null || data.version === undefined ? '' : data.version; unitChildren.childNodes[3].childNodes[1].value = data.unit === null || data.unit === undefined ? '' : data.unit; inventoryChildren.childNodes[3].childNodes[1].value = data.quantity; // 获取物料与条形码的对应关系 var idNumber = materialId.name.split("mid")[1]; var unitItem = $("#unit" + idNumber); unitItem.empty(); unitItem.append(new Option(data.unit, "-1")); let splitInfoList = data.splitInfoList; if (splitInfoList.length > 0) { $.each(splitInfoList, function (index, item) { unitItem.append(new Option(item.newUnit, item.newUnit)); }) } form.render(); var shelfLife = data.shelfLife; if (shelfLife !== null && shelfLife !== undefined) { $("#" + "producedDateItem" + idNumber).show(); var producedDateList = data['producedDateList']; if (producedDateList !== null && producedDateList !== undefined && producedDateList.length > 0) { $.each(producedDateList, function (index, item) { $("#" + "producedDate" + idNumber).append(new Option(item, item)); }) } form.render(); } else { $("#" + "producedDateItem" + idNumber).hide(); form.render(); } } } }) } }) } else { layer.msg("请先选择盘点位置或负责人", { icon: 0, time: 500 },function () { }) } }; // 用于计算盘点结果 calculate = function (obj) { var parent = obj.parentNode.parentNode.parentNode; var oldInventoryItem = parent.childNodes[19].childNodes[3].childNodes[1]; var nowInventoryItem = parent.childNodes[21].childNodes[3].childNodes[1]; var resultItem = parent.childNodes[23].childNodes[3].childNodes[1]; var InventoryItem = parent.childNodes[25].childNodes[3].childNodes[1]; var oldInventory = Number(oldInventoryItem.value); var nowInventory = Number(nowInventoryItem.value); $('#' + resultItem.id).empty(); if (oldInventory > nowInventory) { // 如果盘点数目小于库存数目 $('#' + resultItem.id).append(new Option("盘亏", 'Inventory_down'));//往下拉菜单里添加元素 $("#" + InventoryItem.id).val(oldInventory - nowInventory); } else if (oldInventory < nowInventory) { // 如果盘点数目大于库存数目 $('#' + resultItem.id).append(new Option("盘盈", 'Inventory_up'));//往下拉菜单里添加元素 $("#" + InventoryItem.id).val(nowInventory - oldInventory); } else { // 如果盘点数目等于库存数目 $('#' + resultItem.id).append(new Option("正常", 'Inventory_normal'));//往下拉菜单里添加元素 $("#" + InventoryItem.id).val(nowInventory - oldInventory); } form.render(); }; form.on('select()', function (data) { var id = data.elem.id; //得到select原始DOM对象id var req = {}; if (id.includes("producedDate")) { var idNumber = id.split('producedDate')[1]; // 得到当前id对应数字 req.mid = $("#" + "mid" + idNumber).val(); req.producedDate = data.value; $.ajax({ url: "/material/findQuantityByProducedDate", type: "post", dataType: 'json', data: JSON.stringify(req), contentType: "application/json;charset=utf-8", success: function (d) { $("#" + "oldInventory" + idNumber).val(d.data) } }); } else if (id.includes("unit")) { let idNumber = id.split("unit")[1]; // 得到当前id对应数字 req.mid = $("#" + "midForLocation" + idNumber).val(); req.unit = data.value; req.placeId = $("#placeId").val(); $.ajax({ url: "/material/findQuantityByUnit", type: "post", dataType: 'json', data: JSON.stringify(req), contentType: "application/json;charset=utf-8", success: function (d) { $("#" + "oldInventory" + idNumber).val(d.data) } }); } }); });