diff --git a/js/aq_demand_plan/child/send_out_unplanned_form.js b/js/aq_demand_plan/child/send_out_unplanned_form.js index 2541fab..3fa1926 100644 --- a/js/aq_demand_plan/child/send_out_unplanned_form.js +++ b/js/aq_demand_plan/child/send_out_unplanned_form.js @@ -2,6 +2,8 @@ let objParam, dataObj, fileList = new Array(), imgListUp = new Array(); let form, laydate, layer, upload, table, util; let pageNum = 1, tableIns; // 定义分页 let supplierList = []; // 供应商下拉选 +let data=[]; +let delIdArr =[]; getProList() function setParams(obj) { objParam = JSON.parse(obj); @@ -160,7 +162,7 @@ function beforeSubmitApply() { } } } - openIframeByParamObj("quickAddForm", "采购发货确认", "./send_out_confirm.html", "92%", "92%", dataList); + openIframeByParamObj("quickAddForm", "采购发货确认", "./send_out_confirm.html", "92%", "92%", dataList,1); } // 提交 @@ -296,11 +298,23 @@ function maTypeCheck(modelId) { } function addFitDatas(params,pageSource){ - let data = JSON.parse(params) - data.map(item => { - item.unit = item.unitName - item.modelId = item.id - }) + let newData = JSON.parse(params); + + newData.forEach(item => { + item.unit = item.unitName; + item.modelId = item.id; + + // 查找是否已存在 + let existingIndex = data.findIndex(row => row.modelId === item.modelId); + + if (existingIndex !== -1) { + // 如果存在,则更新(可根据需要只更新某些字段) + data[existingIndex] = { ...data[existingIndex], ...item }; + } else { + // 不存在,新增 + data.push(item); + } + }); setBaseTable(data); } @@ -365,16 +379,7 @@ function getBaseTableData() { // 关闭页面 function closePage(data) { - let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 - if (data) { - let obj = { - resultData:data.resultData, - resultData2:data.resultData2, - id:data.planId - }; - let frameId = parent.document.getElementById('sendOutProDetail').getElementsByTagName("iframe")[0]; - frameId.contentWindow.sendOutSuccess(JSON.stringify(obj)); - } + let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索 parent.layer.close(index); // 再执行关闭 } @@ -398,3 +403,76 @@ function chooseFitTypeTwo() { let params = {}; openIframeByParamObj("choose_type_two", '选择需求计划安全工器具类型', "./choose_type_list.html", '92%', '95%', params); } + + +function delFitTypeTwo() { + if (delIdArr.length === 0) { + layer.msg('请先选择需要删除的数据!', { icon: 7 }); + return; + } + + let layerIndex = layer.confirm('
确定要删除选中数据吗!
', { title: '操作提示' }, function () { + layer.close(layerIndex); + + // 删除数据(修改 jjDataArr) + for (let i = 0; i < delIdArr.length; i++) { + for (let j = 0; j < data.length; j++) { + let id = data[j].id; + if (delIdArr[i] == id) { + data.splice(j, 1); // 删除对应项 + break; + } + } + } + + // 页面无数据时隐藏表格 + if (data.length === 0) { + $('#no_data_title').removeAttr('style'); + $('#search-info').hide(); + $('#table-box').hide(); + } else { + // 同步更新页面表格 + handleDelTableData(delIdArr); + } + + // 清空删除 id 列表 + delIdArr.splice(0, delIdArr.length); + }); +} + + + +// 删除表格数据 +function handleDelTableData(delIdArr) { + if (delIdArr.length > 0) { + $.each(delIdArr, function (index, item) { + $('#baseTable tbody tr').each(function () { + let id = $(this).attr('id'); + if (parseInt(id) === item) { + $(this).remove(); + return false; + } + }) + }) + } + $('#baseTable tbody tr').each(function (index, item) { + $(this).find('td').eq(1).html(index + 1); + }) +} + + +// 单个选中 +function sel(selectStatus, that, id) { + if (selectStatus) { + $(that).prop('checked', true); + delIdArr.push(id); + } else { + $(that).prop('checked', false); + for (let i = 0; i < delIdArr.length; i++) { + if (delIdArr[i] == id) { + delIdArr.splice(i, 1); + break; + } + } + } +} diff --git a/js/aq_demand_plan/child/send_out_unplanned_form_table.js b/js/aq_demand_plan/child/send_out_unplanned_form_table.js new file mode 100644 index 0000000..ce83a03 --- /dev/null +++ b/js/aq_demand_plan/child/send_out_unplanned_form_table.js @@ -0,0 +1,299 @@ +function setBaseTable(results) { + let html = ""; + if (results && results.length > 0) { + for (var i = 0; i < results.length; i++) { + var l = results[i]; + html += ""; + html += ''; + html += "" + + (i + 1) + ""; + html += "" + l.type + ""; + html += "" + l.name + ""; + html += "" + l.model + ""; + html += "" + l.unit + ""; + html += "" + l.needNum + ""; + html += "" + setFormInput(0, 1, l.modelId) + ""; + html += "" + setFormInput(0, 2, l.modelId) + ""; + html += "" + setFormInput('', 3, l.modelId) + ""; + html += "" + setFormInput('', 4, l.modelId) + ""; + html += "" + setFormInput('', 5, l.modelId) + ""; + html += "" + setFormInput('', 6, l.modelId) + ""; + html += ""; + } + } else { + html += "没有相关数据"; + } + $("#baseTable tbody").empty().append(html); + laydate.render({ + elem: '.cjDate' + }); + laydate.render({ + elem: '.jyDate' + }); + layui.form.render(); +} + +function setFormInput(value, type, id) { + let html = '
'; + if (type === 1) { // 采购量 + html += ''; + } else if (type === 2) { // 利库量 + html += ''; + } else if (type === 3) { // 供应商 + html += ''; + } else if (type === 4) { // 出厂日期 + html += ''; + } else if (type === 5) { // 检验日期 + html += ''; + } else if (type === 6) { // 备注 + html += ''; + } + html += '
'; + return html; +} + +function setSelectData(modelId) { + let html = ""; + $.each(supplierList, function (index, item) { + html += ""; + }) + return html; +} + + +// 校验数据 +function checkValue(that, type) { + let value = $(that).val(); + if (type === 1) { // 采购量 + const regex = /^(0|[1-9]\d{0,6})$/; + if (!regex.test(value) && value) { + $(that).val(0); + return layer.msg('采购量输入有误,请重新输入!', { icon: 5 }) + } + // if (value) { + // // 采购量不能大于需要量 + // let needNum = $(that).parents('td').prev().html(); + // if (parseInt(value) > parseInt(needNum)) { + // $(that).val(0); + // return layer.msg('采购量不能大于需要量,请重新输入!', { icon: 5 }) + // } + // } + } else if (type === 2) { // 利库量 + const regex = /^(0|[1-9]\d{0,6})$/; + if (!regex.test(value) && value) { + $(that).val(0); + return layer.msg('利库量输入有误,请重新输入!', { icon: 5 }) + } + if (value) { + // 利库量与库存量校验 + let modelId = $(that).attr('modelId'); + let num = maTypeCheck(modelId); + if (parseInt(value) > num) { + $(that).val(0); + return layer.msg('利库量不能大于库存量,请重新输入!', { icon: 5 }) + } + } + } +} + +// 复选框全选 +function selectAll(selectStatus) {//传入参数(全选框的选中状态) + if (selectStatus) { + $("input[name='check']").each(function (i, n) { + n.checked = true; + }); + $.each(data, function (index, item) { + delIdArr.push(item.id); + }) + } else { + $("input[name='check']").each(function (i, n) { + n.checked = false; + }); + delIdArr.splice(0, delIdArr.length); + } +} + +// 拆分 +function split() { + let splitModelIdArr = []; // 要拆分的数据的ID + $("input[name='check']").each(function (i, n) { + if (n.checked === true) { + splitModelIdArr.push($(this).parents('tr').attr('id')); + } + }); + console.log(splitModelIdArr); + if (splitModelIdArr.length === 0) { + return layer.msg('未选择拆分数据', { icon: 7 }); + } + $.each(splitModelIdArr, function (index, item) { + let idx = $('.model' + item).length; + for (let i = 0; i < 7; i++) { + $('.model' + item).eq(0).find('td').eq(i).attr('rowspan', idx + 1); + } + splitTr(item, idx); + }) + laydate.render({ + elem: '.cjDate' + }); + laydate.render({ + elem: '.jyDate' + }); + layui.form.render(); + // 拆分表格 + function splitTr(modelId, idx) { + let html = ''; + html += ""; + html += "" + setFormInput(0, 1, modelId) + ""; + html += "" + setFormInput(0, 2, modelId) + ""; + html += "" + setFormInput('', 3, modelId) + ""; + html += "" + setFormInput('', 4, modelId) + ""; + html += "" + setFormInput('', 5, modelId) + ""; + html += "" + setFormInput('', 6, modelId) + ""; + html += ""; + $('.model' + modelId).eq(idx - 1).after(html); + } + +} + + +// 取消拆分 +function cancelSplit() { + let splitModelIdArr = []; // 要拆分的数据的ID + $("input[name='check']").each(function (i, n) { + if (n.checked === true) { + splitModelIdArr.push($(this).parents('tr').attr('id')); + } + }); + console.log(splitModelIdArr); + if (splitModelIdArr.length === 0) { + return layer.msg('未选择要取消拆分数据', { icon: 7 }); + } + $.each(splitModelIdArr, function (index, item) { + let idx = $('.model' + item).length; + if (idx > 1) { + $('.model' + item).eq(idx - 1).remove(); + for (let i = 0; i < 7; i++) { + $('.model' + item).eq(0).find('td').eq(i).attr('rowspan', idx - 1); + } + } + }) +} + +// 快速录入 +function quickAdd() { + let modelIdArr = []; + $('#baseTable tbody tr').each(function () { + let modelId = $(this).attr('id'); + modelIdArr.push(modelId); + }) + // 去重后的数据 + let newModelIdArr = removeDuplicates(modelIdArr); + if (modelIdArr.length > newModelIdArr.length) { + return layer.msg('使用快捷录入前,请先确保数据未被拆分', { icon: 7 }); + } + openIframeByParamObj("quickAddForm", "快捷录入", "./quick_add_form.html", "50%", "85%", objParam); +} + + +function removeDuplicates(arr) { + return [...new Set(arr)]; +} + +// 快速赋值 +function quickAddData(data) { + console.error(JSON.parse(data)); + let obj = JSON.parse(data); + $('#baseTable tbody tr').each(function () { + let modelId = $(this).attr('id'); + let needNum = $(this).find('td').eq(6).html(); + if (obj.allSend) { // 全部发货 + $('.num' + modelId).eq(0).val(needNum); + } else { + $('.num' + modelId).eq(0).val(0); + } + if (obj.supplier) { + $('.supplier' + modelId).eq(0).val(obj.supplier); + } else { + $('.supplier' + modelId).eq(0).val(''); + } + if (obj.cjDate) { + $('.cjDate' + modelId).eq(0).val(obj.cjDate); + } else { + $('.cjDate' + modelId).eq(0).val(''); + } + if (obj.jyDate) { + $('.jyDate' + modelId).eq(0).val(obj.jyDate); + } else { + $('.jyDate' + modelId).eq(0).val(''); + } + }) + + layui.form.render(); +} + +// 查询 +function search() { + let keyWord = $('#name').val(); + let keyWord2 = $('#model').val(); + if (keyWord && !keyWord2) { + $('#baseTable tbody tr.mainTr').each(function () { + let name = $(this).find('td').eq(3).html(); + let modelId = $(this).attr('id'); + if (name.indexOf(keyWord) < 0) { + $(this).removeAttr('style'); + $(this).css({ 'display': 'none' }); + $('.model' + modelId).css({ 'display': 'none' }); + } + }); + resetXh(); + } else if (!keyWord && keyWord2) { + $('#baseTable tbody tr.mainTr').each(function () { + let model = $(this).find('td').eq(4).html(); + let modelId = $(this).attr('id'); + if (model.indexOf(keyWord2) < 0) { + $(this).removeAttr('style'); + $(this).css({ 'display': 'none' }); + $('.model' + modelId).css({ 'display': 'none' }); + } + }); + resetXh(); + } else if (keyWord && keyWord2) { + $('#baseTable tbody tr.mainTr').each(function () { + let name = $(this).find('td').eq(3).html(); + let model = $(this).find('td').eq(4).html(); + let modelId = $(this).attr('id'); + if (name.indexOf(keyWord) < 0 || model.indexOf(keyWord2) < 0) { + $(this).removeAttr('style'); + $(this).css({ 'display': 'none' }); + $('.model' + modelId).css({ 'display': 'none' }); + } + }); + resetXh(); + } else { + resetSearch(); + } +} + +// 重置查询 +function resetSearch() { + $('#name').val(''); + $('#model').val(''); + $('#baseTable tbody tr').each(function () { + $(this).removeAttr('style'); + }); + resetXh(); +} + +// 重置序号 +function resetXh() { + let index = 0; + $('#baseTable tbody tr.mainTr').each(function () { + let style = $(this).attr('style'); + if (!style) { + index += 1 + $(this).find('td').eq(1).html(index); + } + }); +} diff --git a/page/aq_demand_plan/child/send_out_unplanned_form.html b/page/aq_demand_plan/child/send_out_unplanned_form.html index bd890a3..d5d828a 100644 --- a/page/aq_demand_plan/child/send_out_unplanned_form.html +++ b/page/aq_demand_plan/child/send_out_unplanned_form.html @@ -107,6 +107,7 @@ + @@ -147,7 +148,7 @@ - +