duhe
2024-01-22 43e741c8377b555f4e5ed287bee724e71a11540f
WebTM/views/ÑéÊÕÈë¿â/Í⹺Èë¿â/Add_Edit_Kf_POStockInBillList.html
@@ -156,14 +156,24 @@
                                        <div class="layui-col-xs4 layui-inline">
                                            <label class="layui-form-label">源单类型</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HSourceBillType" id="HSourceBillType" value="0">
                                                <select name="HSourceBillType" id="HSourceBillType" lay-verify="HSourceBillType">
                                                    <!--动态渲染源单类型-->
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-col-xs4 layui-inline">
                                            <label class="layui-form-label">选单号</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="Box2" id="Box2" autocomplete="off">
                                                <input type="text" name="" id="" class="layui-input" value="" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="XDHList" id="XDHList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                            <!--<label class="layui-form-label">选单号</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="Box2" id="Box2" autocomplete="off">
                                            </div>-->
                                        </div>
                                        <div class="layui-col-xs4 layui-inline">
                                            <label class="layui-form-label">负责人</label>
@@ -249,7 +259,7 @@
                                                <input type="text" class="layui-input" name="HCheckDate" id="HCheckDate" style="background-color:#efefef4d;" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                        <div class="layui-inline" >
                                            <label class="layui-form-label" style="width: 85px;">关闭日期</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HCloseDate" id="HCloseDate" style="background-color:#efefef4d;" readonly>
@@ -325,6 +335,8 @@
            //判断是否登录 æœªç™»å½•则跳到登录页
            get_LoginIs();
            Organ();//显示组织
            //获取源单类型
            HSourceBillType();
            //获取页面跳转参数
            var params = get_UrlVars();
            var OperationType = params[params[0]]; //从参数中获取 æ•°æ®ç±»åž‹  1添加 ä¿å­˜  2复制  3 ç¼–辑
@@ -394,7 +406,8 @@
                "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HAuxPropID": 0, "物料辅助属性": "", "HUnitID": 0, "计量单位": "", "HQtyMust": "", "HQty": "", "HRemark": "",
                "HPrice": "0", "HMoney": "0", "HOrderPrice": "0", "HWHID": 0, "收料仓库": "",
                "HSPID": 0, "仓位名称": "", "HBatchNo": "", "HPOOrderInterID": 0, "HPOOrderEntryID": 0,
                "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": ""
                "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": "",
                "HSourceBillNo": 0, "HSourceBillType": 0, "HSourceInterID": 0, "HSourceEntryID": 0,
            }];
            // åˆå§‹åŒ–界
            set_InitGrid();
@@ -408,7 +421,8 @@
                    "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HAuxPropID": 0, "物料辅助属性": "", "HUnitID": 0, "计量单位": "", "HQtyMust": "", "HQty": "", "HRemark": "",
                    "HPrice": "0", "HMoney": "0", "HOrderPrice": "0", "HWHID": 0, "收料仓库": "",
                    "HSPID": 0, "仓位名称": "", "HBatchNo": "", "HPOOrderInterID": 0, "HPOOrderEntryID": 0,
                    "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": ""
                    "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": "",
                    "HSourceBillNo": 0, "HSourceBillType": 0, "HSourceInterID": 0, "HSourceEntryID": 0,
                };
                switch (obj.event) {
                    case 'btn-AddLine':
@@ -515,6 +529,112 @@
            //#endregion
            //#region ç›‘听单元格编辑  å•元格编辑后 å˜æ›´
            table.on('edit(mainTable)', function (obj) {
                //数值格式校验工具
                var ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
                var temp = "";
                // å•元格编辑之前的值
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                switch (field) {
                    case "HQty":                                         //数量
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp) || temp == 0) {
                            //恢复数据到编辑前
                            obj.update({
                                HQty: oldText
                            });
                            table.render(option);
                            layer.msg("数量请输入大于0的数字!");
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = value * 1;                           //数量
                        var HPrice = obj.data.HPrice * 1;               //单价
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
                            , HPrice: HPrice
                            , HMoney: HMoney
                        });
                        /* table.render(option);*/
                        break;
                    case "HPrice":                                         //单价
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp) || temp == 0) {
                            //恢复数据到编辑前
                            obj.update({
                                HPrice: oldText
                            });
                            /* table.render(option);*/
                            layer.msg("单价请输入大于0的数字!");
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HPrice = value * 1;
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
                            , HPrice: HPrice
                            , HMoney: HMoney
                        });
                        break;
                    case "HMoney":                                         //金额
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp) || temp == 0) {
                            //恢复数据到编辑前
                            obj.update({
                                HMoney: oldText
                            });
                            /* table.render(option);*/
                            layer.msg("金额请输入大于0的数字!");
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HMoney = value * 1;
                        var HPrice = (HMoney / HQty).toFixed(2);       //单价=金额/数量
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
                            , HPrice: HPrice
                            , HMoney: HMoney
                        });
                        break;
                        table.render(option);
                    default:
                }
            });
            //#endregion
            //#endregion
            //#endregion
            //#region æœ¬é¡µé¢æ‰€æœ‰è¢«è°ƒç”¨çš„æ–¹æ³•
            //#region åˆ¤æ–­æ˜¯å¦ç™»å½• æœªç™»å½•则跳到登录页
