From 4621c9235c8ab139dfb85d0f8cbb07725c7d944a Mon Sep 17 00:00:00 2001 From: hongchao <3228015117@qq.com> Date: Thu, 13 Mar 2025 12:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E5=90=88=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/aq_demand_plan/apply_plan_form.css | 44 ++- js/aq_demand_plan/child/apply_plan_form.js | 191 +++++++++- .../child/choose_crane_type_list.js | 339 ++++++++++++++++++ .../child/choose_tool_type_list.js | 338 +++++++++++++++++ .../child/choose_vehicle_type_list.js | 339 ++++++++++++++++++ .../aq_demand_plan/child/apply_plan_form.html | 291 ++++++++++++++- .../child/choose_crane_type_list.html | 86 +++++ .../child/choose_tool_type_list.html | 86 +++++ .../child/choose_vehicle_type_list.html | 86 +++++ 9 files changed, 1780 insertions(+), 20 deletions(-) create mode 100644 js/aq_demand_plan/child/choose_crane_type_list.js create mode 100644 js/aq_demand_plan/child/choose_tool_type_list.js create mode 100644 js/aq_demand_plan/child/choose_vehicle_type_list.js create mode 100644 page/aq_demand_plan/child/choose_crane_type_list.html create mode 100644 page/aq_demand_plan/child/choose_tool_type_list.html create mode 100644 page/aq_demand_plan/child/choose_vehicle_type_list.html diff --git a/css/aq_demand_plan/apply_plan_form.css b/css/aq_demand_plan/apply_plan_form.css index d21a0cc..eec1c48 100644 --- a/css/aq_demand_plan/apply_plan_form.css +++ b/css/aq_demand_plan/apply_plan_form.css @@ -4,15 +4,55 @@ justify-content: center; } + #no_data_title { width: 100%; - height: 200px; + flex-direction: column; justify-content: space-evenly; margin-top: 2%; } -#search-info { +#no_data_titleJJ { + width: 100%; + + flex-direction: column; + justify-content: space-evenly; + margin-top: 2%; +} + +#no_data_titleDC { + width: 100%; + + flex-direction: column; + justify-content: space-evenly; + margin-top: 2%; +} + +#no_data_titleYS { + width: 100%; + + + flex-direction: column; + justify-content: space-evenly; + margin-top: 2%; +} +search-info { + border-width: 1px; + margin-bottom: 10px; +} + +#search-infoJJ { + border-width: 1px; + margin-bottom: 10px; +} + +#search-infoDC { + border-width: 1px; + margin-bottom: 10px; +} + +#search-infoYS { border-width: 1px; margin-bottom: 10px; } diff --git a/js/aq_demand_plan/child/apply_plan_form.js b/js/aq_demand_plan/child/apply_plan_form.js index c2bb837..cebeeb1 100644 --- a/js/aq_demand_plan/child/apply_plan_form.js +++ b/js/aq_demand_plan/child/apply_plan_form.js @@ -1,4 +1,4 @@ -let idParam, objParam; +let idParam, objParam;fileList = new Array(), imgListUp = new Array(); let form, laydate, layer, upload, table, util; let pageNum = 1, tableIns; // 定义分页 let jjDataArr = []; // 配件数据 @@ -16,15 +16,157 @@ function setParams(obj) { laydate.render({ elem: '#needTime' }); - form.verify(); + // form.verify(); + // 自定义验证规则 + form.verify({ + atLeastOne: function(value){ + var checkboxes = document.querySelectorAll('input[name="applyType"]:checked'); + if(checkboxes.length === 0){ + return '请至少选择一个申请类型'; + } + } + }); form.on('submit(formData)', function (data) { - submitApply(data); + const isVehicleChecked = $('input[name="applyType"][value="vehicle"]').is(':checked'); + if (isVehicleChecked) { + form.on('submit(formDataTwo)', function (data){ + submitApply(data); + }) + }else{ + submitApply(data); + } + + + }); + + form.on('checkbox', function(data) { + console.log("xxxxxxxxxxxx", data.elem); + var detailId = data.elem.value === 'tool' ? 'tool-details' : + data.elem.value === 'safety-tool' ? 'safety-tool-details' : + data.elem.value === 'crane' ? 'crane-details' : + 'vehicle-details'; + toggleDetails(detailId,data.elem.value); }); form.render(); + let uploadObj = upload.render({ + elem: '#test2', + multiple: true, + dataType: "json", + exts: 'jpg|png|jpeg|doc|docx|pdf|xlsx|xls', + acceptMime: 'image/jpg,image/png,image/jpeg,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + number: 5, //最大上传数量 + size: 1024 * 10, //最大文件大小,单位k + auto: false, //是否自动上传 ,默认为true + bindAction: '#hideUpload', //绑定的按钮 + choose: function (obj) { + uploadObj.config.elem.next()[0].value = ''; + let length = $('.file-iteme').length; + if (length >= 5) { + return layer.msg('最多上传5个附件证明', { icon: 7 }); + } + let num = 0; + obj.preview(function (index, file, result) { + num ++; + if(num <= (5 - length)){ + $('#uploader-list').append( + '
' + + '

