let idParam,objParam,fileList = new Array(), imgListUp = new Array(); let form,laydate,layer,upload,table,util; let jjDataArr = []; // 新增需求计划外机具的数据 let jjDetailArr = []; // 机具明细数据 function setParams(id) { idParam = id; layui.use([ 'form', 'layer','laydate','upload','table'], function() { form = layui.form; layer = layui.layer; laydate = layui.laydate; upload = layui.upload; table = layui.table; util = layui.util; laydate.render({ elem: '#time' }); form.verify(); form.on('submit(formData)', function(data) { submitApply(data); }); 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 = ''; obj.preview(function (index, file, result) { console.log(file); $('#uploader-list').append( '
' + '

x

' + handleFileType(index, file, result) + '
' ); let map = new Map();//将选择的图片索引和图片写成对象存入集合 map.index = index; map.file = file; fileList.push(map); }); } }); initTable(); }); } // 设置文件类型 function handleFileType(index, file, result) { let html = '',img = ''; 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; } // 删除文件 $(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 initTable() { let dataList = [ { id: "1", username: "张三", num: 1, num2: 1, status: "部分发货", progress: 30, lastSendTime:'2024-11-07 12:00:00', 'xyl':'1', 'fhl':'1' }, { id: "2", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00', 'xyl':'1', 'fhl':'1' }, { id: "3", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00', 'xyl':'1', 'fhl':'1' }, { id: "4", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00', 'xyl':'1', 'fhl':'1' }, { id: "5", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00', 'xyl':'1', 'fhl':'1' }, { id: "6", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, { id: "7", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, { id: "8", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, { id: "9", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, { id: "10", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, { id: "11", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07' }, { id: "12", username: "李四", num: 1, num2: 2, status: "全部发货", progress: 150, lastSendTime:'2024-11-07 12:00:00' }, ]; table.render({ elem: "#currentTableId", id:'currentTableId', data: dataList, height: "full", // url: "../api/table.json", parseData: function(res){ console.error(res); }, cols: [ [ { width: 80, title: "序号", align: "center", templet: function (d) { return d.LAY_NUM; }, }, { field: "username", width: 150, title: "物机类型", unresize: true, align: "center", }, { field: "num", width: 150, title: "物机名称", unresize: true, align: "center", templet: function (d) { // return setNumColor(d.num); }, }, { field: "num2", width: 120, title: "规格 ", unresize: true, align: "center", templet: function (d) { // return setNumColor(d.num2); }, }, { field: "unit", title: "单位", width: 120, unresize: true, align: "center", }, { field: "xyl", width: 120, title: "需要量", unresize: true, align: "center", }, { field: "yfhl", width: 120, title: "已发货量", unresize: true, align: "center", }, { field: "cql", width: 120, title: "差缺量", unresize: true, align: "center", }, { field: "fhl", width: 150, title: " * 本次发货量", unresize: true, align: "center", edit:'text', style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' }, { field: "tzl", width: 150, title: "调整量", unresize: true, align: "center", edit:'text', style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' }, { field: "remark", width: 250, 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) { $("#tips").suspensionTips({"content": "1.如需单个机具进度达到100%,请填写不发货的数量;2.若填写不发货数量,请填写备注不发货原因及附件说明", position:"top", width:300}); }, }); table.on('edit(currentTableId)', function(obj){ console.log(obj); var field = obj.field; // 得到修改的字段 var value = obj.value // 得到修改后的值 var oldValue = obj.oldValue // 得到修改前的值 -- v2.8.0 新增 var data = obj.data // 得到所在行所有键值 var col = obj.getCol(); // 得到当前列的表头配置属性 -- v2.8.0 新增 if(field === 'fhl' || field === 'tzl'){ // 本次发货量/调整量 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 === 'remark'){ // 备注 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; let fhl = obj.data.fhl; let tzl = obj.data.tzl; let remark = obj.data.remark; let objParam = { id:id, fhl:fhl, tzl:tzl, remark:remark } updateOrAddObject(id,objParam); }); } // 根据id 判断对象数组的对象是否存在 如果存在则替换,不存在则添加 function updateOrAddObject(id, newObject) { const index = jjDetailArr.findIndex(obj => obj.id === id); if (index !== -1) { // 如果对象存在,则替换它 jjDetailArr[index] = newObject; } else { // 如果对象不存在,则添加到数组 jjDetailArr.push(newObject); } } function saveData2() { $('#formSubmit').trigger('click') } // 提交 function submitApply(data) { data.field.jjDataArr = jjDetailArr; data.field.jjDetailArr = jjDetailArr; let formData = new FormData(); //遍历最终文件集合 for (let i = 0; i < fileList.length; i++) { formData.append("file[]", fileList[i].file) } formData.append('params',JSON.stringify(data.field)); /* let loadingMsg = layer.msg('正在提交保存,请稍等...', { icon : 16, shade : 0.01, time : '0' }); */ console.log(JSON.stringify(data.field)); data.field.applyId = idParam; } // 处理数字 function handleNum(value){ if(!value){ return null; } const regex = /^(0|[1-9]\d{0,6})$/; if(!regex.test(value)){ return layer.msg('格式不正确,最大输入6位数,且为正整数!',{icon:7}) } return null; } // 详情 function openDetail(){ alert('详情'); } // 新增需求计划外机具 function addJjData(){ let params = '-1'; if(jjDataArr && jjDataArr.length > 0){ params = JSON.stringify(jjDataArr); } openIframeByParam("addJjData", '新增需求计划外机具', "./add_jj_data.html", '72%', '80%',params); } function addJjDatas(data){ console.log('新增的数据:'+data); jjDataArr = JSON.parse(data); } // 关闭页面 function closePage(type) { let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 parent.layer.close(index); // 再执行关闭 if (type == 1) { window.parent.closePage(); } }