@@ -564,7 +684,7 @@
            }
            //子表
            function set_InitGrid() {
                option = {
@@ -576,6 +696,10 @@
                    , cols: [[ //子表
                        { type: 'checkbox', totalRowText: '合计行' }
                        , { type: 'numbers', title: '序号', width: 100, totalRow: true }
                        , { type: 'HSourceBillNo', title: '源单号', width: 100, hide: true }//源单号
                        , { field: 'HSourceBillType', title: '源单类型', width: 100, hide: true }//源单类型
                        , { type: 'HSourceInterID', title: '源单主内码', width: 100, hide: true }//源单主内码
                        , { field: 'HSourceEntryID', title: '源单子内码', width: 100, hide: true }//源单子内码
                        , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true }
                        , { field: '物料代码', title: '物料代码', width: 150, edit: 'text', event: "HMaterID" }//f7
                        , { field: '物料名称', title: '物料名称', width: 150, }
@@ -599,7 +723,7 @@
                    ]]
                }
                option.data = rowdata;
                option.data = [];
                table.render(option);
            }
@@ -637,7 +761,7 @@
                                , "HManagerID": data.HManagerID
                                , "HManagerName": data.负责人
                                , "HExRate": data.汇率
                                , "Box2": ""
                                //, "Box2": ""
                                , "HRemark": data.表头备注
                                , "HMaker": data.制单人
                                , "HChecker": data.审核人
@@ -657,7 +781,11 @@
                                    {
                                        "HMaterID": subdata[i].HMaterID, "物料代码": subdata[i].物料代码, "物料名称": subdata[i].物料名称, "规格型号": subdata[i].规格型号, "HAuxPropID": subdata[i].HAuxPropID, "物料辅助属性": subdata[i].物料辅助属性, "HUnitID": subdata[i].HUnitID, "计量单位": subdata[i].计量单位,
                                        "HQtyMust": subdata[i].应收数量, "HQty": subdata[i].实收数量, "HRemark": subdata[i].表体备注, "HPrice": subdata[i].单价, "HMoney": subdata[i].金额, "HOrderPrice": subdata[i].采购金额, "HWHID": subdata[i].HWHID, "收料仓库": subdata[i].收料仓库, "HSPID": subdata[i].HSPID, "仓位名称": subdata[i].仓位名称,
                                        "HBatchNo": subdata[i].批次
                                        "HBatchNo": subdata[i].批次,
                                        "HSourceBillNo": subdata[i].源单单号,    //源单号
                                        "HSourceBillType": subdata[i].源单类型,   //源单类型
                                        "HSourceInterID": subdata[i].源单主内码,   //源单主内码
                                        "HSourceEntryID": subdata[i].源单子内码     //源单子内码
                                    }
                                )
                            }