x

' + + handleFileType(index, file, result) + + '
' + ); + let map = new Map();//将选择的图片索引和图片写成对象存入集合 + map.index = index; + map.file = file; + fileList.push(map); + } + }); + } + }); getProList(); }); } +// 删除文件 +$(document).on("click", ".file-iteme .handle", function (event) { + imgListUp.splice(0, imgListUp.length); + let index = $(this).next().attr('data-index'); + $.each(fileList, function (inx, ele) { + //对比删除文件索引 + //将未删除的存入新集合 + if (index != ele.index) { + imgListUp.push(ele); + } + }); + $(this).parent().remove(); + //将新文件集合替换老集合 + fileList.splice(0, fileList.length); + $.each(imgListUp, function (inx, ele) { + fileList.push(ele) + }); +}); + +// 设置文件类型 +function handleFileType(index, file, result) { + let html = '', img = ''; + if(file.ext){ + file.ext = file.ext.toLowerCase(); + } + if(file.name){ + file.name = file.name.toLowerCase(); + } + if (file.ext === 'doc' || file.ext === 'docx') { + img = '../../../images/docx.png'; + } else if (file.ext === 'xls' || file.ext === 'xlsx') { + img = '../../../images/xlsx.png'; + } else if (file.ext === 'pdf') { + img = '../../../images/pdf.png'; + } else { + return ''; + } + html += '
' + + '' + + '

' + file.name + '

