diff --git a/js/accessory/child/choose_inventory_count_fit_type_list.js b/js/accessory/child/choose_inventory_count_fit_type_list.js new file mode 100644 index 0000000..15b4577 --- /dev/null +++ b/js/accessory/child/choose_inventory_count_fit_type_list.js @@ -0,0 +1,379 @@ +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); + console.log(objParam); + layui.use(["form", "table", 'element', 'layer', 'util'], function () { + form = layui.form; + table = layui.table; + element = layui.element; + layer = layui.layer; + util = layui.util; + getVendList(); + initTable(); + }); +} + +// 厂家下拉选 +function getVendList() { + cjList.splice(0, cjList.length); + let encryptedData = {}; + let url = dataUrl + 'backstage/paType/getVendList?encryptedData=' + encodeURIComponent(JSON.stringify(encryptedData)); + ajaxRequest(url, "GET", null, false, function () { + }, function (result) { + console.log(result); + if (result.code === 200) { + cjList = result.data; + } + }, function (xhr, status, error) { + errorFn(xhr, status, error) + }, null); +} + +// 查询/重置 +function queryTable(type) { + if (type === 1) { + reloadTable(1); + } else if (type === 2) { + $('#name').val(''); + $('#module').val(''); + $('#type').val(''); + layui.form.render(); + reloadTable(1); + } +} + +// 重载表格 +function reloadTable(pageNum) { + table.reload("currentTableId", { + page: { + curr: pageNum ? pageNum : 1, + }, + where: { + encryptedData: JSON.stringify({ + 'name': $('#name').val(), + 'model': $('#model').val(), + 'type': $('#type').val(), + }), + }, + }, + ); +} + + +// 表格数据 +function initTable() { + tableIns = table.render({ + elem: "#currentTableId", + id: 'currentTableId', + height: "full-200", + headers: { + authorization: sessionStorage.getItem("gz-token"), + }, + url: dataUrl + "backstage/paType/findByPage", + where: { + encryptedData: JSON.stringify({ + 'type': $('#type').val(), + 'name': $('#name').val(), + 'model': $('#model').val(), + }), + }, + request: { + pageName: 'pageNum', + limitName: 'pageSize' + }, + parseData: function (res) { // res 即为原始返回的数据 + if (jjDetailArr && res.list) { + $.each(res.list, function (index, item) { + $.each(jjDetailArr, function (index2, item2) { + if (item.id === item2.id) { + item.num = item2.num; + item.price = item2.price; + item.remarks = item2.remarks; + item.manufacturer = item2.manufacturer; + } + }); + }); + } + 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: "type", + width: '11.8%', + title: "配件类型", + unresize: true, + align: "center", + }, + { + field: "name", + width: '12%', + title: "配件名称", + unresize: true, + align: "center", + }, + { + field: "model", + width: '10%', + title: "规格型号", + unresize: true, + align: "center", + }, + { + field: "unit", + title: "单位", + width: '8%', + unresize: true, + align: "center", + }, + { + field: "num", + width: '10%', + title: " * 本次入库量", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + { + field: "price", + width: '9.8%', + title: "单价(元)", + unresize: true, + align: "center", + edit: 'text', + style: 'outline: 1px solid #e6e6e6;outline-offset: -5px;' + }, + { + field: "manufacturer", + width: '15%', + title: " * 配件厂家", + unresize: true, + align: "center", + templet: '#TPL-select-demo' + }, + { + field: "remarks", + width: '12%', + 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) { + var options = this; + table.resize("currentTableId"); + pageNum = tableIns.config.page.curr; + form.on('select(select-demo)', function (obj) { + console.log(obj); + var value = obj.value; // 获取选中项 value + // 获取当前行数据(如 id 等字段,以作为数据修改的索引) + var data = table.getRowData(options.id, obj.elem); + // 更新数据中对应的字段 + data.manufacturer = value; + updateOrAddObject(data.id, data); + }); + // 获取当前行数据 - 自定义方法 + table.getRowData = function (tableId, elem) { + var index = $(elem).closest('tr').data('index'); + return table.cache[tableId][index] || {}; + }; + + //设置全部数据到全局变量 + 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 === 'num') { // 本次入库量 + 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 === 'price') { + const regex = /^(?:1(?:\d{0,8}|[0-9]*\.\d{1,2})|(?:[1-9]\d{0,7}|[1-9]\d{0,6}\.\d{1,2}|[1-9]\d{1,7}\.\d{2}|100000000(?:\.00)?))$/; + if (!regex.test(value)) { + obj.reedit(); + return layer.msg('单价格式不正确!', { 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]);//调用自定义的根据值移除函数 + } + } + } + } + } + }); +} + +// 根据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); + } + } + } + } + console.log(dataArr); + 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 addFitTypeData() { + openIframeByParamObj2("add_fit_type_data", "配件类型", "../../../page/basic/fit_type_list.html", "92%", "95%", {}); +} + +function closePage(type,params) { + let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引 + parent.layer.close(index); // 再执行关闭 + if (type == 1) { + window.parent.addFitDatas(params); + } + +} \ No newline at end of file diff --git a/js/accessory/child/inventory_count_form.js b/js/accessory/child/inventory_count_form.js index 4214bbb..7c37507 100644 --- a/js/accessory/child/inventory_count_form.js +++ b/js/accessory/child/inventory_count_form.js @@ -14,7 +14,9 @@ function setParams(obj) { table = layui.table; util = layui.util; laydate.render({ - elem: '#inputDay' + elem: '#ID-laydate-rangeLinked', + range: ['#startDay', '#endDay'], + rangeLinked: true }); form.verify(); form.on('submit(formData)', function (data) { @@ -187,10 +189,7 @@ function getBaseTableData() { // 选择入库配件类型 function chooseFitType() { let params = {}; - /* if (jjDataArr && jjDataArr.length > 0) { - params.jjDataArrStr = JSON.stringify(jjDataArr); - } */ - openIframeByParamObj("choose_fit_type", '选择入库配件类型', "./choose_fit_type_list.html", '92%', '95%', params); + openIframeByParamObj("choose_fit_type_inventory_count", '选择盘点配件类型', "./choose_inventory_count_fit_type_list.html", '92%', '95%', params); } // 查询 diff --git a/page/accessory/child/choose_inventory_count_fit_type_list.html b/page/accessory/child/choose_inventory_count_fit_type_list.html new file mode 100644 index 0000000..06d0f2c --- /dev/null +++ b/page/accessory/child/choose_inventory_count_fit_type_list.html @@ -0,0 +1,103 @@ + + + + + + + 需求计划 + + + + + + + +
+
+
+ 搜索信息 +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ + + +
+
+

(无配件名称及规格,点击添加新数据)

+
+
+
+
+
+
+
+
+
+ + +
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/page/accessory/child/inventory_count_form.html b/page/accessory/child/inventory_count_form.html index b9685d4..c0d4101 100644 --- a/page/accessory/child/inventory_count_form.html +++ b/page/accessory/child/inventory_count_form.html @@ -17,26 +17,32 @@
- +
- +
- -
-
- + +
+
+ +
+
-
+
+
-
- +
+

您还没选择盘点配件类型

+

需要添加配件类型后才能执行盘点操作

+
- + @@ -121,7 +127,7 @@
- +