@@ -720,6 +848,7 @@
                    return;
                }
                var num = [];
                for (var i = 0; i < table.cache["mainTable"].length; i++) {
                    if (table.cache["mainTable"][i] != "") {
@@ -727,6 +856,25 @@
                        num.push(table.cache["mainTable"][i])
                    }
                }
                checkDuplicateData(num);
                const duplicateRows = checkDuplicateData(num);
                if (duplicateRows.length > 0) {
                    let message = '表格中存在重复数据,重复行数为:';
                    for (let i = 0; i < duplicateRows.length; i++) {
                        const { row1, row2 } = duplicateRows[i];
                        message += `第${row1}行与第${row2}行相同`;
                        if (i !== duplicateRows.length - 1) {
                            message += ',';
                        }
                    }
                    message += ',请删除其中一行';
                    layer.alert(message);
                }
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(num);
@@ -953,7 +1101,8 @@
                                                "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HAuxPropID": 0, "物料辅助属性": "", "HUnitID": 0, "计量单位": "", "HQtyMust": "", "HQty": "", "HRemark": "",
                                                "HPrice": "0", "HMoney": "0", "HOrderPrice": "0", "HWHID": 0, "收料仓库": "",
                                                "HSPID": 0, "仓位名称": "", "HBatchNo": "", "HPOOrderInterID": 0, "HPOOrderEntryID": 0,
                                                "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": ""
                                                "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": "",
                                                "HSourceBillNo": 0, "HSourceBillType": 0, "HSourceInterID": 0, "HSourceEntryID": 0,
                                            };
                                            table.cache["mainTable"].push(NewRow);