' + + '
'; + return html; +} + + +// // 验证 formDataTwo 表单 +// function validateFormDataTwo(data) { +// // 这里可以添加具体的表单验证逻辑 +// // 例如,检查某些字段是否为空 +// const requiredFields = ['carLength', 'carWidth', 'carHeight', 'carWeight','carStart','carEnd']; +// for (let i = 0; i < requiredFields.length; i++) { +// const field = requiredFields[i]; +// if (!data.field[field]) { +// layer.msg(`${field} 是必填项`, { icon: 7 }); +// return false; +// } +// } +// return true; +// } + +function toggleDetails(detailId,applyType) { + console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",applyType) + const detailElement = document.getElementById(detailId); + if (detailElement.style.display === 'none') { + detailElement.style.display = 'block'; + } else { + detailElement.style.display = 'none'; + } + if (applyType === 'vehicle') { + // 重置运输车辆明细表单 + var form = document.getElementById('formTwo'); + if (form) { + form.reset(); + } + var tableBody = document.getElementById('baseTableYS').getElementsByTagName('tbody')[0]; + if (tableBody) { + tableBody.innerHTML = ''; + } + } +} + // 工程下拉选 function getProList() { let url = dataUrl + 'backstage/planApply/getProSelect'; @@ -50,6 +192,11 @@ function setSelectData(proList) { function saveData2() { $('#formSubmit').trigger('click') + const isVehicleChecked = $('input[name="applyType"][value="vehicle"]').is(':checked'); + if (isVehicleChecked) { + $('#formSubmitTwo').trigger('click') + } + } function setNumColor(value, type) { // 1.需要量 2.已发货量 3.差缺量 @@ -68,7 +215,14 @@ function setNumColor(value, type) { // 1.需要量 2.已发货量 3.差缺量 // 提交 function submitApply(data) { let list = getBaseTableData(); - // 校验配件入库数量 + const isVehicleChecked = $('input[name="applyType"][value="vehicle"]').is(':checked'); + if (isVehicleChecked) { + // 校验附件是否上传 + if (fileList.length === 0) { + return layer.msg('请上传附件', { icon: 7 }); + } + } + //校验配件入库数量 if (list.length === 0) { return layer.msg('未添加安全工器具明细数据', { icon: 7 }); } @@ -130,11 +284,25 @@ function getBaseTableData() { // 选择需求计划安全工器具类型 -function chooseFitType() { +function chooseFitTypeTwo() { let params = {}; - openIframeByParamObj("choose_type", '选择需求计划安全工器具类型', "./choose_type_list.html", '92%', '95%', params); + openIframeByParamObj("choose_type_two", '选择需求计划安全工器具类型', "./choose_type_list.html", '92%', '95%', params); +} +// 选择机具类型 +function chooseFitTypeOne() { + let params = {}; + openIframeByParamObj("choose_type_one", '选择需求计划机具类型(设备类请备注大、中、小)', "./choose_tool_type_list.html", '92%', '95%', params); +} +// 选择车辆类型 +function chooseFitTypeThree() { + let params = {}; + openIframeByParamObj("choose_type_three", '选择需求计划安车辆类型', "./choose_crane_type_list.html", '92%', '95%', params); +} +//选择吊车类型 +function chooseFitTypeFour() { + let params = {}; + openIframeByParamObj("choose_type_four", '选择需求计划吊车类型', "./choose_vehicle_type_list.html", '92%', '95%', params); } - // 查询 function search() { let keyWord = $('#modelName').val(); @@ -167,8 +335,9 @@ function resetSearch() { } // 子页面回调数据 -function addFitDatas(data) { +function addFitDatas(data,pageSource) { console.log('新增的数据:' + data); + console.log('回调的页面:' + pageSource); if (jjDataArr.length > 0) { // 继续添加数据 let newJjDataArr = JSON.parse(data); $.each(newJjDataArr, function (index, item) { @@ -179,9 +348,9 @@ function addFitDatas(data) { } else { // 第一次添加数据 jjDataArr = JSON.parse(data); if (jjDataArr && jjDataArr.length > 0) { - $('#no_data_title').css({ 'display': 'none' }); - $('#search-info').removeAttr('style'); - $('#table-box').removeAttr('style'); + $('#no_data_titleJJ').css({ 'display': 'none' }); + $('#search-infoJJ').removeAttr('style'); + $('#table-boxJJ').removeAttr('style'); setTableData(jjDataArr); } } diff --git a/js/aq_demand_plan/child/choose_crane_type_list.js b/js/aq_demand_plan/child/choose_crane_type_list.js new file mode 100644 index 0000000..6eb73dc --- /dev/null +++ b/js/aq_demand_plan/child/choose_crane_type_list.js @@ -0,0 +1,339 @@ +let objParam; +let form, table, element, tableIns, layer, util; +let pageNum = 1; +let quanju = new Array();//全局 +let huancun = new Array();//缓存 +let huancunObj = new Array();//缓存2 +let cjList = []; +let jjDetailArr = []; // 入库配件类型数据 +function setParams(obj) { + objParam = JSON.parse(obj); + layui.use(["form", "table", 'element', 'layer', 'util'], function () { + form = layui.form; + table = layui.table; + element = layui.element; + layer = layui.layer; + util = layui.util; + initTable(); + }); +} + +// 查询/重置 +function queryTable(type) { + if (type === 1) { + let pName = $('#pName').val(); + let flag = checkValue(pName); + if (flag) { + $('#pName').val(''); + return layer.msg('物机名称查询包含特殊字符,请重新输入', { icon: 2 }); + } + let name = $('#name').val(); + let flag2 = checkValue(name); + if (flag2) { + $('#name').val(''); + return layer.msg('规格查询包含特殊字符,请重新输入', { icon: 2 }); + } + reloadTable(1); + } else if (type === 2) { + $('#pName').val(''); + $('#name').val(''); + layui.form.render(); + reloadTable(1); + } +} + +// 重载表格 +function reloadTable(pageNum) { + table.reload("currentTableId", { + page: { + curr: pageNum ? pageNum : 1, + }, + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + }, + ); +} + + +// 表格数据 +function initTable() { + tableIns = table.render({ + elem: "#currentTableId", + id: 'currentTableId', + height: "full-200", + headers: { + authorization: sessionStorage.getItem("gz-token"), + }, + url: dataUrl + "backstage/planApplication/getTypeList", + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + request: { + pageName: 'pageNum', + limitName: 'pageSize' + }, + parseData: function (res) { // res 即为原始返回的数据 + if(res.code === 401){ + closeWindowOpen(); + } + if (jjDetailArr && res.list) { + $.each(res.list, function (index, item) { + $.each(jjDetailArr, function (index2, item2) { + if (item.id === item2.id) { + item.needNum = item2.needNum; + item.tiems = item2.tiems; + item.remarks = item2.remarks; + } + }); + }); + } + return { + "code": 0, // 解析接口状态 + "msg": '获取成功', // 解析提示文本 + "count": res.total, // 解析数据长度 + "data": res.list // 解析数据列表 + }; + }, + cols: [ + [ + { type: 'checkbox', width: '5%' }, + { + width: '6%', + title: "序号", + align: "center", + templet: function (d) { + return d.LAY_NUM; + }, + }, + { + field: "ppName", + width: '10%', + title: "物机类型", + unresize: true, + align: "center", + sort:true, + }, + { + field: "pName", + width: '10%', + title: "物机名称", + unresize: true, + align: "center", + sort:true, + }, + { + field: "name", + width: '10%', + title: "规格", + unresize: true, + align: "center", + sort:true, + }, + { + field: "unit", + title: "单位", + width: '10%', + unresize: true, + align: "center", + sort:true, + }, + { + field: "needNum", + width: '15%', + title: " * 需用量", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + { + field: "times", + width: '15%', + title: " * 需用天数", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;', + }, + { + field: "remarks", + width: '18.9%', + title: "备注", + unresize: true, + align: "center", + edit: 'textarea', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + + ], + ], + limits: [10, 15, 20, 25, 50, 100], + limit: 10, + page: true, + done: function (res, curr, count) { + table.resize("currentTableId"); + pageNum = tableIns.config.page.curr; + //设置全部数据到全局变量 + quanju = res.data; + for (var i = 0; i < res.data.length; i++) { + for (var j = 0; j < huancun.length; j++) { + //数据id和要勾选的id相同时checkbox选中 + if (res.data[i].id === huancun[j]) { + //这里才是真正的有效勾选 + res.data[i]["LAY_CHECKED"] = 'true'; + //找到对应数据改变勾选样式,呈现出选中效果 + var index = res.data[i]['LAY_INDEX']; + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true); + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked'); + } + } + } + //设置全选checkbox的选中状态,只有改变LAY_CHECKED的值, table.checkStatus才能抓取到选中的状态 + let checkStatus = table.checkStatus('currentTableId');//这里的lightTable是指分页中的id + if (checkStatus.isAll) {//是否全选 + //layTableAllChoose + $('.layui-table th[data-field="0"] input[type="checkbox"]').prop('checked', true);//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + $('.layui-table th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + } + }, + }); + table.on('edit(currentTableId2)', function (obj) { + var field = obj.field; // 得到修改的字段 + var value = obj.value // 得到修改后的值 + if (field === 'needNum' || field === 'times') { // 需用量 / 需用天数 + if (value) { + const regex = /^(0|[1-9]\d{0,6})$/; + if (!regex.test(value)) { + obj.reedit(); + return layer.msg('格式不正确,最大输入6位数,且为正整数!', { icon: 7 }) + } + } + } else if (field === 'remarks') { // 备注 + if (value) { + if (value.length > 255) { + obj.reedit(); + return layer.msg('备注最多输入255位!', { icon: 7 }) + } + } + } + // 显示 - 仅用于演示 + // layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改值为:' + util.escape(value)); + let id = obj.data.id; + updateOrAddObject(id, obj.data); + }); + //复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组 + table.on('checkbox(currentTableId2)', function (obj) { + if (obj.checked === true) { + if (obj.type === 'one' && huancun.indexOf(obj.data.id) === -1) { + huancun.push(obj.data.id); + huancunObj.push(obj.data); + } else { + for (let i = 0; i < quanju.length; i++) { + if (huancun.indexOf(quanju[i].id) === -1) { + huancun.push(quanju[i].id); + huancunObj.push(quanju[i]); + } + } + } + } else { + if (obj.type === 'one') { + for (let i = 0; i < huancun.length; i++) { + if (huancun[i] === obj.data.id) { + removeByValue(huancun, huancun[i]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, huancunObj[i]);//调用自定义的根据值移除函数 + } + } + } else { + for (let i = 0; i < quanju.length; i++) { + for (let j = 0; j < huancun.length; j++) { + if (huancun[j] === quanju[i].id) { + removeByValue(huancun, +huancun[j]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, +huancunObj[j]);//调用自定义的根据值移除函数 + } + } + } + } + } + $('#num').html(huancun.length); + }); +} + +// 根据id 判断对象数组的对象是否存在 如果存在则替换,不存在则添加 +function updateOrAddObject(id, newObject) { + const index = jjDetailArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + jjDetailArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + jjDetailArr.push(newObject); + } +} + + +//自定义方法,根据值去移除 +function removeByValue(arr, val) { + for (let i = 0; i < arr.length; i++) { + if (arr[i] == val) { + arr.splice(i, 1); + break; + } + } + for (let i = 0; i < huancunObj.length; i++) { + if (huancunObj[i].id == val) { + huancunObj.splice(i, 1); + break; + } + } +} + +// 保存数据 +function saveData2(params) { + let dataArr = []; + if (huancun.length === 0) { + return layer.msg('未添加数据', { icon: 7 }); + } else { + $.each(huancunObj, function (index, item) { + dataArr.push(item); + }) + for (let i = 0; i < huancun.length; i++) { + const id = huancun[i]; + for (let j = 0; j < jjDetailArr.length; j++) { + const obj = jjDetailArr[j]; + if (id === obj.id) { + updateOrAddObject2(id, obj); + } + } + } + } + let layerIndex = layer.confirm('
数据即将被添加,请仔细检查数据是否有错误!
', { title: '操作提示' }, function () { + layer.close(layerIndex); + closePage(1, JSON.stringify(dataArr)); + }); + // 替换对象 + function updateOrAddObject2(id, newObject) { + const index = dataArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + dataArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + dataArr.push(newObject); + } + } +} + +function closePage(type, params) { + let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 + if (type == 1) { + window.parent.addFitDatas(params); + } + parent.layer.close(index); // 再执行关闭 +} \ No newline at end of file diff --git a/js/aq_demand_plan/child/choose_tool_type_list.js b/js/aq_demand_plan/child/choose_tool_type_list.js new file mode 100644 index 0000000..57feb24 --- /dev/null +++ b/js/aq_demand_plan/child/choose_tool_type_list.js @@ -0,0 +1,338 @@ +let objParam; +let form, table, element, tableIns, layer, util; +let pageNum = 1; +let quanju = new Array();//全局 +let huancun = new Array();//缓存 +let huancunObj = new Array();//缓存2 +let cjList = []; +let jjDetailArr = []; // 入库配件类型数据 +function setParams(obj) { + objParam = JSON.parse(obj); + layui.use(["form", "table", 'element', 'layer', 'util'], function () { + form = layui.form; + table = layui.table; + element = layui.element; + layer = layui.layer; + util = layui.util; + initTable(); + }); +} + +// 查询/重置 +function queryTable(type) { + if (type === 1) { + let pName = $('#pName').val(); + let flag = checkValue(pName); + if (flag) { + $('#pName').val(''); + return layer.msg('物机名称查询包含特殊字符,请重新输入', { icon: 2 }); + } + let name = $('#name').val(); + let flag2 = checkValue(name); + if (flag2) { + $('#name').val(''); + return layer.msg('规格查询包含特殊字符,请重新输入', { icon: 2 }); + } + reloadTable(1); + } else if (type === 2) { + $('#pName').val(''); + $('#name').val(''); + layui.form.render(); + reloadTable(1); + } +} + +// 重载表格 +function reloadTable(pageNum) { + table.reload("currentTableId", { + page: { + curr: pageNum ? pageNum : 1, + }, + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + }, + ); +} + +// 表格数据 +function initTable() { + tableIns = table.render({ + elem: "#currentTableId", + id: 'currentTableId', + height: "full-200", + headers: { + authorization: sessionStorage.getItem("gz-token"), + }, + url: dataUrl + "backstage/planApplication/getTypeList", + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + request: { + pageName: 'pageNum', + limitName: 'pageSize' + }, + parseData: function (res) { // res 即为原始返回的数据 + if(res.code === 401){ + closeWindowOpen(); + } + if (jjDetailArr && res.list) { + $.each(res.list, function (index, item) { + $.each(jjDetailArr, function (index2, item2) { + if (item.id === item2.id) { + item.needNum = item2.needNum; + item.tiems = item2.tiems; + item.remarks = item2.remarks; + } + }); + }); + } + return { + "code": 0, // 解析接口状态 + "msg": '获取成功', // 解析提示文本 + "count": res.total, // 解析数据长度 + "data": res.list // 解析数据列表 + }; + }, + cols: [ + [ + { type: 'checkbox', width: '5%' }, + { + width: '6%', + title: "序号", + align: "center", + templet: function (d) { + return d.LAY_NUM; + }, + }, + { + field: "ppName", + width: '10%', + title: "物机类型", + unresize: true, + align: "center", + sort:true, + }, + { + field: "pName", + width: '10%', + title: "物机名称", + unresize: true, + align: "center", + sort:true, + }, + { + field: "name", + width: '10%', + title: "规格", + unresize: true, + align: "center", + sort:true, + }, + { + field: "unit", + title: "单位", + width: '10%', + unresize: true, + align: "center", + sort:true, + }, + { + field: "needNum", + width: '15%', + title: " * 需用量", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + { + field: "times", + width: '15%', + title: " * 需用天数", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;', + }, + { + field: "remarks", + width: '18.9%', + title: "备注", + unresize: true, + align: "center", + edit: 'textarea', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + + ], + ], + limits: [10, 15, 20, 25, 50, 100], + limit: 10, + page: true, + done: function (res, curr, count) { + table.resize("currentTableId"); + pageNum = tableIns.config.page.curr; + //设置全部数据到全局变量 + quanju = res.data; + for (var i = 0; i < res.data.length; i++) { + for (var j = 0; j < huancun.length; j++) { + //数据id和要勾选的id相同时checkbox选中 + if (res.data[i].id === huancun[j]) { + //这里才是真正的有效勾选 + res.data[i]["LAY_CHECKED"] = 'true'; + //找到对应数据改变勾选样式,呈现出选中效果 + var index = res.data[i]['LAY_INDEX']; + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true); + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked'); + } + } + } + //设置全选checkbox的选中状态,只有改变LAY_CHECKED的值, table.checkStatus才能抓取到选中的状态 + let checkStatus = table.checkStatus('currentTableId');//这里的lightTable是指分页中的id + if (checkStatus.isAll) {//是否全选 + //layTableAllChoose + $('.layui-table th[data-field="0"] input[type="checkbox"]').prop('checked', true);//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + $('.layui-table th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + } + }, + }); + table.on('edit(currentTableId2)', function (obj) { + var field = obj.field; // 得到修改的字段 + var value = obj.value // 得到修改后的值 + if (field === 'needNum' || field === 'times') { // 需用量 / 需用天数 + if (value) { + const regex = /^(0|[1-9]\d{0,6})$/; + if (!regex.test(value)) { + obj.reedit(); + return layer.msg('格式不正确,最大输入6位数,且为正整数!', { icon: 7 }) + } + } + } else if (field === 'remarks') { // 备注 + if (value) { + if (value.length > 255) { + obj.reedit(); + return layer.msg('备注最多输入255位!', { icon: 7 }) + } + } + } + // 显示 - 仅用于演示 + // layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改值为:' + util.escape(value)); + let id = obj.data.id; + updateOrAddObject(id, obj.data); + }); + //复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组 + table.on('checkbox(currentTableId2)', function (obj) { + if (obj.checked === true) { + if (obj.type === 'one' && huancun.indexOf(obj.data.id) === -1) { + huancun.push(obj.data.id); + huancunObj.push(obj.data); + } else { + for (let i = 0; i < quanju.length; i++) { + if (huancun.indexOf(quanju[i].id) === -1) { + huancun.push(quanju[i].id); + huancunObj.push(quanju[i]); + } + } + } + } else { + if (obj.type === 'one') { + for (let i = 0; i < huancun.length; i++) { + if (huancun[i] === obj.data.id) { + removeByValue(huancun, huancun[i]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, huancunObj[i]);//调用自定义的根据值移除函数 + } + } + } else { + for (let i = 0; i < quanju.length; i++) { + for (let j = 0; j < huancun.length; j++) { + if (huancun[j] === quanju[i].id) { + removeByValue(huancun, +huancun[j]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, +huancunObj[j]);//调用自定义的根据值移除函数 + } + } + } + } + } + $('#num').html(huancun.length); + }); +} + +// 根据id 判断对象数组的对象是否存在 如果存在则替换,不存在则添加 +function updateOrAddObject(id, newObject) { + const index = jjDetailArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + jjDetailArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + jjDetailArr.push(newObject); + } +} + + +//自定义方法,根据值去移除 +function removeByValue(arr, val) { + for (let i = 0; i < arr.length; i++) { + if (arr[i] == val) { + arr.splice(i, 1); + break; + } + } + for (let i = 0; i < huancunObj.length; i++) { + if (huancunObj[i].id == val) { + huancunObj.splice(i, 1); + break; + } + } +} + +// 保存数据 +function saveData2(params) { + let dataArr = []; + if (huancun.length === 0) { + return layer.msg('未添加数据', { icon: 7 }); + } else { + $.each(huancunObj, function (index, item) { + dataArr.push(item); + }) + for (let i = 0; i < huancun.length; i++) { + const id = huancun[i]; + for (let j = 0; j < jjDetailArr.length; j++) { + const obj = jjDetailArr[j]; + if (id === obj.id) { + updateOrAddObject2(id, obj); + } + } + } + } + let layerIndex = layer.confirm('
数据即将被添加,请仔细检查数据是否有错误!
', { title: '操作提示' }, function () { + layer.close(layerIndex); + closePage(1, JSON.stringify(dataArr),"page1"); + }); + // 替换对象 + function updateOrAddObject2(id, newObject) { + const index = dataArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + dataArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + dataArr.push(newObject); + } + } +} + +function closePage(type, params,pageSource) { + let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 + if (type == 1) { + window.parent.addFitDatas(params,pageSource); + } + parent.layer.close(index); // 再执行关闭 +} \ No newline at end of file diff --git a/js/aq_demand_plan/child/choose_vehicle_type_list.js b/js/aq_demand_plan/child/choose_vehicle_type_list.js new file mode 100644 index 0000000..6eb73dc --- /dev/null +++ b/js/aq_demand_plan/child/choose_vehicle_type_list.js @@ -0,0 +1,339 @@ +let objParam; +let form, table, element, tableIns, layer, util; +let pageNum = 1; +let quanju = new Array();//全局 +let huancun = new Array();//缓存 +let huancunObj = new Array();//缓存2 +let cjList = []; +let jjDetailArr = []; // 入库配件类型数据 +function setParams(obj) { + objParam = JSON.parse(obj); + layui.use(["form", "table", 'element', 'layer', 'util'], function () { + form = layui.form; + table = layui.table; + element = layui.element; + layer = layui.layer; + util = layui.util; + initTable(); + }); +} + +// 查询/重置 +function queryTable(type) { + if (type === 1) { + let pName = $('#pName').val(); + let flag = checkValue(pName); + if (flag) { + $('#pName').val(''); + return layer.msg('物机名称查询包含特殊字符,请重新输入', { icon: 2 }); + } + let name = $('#name').val(); + let flag2 = checkValue(name); + if (flag2) { + $('#name').val(''); + return layer.msg('规格查询包含特殊字符,请重新输入', { icon: 2 }); + } + reloadTable(1); + } else if (type === 2) { + $('#pName').val(''); + $('#name').val(''); + layui.form.render(); + reloadTable(1); + } +} + +// 重载表格 +function reloadTable(pageNum) { + table.reload("currentTableId", { + page: { + curr: pageNum ? pageNum : 1, + }, + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + }, + ); +} + + +// 表格数据 +function initTable() { + tableIns = table.render({ + elem: "#currentTableId", + id: 'currentTableId', + height: "full-200", + headers: { + authorization: sessionStorage.getItem("gz-token"), + }, + url: dataUrl + "backstage/planApplication/getTypeList", + where: { + encryptedData: JSON.stringify({ + 'pName': $('#pName').val(), + 'name': $('#name').val(), + }), + }, + request: { + pageName: 'pageNum', + limitName: 'pageSize' + }, + parseData: function (res) { // res 即为原始返回的数据 + if(res.code === 401){ + closeWindowOpen(); + } + if (jjDetailArr && res.list) { + $.each(res.list, function (index, item) { + $.each(jjDetailArr, function (index2, item2) { + if (item.id === item2.id) { + item.needNum = item2.needNum; + item.tiems = item2.tiems; + item.remarks = item2.remarks; + } + }); + }); + } + return { + "code": 0, // 解析接口状态 + "msg": '获取成功', // 解析提示文本 + "count": res.total, // 解析数据长度 + "data": res.list // 解析数据列表 + }; + }, + cols: [ + [ + { type: 'checkbox', width: '5%' }, + { + width: '6%', + title: "序号", + align: "center", + templet: function (d) { + return d.LAY_NUM; + }, + }, + { + field: "ppName", + width: '10%', + title: "物机类型", + unresize: true, + align: "center", + sort:true, + }, + { + field: "pName", + width: '10%', + title: "物机名称", + unresize: true, + align: "center", + sort:true, + }, + { + field: "name", + width: '10%', + title: "规格", + unresize: true, + align: "center", + sort:true, + }, + { + field: "unit", + title: "单位", + width: '10%', + unresize: true, + align: "center", + sort:true, + }, + { + field: "needNum", + width: '15%', + title: " * 需用量", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + { + field: "times", + width: '15%', + title: " * 需用天数", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;', + }, + { + field: "remarks", + width: '18.9%', + title: "备注", + unresize: true, + align: "center", + edit: 'textarea', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + + ], + ], + limits: [10, 15, 20, 25, 50, 100], + limit: 10, + page: true, + done: function (res, curr, count) { + table.resize("currentTableId"); + pageNum = tableIns.config.page.curr; + //设置全部数据到全局变量 + quanju = res.data; + for (var i = 0; i < res.data.length; i++) { + for (var j = 0; j < huancun.length; j++) { + //数据id和要勾选的id相同时checkbox选中 + if (res.data[i].id === huancun[j]) { + //这里才是真正的有效勾选 + res.data[i]["LAY_CHECKED"] = 'true'; + //找到对应数据改变勾选样式,呈现出选中效果 + var index = res.data[i]['LAY_INDEX']; + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true); + $('.layui-table tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked'); + } + } + } + //设置全选checkbox的选中状态,只有改变LAY_CHECKED的值, table.checkStatus才能抓取到选中的状态 + let checkStatus = table.checkStatus('currentTableId');//这里的lightTable是指分页中的id + if (checkStatus.isAll) {//是否全选 + //layTableAllChoose + $('.layui-table th[data-field="0"] input[type="checkbox"]').prop('checked', true);//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + $('.layui-table th[data-field="0"] input[type="checkbox"]').next().addClass('layui-form-checked');//data-field值默认为0,如果在分页部分自定义了属性名,则需要改成对应的属性名 + } + }, + }); + table.on('edit(currentTableId2)', function (obj) { + var field = obj.field; // 得到修改的字段 + var value = obj.value // 得到修改后的值 + if (field === 'needNum' || field === 'times') { // 需用量 / 需用天数 + if (value) { + const regex = /^(0|[1-9]\d{0,6})$/; + if (!regex.test(value)) { + obj.reedit(); + return layer.msg('格式不正确,最大输入6位数,且为正整数!', { icon: 7 }) + } + } + } else if (field === 'remarks') { // 备注 + if (value) { + if (value.length > 255) { + obj.reedit(); + return layer.msg('备注最多输入255位!', { icon: 7 }) + } + } + } + // 显示 - 仅用于演示 + // layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改值为:' + util.escape(value)); + let id = obj.data.id; + updateOrAddObject(id, obj.data); + }); + //复选框选中监听,将选中的id 设置到缓存数组,或者删除缓存数组 + table.on('checkbox(currentTableId2)', function (obj) { + if (obj.checked === true) { + if (obj.type === 'one' && huancun.indexOf(obj.data.id) === -1) { + huancun.push(obj.data.id); + huancunObj.push(obj.data); + } else { + for (let i = 0; i < quanju.length; i++) { + if (huancun.indexOf(quanju[i].id) === -1) { + huancun.push(quanju[i].id); + huancunObj.push(quanju[i]); + } + } + } + } else { + if (obj.type === 'one') { + for (let i = 0; i < huancun.length; i++) { + if (huancun[i] === obj.data.id) { + removeByValue(huancun, huancun[i]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, huancunObj[i]);//调用自定义的根据值移除函数 + } + } + } else { + for (let i = 0; i < quanju.length; i++) { + for (let j = 0; j < huancun.length; j++) { + if (huancun[j] === quanju[i].id) { + removeByValue(huancun, +huancun[j]);//调用自定义的根据值移除函数 + removeByValue(huancunObj, +huancunObj[j]);//调用自定义的根据值移除函数 + } + } + } + } + } + $('#num').html(huancun.length); + }); +} + +// 根据id 判断对象数组的对象是否存在 如果存在则替换,不存在则添加 +function updateOrAddObject(id, newObject) { + const index = jjDetailArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + jjDetailArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + jjDetailArr.push(newObject); + } +} + + +//自定义方法,根据值去移除 +function removeByValue(arr, val) { + for (let i = 0; i < arr.length; i++) { + if (arr[i] == val) { + arr.splice(i, 1); + break; + } + } + for (let i = 0; i < huancunObj.length; i++) { + if (huancunObj[i].id == val) { + huancunObj.splice(i, 1); + break; + } + } +} + +// 保存数据 +function saveData2(params) { + let dataArr = []; + if (huancun.length === 0) { + return layer.msg('未添加数据', { icon: 7 }); + } else { + $.each(huancunObj, function (index, item) { + dataArr.push(item); + }) + for (let i = 0; i < huancun.length; i++) { + const id = huancun[i]; + for (let j = 0; j < jjDetailArr.length; j++) { + const obj = jjDetailArr[j]; + if (id === obj.id) { + updateOrAddObject2(id, obj); + } + } + } + } + let layerIndex = layer.confirm('
数据即将被添加,请仔细检查数据是否有错误!
', { title: '操作提示' }, function () { + layer.close(layerIndex); + closePage(1, JSON.stringify(dataArr)); + }); + // 替换对象 + function updateOrAddObject2(id, newObject) { + const index = dataArr.findIndex(obj => obj.id === id); + if (index !== -1) { + // 如果对象存在,则替换它 + dataArr[index] = newObject; + } else { + // 如果对象不存在,则添加到数组 + dataArr.push(newObject); + } + } +} + +function closePage(type, params) { + let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 + if (type == 1) { + window.parent.addFitDatas(params); + } + parent.layer.close(index); // 再执行关闭 +} \ No newline at end of file diff --git a/page/aq_demand_plan/child/apply_plan_form.html b/page/aq_demand_plan/child/apply_plan_form.html index aee8c9d..79178ac 100644 --- a/page/aq_demand_plan/child/apply_plan_form.html +++ b/page/aq_demand_plan/child/apply_plan_form.html @@ -51,6 +51,17 @@ +
+
+ +
+ + + + +
+
+
@@ -58,10 +69,75 @@ class="layui-textarea" maxLength="250" lay-affix="clear">
- + -
+ + +
@@ -121,7 +197,209 @@ + + + + +
@@ -133,5 +411,4 @@ - \ No newline at end of file diff --git a/page/aq_demand_plan/child/choose_crane_type_list.html b/page/aq_demand_plan/child/choose_crane_type_list.html new file mode 100644 index 0000000..33b4a26 --- /dev/null +++ b/page/aq_demand_plan/child/choose_crane_type_list.html @@ -0,0 +1,86 @@ + + + + + + + 需求计划机具类型 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+

已选:0

+
+
+
+
+
+
+
+
+
+ + +
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/page/aq_demand_plan/child/choose_tool_type_list.html b/page/aq_demand_plan/child/choose_tool_type_list.html new file mode 100644 index 0000000..33b4a26 --- /dev/null +++ b/page/aq_demand_plan/child/choose_tool_type_list.html @@ -0,0 +1,86 @@ + + + + + + + 需求计划机具类型 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+

已选:0

+
+
+
+
+
+
+
+
+
+ + +
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/page/aq_demand_plan/child/choose_vehicle_type_list.html b/page/aq_demand_plan/child/choose_vehicle_type_list.html new file mode 100644 index 0000000..33b4a26 --- /dev/null +++ b/page/aq_demand_plan/child/choose_vehicle_type_list.html @@ -0,0 +1,86 @@ + + + + + + + 需求计划机具类型 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+

已选:0

+
+
+
+
+
+
+
+
+
+ + +
+
+
+ + + + + + + + + \ No newline at end of file