@@ -1085,8 +1234,123 @@
                    }
                })
            }
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridDelete(obj);   //行内删除
                set_GridCellCheck(obj); //行内快捷键筛选
            });
            //动态弹出页面
            function getSupType() {
                var type = $("#HSourceBillType").val();
                switch (type) {
                    case '1102':
                        return { url: "../../采购管理/采购订单/Cg_POOrderBillList.html", name: "采购订单" };
                        break;
                    case '1103':
                        return { url: "../../采购管理/收料通知单/Cg_POInStockBillList.html", name: "收料通知单" };
                        break;
                }
            }
            //表头信息选择单据弹窗
            form.on('submit(XDHList)', function () {
                if ($("#HSourceBillType").val() == 0 || $("#HSourceBillType").val() == null) {
                    return layer.msg('请选择单据类型');
                }
                var url = getSupType().url;
                url = encodeURI(url);
                //页面层-自定义
                layer.open({
                    type: 2
                    , skin: "layui-layer-rim" //加上边框
                    , title: '' + getSupType().name + '列表'  //标题
                    , closeBtn: 1  //窗体右上角关闭 çš„ æ ·å¼
                    , shift: 2 //弹出动画
                    , area: ["90%", "90%"] //窗体大小
                    , maxmin: true //设置最大最小按钮是否显示
                    , content: [url, "yes"]
                    , btn: ["确定", "取消"]
                    , btn1: function (index, laero) {
                        //按钮一  çš„回调
                        var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                        var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                        if (checkStatus.data.length == 0) {
                            return layer.msg("请至少选择一条数据!");
                        }
                        layer.alert("你已选择" + checkStatus.data.length + "条数据");
                        //获取收料通知单代码
                        var ProcessNumber = [];
                        for (var i = 0; i < checkStatus.data.length; i++) {
                            ProcessNumber.push(checkStatus.data[i]);
                        }
                        //获取当前位置所在行数
                        var NowNum = 0;
                        NowNum = option.data.length;
                        if (getSupType().name == "采购订单") {
                            var j = 0;
                            for (var i = 0; i < checkStatus.data.length; i++) {
                                option.data.push({
                                    "HMaterID": checkStatus.data[j].HMaterID, "物料代码": checkStatus.data[j].物料代码, "物料名称": checkStatus.data[j].物料名称, "规格型号": checkStatus.data[j].规格型号,
                                    "HUnitID": checkStatus.data[j].HUnitID, "计量单位": checkStatus.data[j].计量单位,
                                    "HQty": checkStatus.data[j].数量, "HPrice": checkStatus.data[j].单价,
                                    "HMoney": checkStatus.data[j].金额,
                                    "HSourceBillNo": checkStatus.data[j].单据号, "HSourceBillType": checkStatus.data[j].HBillType, "HSourceInterID": checkStatus.data[j].hmainid, "HSourceEntryID": checkStatus.data[j].hsubid,
                                })
                                j++;
                            }
                            table.render(option);
                            layer.close(index);
                        } else if (getSupType().name =="收料通知单") {
                            var j = 0;
                            for (var i = 0; i < ProcessNumber.length; i++) {
                                option.data.push({
                                    "HMaterID": checkStatus.data[j].HMaterID, "物料代码": checkStatus.data[j].物料代码, "物料名称": checkStatus.data[j].物料名称, "规格型号": checkStatus.data[j].规格型号,
                                    "   ": 0, "物料辅助属性": "", "HUnitID": checkStatus.data[j].HUnitID, "计量单位": checkStatus.data[j].计量单位, "HQtyMust": "", "HQty": checkStatus.data[j].数量, "HRemark": "",
                                    "HPrice": checkStatus.data[j].单价, "HMoney": checkStatus.data[j].金额, "HOrderPrice": "0", "HWHID": checkStatus.data[j].HWHID, "收料仓库": checkStatus.data[j].收料仓库,
                                    "HSPID": checkStatus.data[j].HSPID, "仓位名称": checkStatus.data[j].仓位名称, "HBatchNo": "", "HPOOrderInterID": 0, "HPOOrderEntryID": 0,
                                    "HPOOrderBillNo": "", "HSeOrderInterID": 0, "HSeOrderEntryID": 0, "HSeOrderBillNo": "",
                                    "HSourceBillNo": checkStatus.data[j].单据号, "HSourceBillType": checkStatus.data[j].HBillType, "HSourceInterID": checkStatus.data[j].hmainid, "HSourceEntryID": checkStatus.data[j].hsubid,
                                })
                                j++;
                            }
                            table.render(option);
                            layer.close(index);//关闭弹窗
                        }
                    }
                });
            });
            //判断所选着与表格是否有重复数据
            function checkDuplicateData(data) {
                const duplicates = [];
                for (let i = 0; i < data.length; i++) {
                    const currentItem = data[i];
                    let isDuplicate = false;
                    for (let j = i + 1; j < data.length; j++) {
                        const compareItem = data[j];
                        if (currentItem.HSourceInterID === compareItem.HSourceInterID && currentItem.HSourceEntryID === compareItem.HSourceEntryID) {
                            isDuplicate = true;
                            duplicates.push({ row1: i + 1, row2: j + 1 }); // è®°å½•重复数据所在行数
                        }
                    }
                    if (isDuplicate && !duplicates.some(item => item.row1 === i + 1)) {
                        duplicates.push({ row1: i + 1, row2: -1 }); // è®°å½•重复数据所在行数,-1 è¡¨ç¤ºæœªæ‰¾åˆ°ä¸Žå½“前行重复的行
                    }
                }
                return duplicates;
            }
            //行内删除
            function set_GridDelete(obj) {
                var data = obj.data;
@@ -1138,6 +1402,30 @@
            }
            //#endregion
            //#region èŽ·å–æºå•ç±»åž‹
            function HSourceBillType() {
                var HName = '采购入库单';
                //获取登录页组织列
                $.ajax({
                    type: "get",
                    async: false,
                    data: { "HName": HName },
                    url: GetWEBURL() + "/Web/GetHSourceBillType",
                    success: function (result) {
                        var HSourceBillTypes = "";
                        if (result.count == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                            var data = result.data;
                            for (var i = 0; i < data.length; i++) {
                                HSourceBillTypes += '<option  style="color:blue;" value="' + data[i].HSourceBillType + '">' + data[i].HSourceBillTypeName + '</option>';
                            }
                            $("#HSourceBillType").append(HSourceBillTypes);
                            form.render('select');
                        }
                    }
                })
            }
            //#endregion
            //#endregion