1
yxj
2024-08-13 46e76977b1c9ebb0fcfe4998e9123b0f096c074c
WebTM/views/²É¹º¹ÜÀí/²É¹ººÏͬ/Add_Edit_Cg_ContractBillList.html
@@ -582,7 +582,10 @@
                //数值格式校验工具
                var ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
                var temp = "";                      //定义一个空字符串变量 temp
                var Dec = getDecByMaterID(obj.data.HMaterID) //获取精度
                var HQtyDec = (Dec["HQtyDec"] == null || Dec["HQtyDec"] == 0) ? 4 : Dec["HQtyDec"];  //数量精度
                var HPriceDec = (Dec["HPriceDec"] == null || Dec["HPriceDec"] == 0) ? 4 : Dec["HPriceDec"];  //单价精度
                var HMoneyDec = (Dec["HMoneyDec"] == null || Dec["HMoneyDec"] == 0) ? 2 : Dec["HMoneyDec"];  //金额精度
                // å•元格编辑之前的值
                var oldText = $(this).prev().text();     //获取当前的值赋值给oldtext           èŽ·å–å½“å‰å…ƒç´ ï¼ˆå¯èƒ½æ˜¯ä¸€ä¸ªè¡¨æ ¼å•å…ƒæ ¼ï¼‰çš„å‰ä¸€ä¸ªåŒçº§å…ƒç´ çš„æ–‡æœ¬å†…å®¹ï¼Œå¹¶å°†è¿™ä¸ªæ–‡æœ¬å†…å®¹å­˜å‚¨åœ¨å˜é‡oldText中
                var value = obj.value               //得到修改后的值
@@ -598,7 +601,6 @@
                                HQty: oldText  //将hqty字段恢复到保存单元格的值
                            });
                            table.render(option);  //重新渲染表格
                            layer.msg("数量请输入大于0的数字!");   //提示请输入大于0数字
                            return; 
                        }
@@ -610,7 +612,11 @@
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HExRate = $("#HExRate").val();                      //汇率
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({             //更新表格数据                æ–¹æ³•是该对象提供的一个方法,用于更新其内部状态或与之关联的数据源
                            HQty: HQty                    //   æ›´æ–°HQty字段,其值来自变量HQty 
@@ -619,6 +625,7 @@
                            , HTaxMoney: HTaxMoney          //更新HMoney字段,其值来自变量HMoney  
                            , HlineTotal: HlineTotal        //新HlineTotal字段,其值来自变量HlineTotal
                        });
                        table.render(option)
                        break;
                    case "HPrice":                                         //单价
                        //数据格式校验
@@ -628,7 +635,7 @@
                            obj.update({     //使用obj.update方法更新表格中某一行的数据
                                HPrice: oldText    //将HPrice字段恢复到保存单元格的值
                            });
                            table.render(option);  //重新渲染表格
                            layer.msg("单价请输入大于0的数字!");  //提示 å•价请输入大于0的数字!
                            return;
                        }
@@ -641,6 +648,11 @@
                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HExRate = $("#HExRate").val();                      //汇率
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
@@ -650,6 +662,7 @@
                            , HTaxMoney: HTaxMoney
                            , HlineTotal: HlineTotal
                        });
                        table.render(option)
                        break;
                    case "HTaxRate":                                                       //数量
                        //数据格式校验
@@ -660,6 +673,7 @@
                                HTaxRate: oldText
                            });
                            layer.msg("税率请输入不小于0的数字!");
                            table.render(option);  //重新渲染表格
                            return;
                        }
@@ -673,6 +687,12 @@
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        var HExRate = $("#HExRate").val();                       //汇率
                        //数字精度
                        HQty = Number(HQty.toFixed(HQtyDec));
                        HPrice = Number(HPrice.toFixed(HPriceDec));
                        HMoney = Number(HMoney.toFixed(HMoneyDec));
                        HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HTaxRate: HTaxRate * 100
@@ -683,7 +703,6 @@
                            , HlineTotal: HlineTotal
                        });
                        break;
                        table.render(option);
                    default:
                }
            });
@@ -1091,31 +1110,33 @@
                                    //    return layer.msg("请选择一条数据");
                                    //}
                                    OptionData = checkStatus.data[0];
                                    var rowIndex = $(obj.tr).attr("data-index") * 1;
                                    for (var i = 0; i < checkStatus.data.length; i++) {
                                        if (rowIndex + i >= option.data.length) {
                                            var NewRow = {
                                                "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HUnitID": 0, "计量单位": "", "HWHID": 0, "HWHName": "", "数量": "", "HRemark": ""
                                                , "HPrice": "0", "HTaxPrice": "0", "HMoney": "0", "HDiscountRate": "1", "HRelTaxPrice": "0", "HTaxRate": "0", "HTaxMoney": "0", "HlineTotal": "0", "HlineTotalBB": "0", "HDate": Format(new Date, "yyyy- MM - dd")
                                            };
                                    if (checkStatus.data.length > 1) {
                                        var rowIndex = $(obj.tr).attr("data-index") * 1;
                                        for (var i = 0; i < checkStatus.data.length; i++) {
                                            if (rowIndex + i >= option.data.length) {
                                                var NewRow = {
                                                    "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HUnitID": 0, "计量单位": "", "HWHID": 0, "HWHName": "", "数量": "", "HRemark": ""
                                                    , "HPrice": "0", "HTaxPrice": "0", "HMoney": "0", "HDiscountRate": "1", "HRelTaxPrice": "0", "HTaxRate": "0", "HTaxMoney": "0", "HlineTotal": "0", "HlineTotalBB": "0", "HDate": Format(new Date, "yyyy- MM - dd")
                                                };
                                            table.cache["mainTable"].push(NewRow);
                                            option.data = table.cache["mainTable"];
                                                table.cache["mainTable"].push(NewRow);
                                                option.data = table.cache["mainTable"];
                                            table.render(option);
                                                table.render(option);
                                            }
                                            var HMaterID = checkStatus.data[i].HItemID;
                                            var resultData = getMaterialByMaterID(HMaterID);
                                            option.data[rowIndex + i].HMaterID = resultData.HMaterID;
                                            option.data[rowIndex + i].物料代码 = resultData.HMaterNumber;
                                            option.data[rowIndex + i].物料名称 = resultData.HMaterName;
                                            option.data[rowIndex + i].规格型号 = resultData.HMaterModel;
                                            option.data[rowIndex + i].HUnitID = resultData.HUnitID;
                                            option.data[rowIndex + i].计量单位 = resultData.HUnitName;
                                        }
                                        var HMaterID = checkStatus.data[i].HItemID;
                                        var resultData = getMaterialByMaterID(HMaterID);
                                        option.data[rowIndex + i].HMaterID = resultData.HMaterID;
                                        option.data[rowIndex + i].物料代码 = resultData.HMaterNumber;
                                        option.data[rowIndex + i].物料名称 = resultData.HMaterName;
                                        option.data[rowIndex + i].规格型号 = resultData.HMaterModel;
                                        option.data[rowIndex + i].HUnitID = resultData.HUnitID;
                                        option.data[rowIndex + i].计量单位 = resultData.HUnitName;
                                        table.render(option);
                                    }
                                    table.render(option);
                                    layer.closeAll();
                                    //layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
@@ -1124,14 +1145,50 @@
                                    //return false å¼€å¯è¯¥ä»£ç å¯ç¦æ­¢ç‚¹å‡»è¯¥æŒ‰é’®å…³é—­
                                },
                                end: function () {
                                    obj.update({
                                        "HMaterID": OptionData.HItemID
                                        , "物料代码": OptionData.物料代码
                                        , "物料名称": OptionData.物料名称
                                        , "规格型号": OptionData.规格型号
                                        , "HUnitID": OptionData.HUnitID
                                        , "计量单位": OptionData.计量单位名称
                                    })
                                    //通过供应商id获取税率
                                    var HSupID = $("#HSupID").val();
                                    if (HSupID != 0) {
                                        $.ajax({
                                            url: GetWEBURL() + "/Gy_Supplier/xg",
                                            //url: "http://localhost:12761/Gy_Supplier/xg",
                                            type: "GET",
                                            data: {
                                                "HInterID": HSupID
                                            },
                                            success: function (d) {
                                                var HTaxRate = parseInt(d.data[0].增值税率) * 0.01;
                                                //数据校验合格,重算记录
                                                var HQty = obj.data.HQty * 1;                           //数量
                                                var HPrice = obj.data.HPrice * 1;               //单价
                                                var HMoney = HQty * HPrice;                     //金额=数量*单价
                                                var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                                                var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                                obj.update({ //更新表格数据
                                                    "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                                    , "物料代码": OptionData.物料代码
                                                    , "物料名称": OptionData.物料名称
                                                    , "规格型号": OptionData.规格型号
                                                    , "HUnitID": OptionData.HUnitID
                                                    , "计量单位": OptionData.计量单位名称
                                                    , "HTaxRate": HTaxRate * 100
                                                    , HQty: HQty                               //更新HQty字段,HQty
                                                    , HPrice: HPrice                         //更新HPrice字段,HPrice
                                                    , HMoney: HMoney                      //更新HMoney字段,HMoney
                                                    , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                                    , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                                })
                                            }
                                        });
                                    } else {
                                        obj.update({ //更新表格数据
                                            "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                            , "物料代码": OptionData.物料代码
                                            , "物料名称": OptionData.物料名称
                                            , "规格型号": OptionData.规格型号
                                            , "HUnitID": OptionData.HUnitID
                                            , "计量单位": OptionData.计量单位名称
                                        })
                                    }
                                }
                            });
                        }
@@ -1210,6 +1267,110 @@
                    }
                })
                //双击
                $('.layui-table-box tbody td[data-field="物料代码"]').off('dblclick').on('dblclick', function () {
                    var HOrgID = $("#HOrgID").val();
                    layer.open({
                        type: 2
                        , skin: "layui-layer-rim" //加上边框
                        , title: "物料列表"  //标题
                        , closeBtn: 1  //窗体右上角关闭 çš„ æ ·å¼
                        , shift: 2 //弹出动画
                        , area: ["90%", "90%"] //窗体大小
                        , maxmin: true //设置最大最小按钮是否显示
                        , content: ['../../基础资料/公用基础资料/Gy_Material.html?openType=2&HOrgID=' + HOrgID, 'yes']
                        , btn: ["确定", "取消"]
                        , btn1: function (index, laero) {
                            //按钮一  çš„回调
                            var iframeWindow = window["layui-layer-iframe" + index];//获取弹框页面
                            var checkStatus = iframeWindow.layui.table.checkStatus("mainTable");//获取选中的数据
                            //if (checkStatus.data.length != 1) {
                            //    return layer.msg("请选择一条数据");
                            //}
                            OptionData = checkStatus.data[0];
                            if (checkStatus.data.length > 1) {
                                var rowIndex = $(obj.tr).attr("data-index") * 1;
                                for (var i = 0; i < checkStatus.data.length; i++) {
                                    if (rowIndex + i >= option.data.length) {
                                        var NewRow = {
                                            "HMaterID": 0, "物料代码": "", "物料名称": "", "规格型号": "", "HUnitID": 0, "计量单位": "", "HWHID": 0, "HWHName": "", "数量": "", "HRemark": ""
                                            , "HPrice": "0", "HTaxPrice": "0", "HMoney": "0", "HDiscountRate": "1", "HRelTaxPrice": "0", "HTaxRate": "0", "HTaxMoney": "0", "HlineTotal": "0", "HlineTotalBB": "0", "HDate": Format(new Date, "yyyy- MM - dd")
                                        };
                                        table.cache["mainTable"].push(NewRow);
                                        option.data = table.cache["mainTable"];
                                        table.render(option);
                                    }
                                    var HMaterID = checkStatus.data[i].HItemID;
                                    var resultData = getMaterialByMaterID(HMaterID);
                                    option.data[rowIndex + i].HMaterID = resultData.HMaterID;
                                    option.data[rowIndex + i].物料代码 = resultData.HMaterNumber;
                                    option.data[rowIndex + i].物料名称 = resultData.HMaterName;
                                    option.data[rowIndex + i].规格型号 = resultData.HMaterModel;
                                    option.data[rowIndex + i].HUnitID = resultData.HUnitID;
                                    option.data[rowIndex + i].计量单位 = resultData.HUnitName;
                                }
                                table.render(option);
                            }
                            layer.closeAll();
                            //layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                        }
                        , btn2: function (index, layero) {
                            //按钮【按钮二】的回调
                            //return false å¼€å¯è¯¥ä»£ç å¯ç¦æ­¢ç‚¹å‡»è¯¥æŒ‰é’®å…³é—­
                        },
                        end: function () {
                            //通过供应商id获取税率
                            var HSupID = $("#HSupID").val();
                            if (HSupID != 0) {
                                $.ajax({
                                    url: GetWEBURL() + "/Gy_Supplier/xg",
                                    //url: "http://localhost:12761/Gy_Supplier/xg",
                                    type: "GET",
                                    data: {
                                        "HInterID": HSupID
                                    },
                                    success: function (d) {
                                        var HTaxRate = parseInt(d.data[0].增值税率) * 0.01;
                                        //数据校验合格,重算记录
                                        var HQty = obj.data.HQty * 1;                           //数量
                                        var HPrice = obj.data.HPrice * 1;               //单价
                                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                                        var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                                        obj.update({ //更新表格数据
                                            "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                            , "物料代码": OptionData.物料代码
                                            , "物料名称": OptionData.物料名称
                                            , "规格型号": OptionData.规格型号
                                            , "HUnitID": OptionData.HUnitID
                                            , "计量单位": OptionData.计量单位名称
                                            , "HTaxRate": HTaxRate * 100
                                            , HQty: HQty                               //更新HQty字段,HQty
                                            , HPrice: HPrice                         //更新HPrice字段,HPrice
                                            , HMoney: HMoney                      //更新HMoney字段,HMoney
                                            , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                            , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                        })
                                    }
                                });
                            } else {
                                obj.update({ //更新表格数据
                                    "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                    , "物料代码": OptionData.物料代码
                                    , "物料名称": OptionData.物料名称
                                    , "规格型号": OptionData.规格型号
                                    , "HUnitID": OptionData.HUnitID
                                    , "计量单位": OptionData.计量单位名称
                                })
                            }
                        }
                    });
                });
            }
            //行内删除
@@ -1386,6 +1547,31 @@
            }
            //#endregion
            //#region æ ¹æ®ç‰©æ–™ID获取精度
            function getDecByMaterID(HMaterID) {
                var resultData = {};
                $.ajax({  // å¼‚步请求
                    url: GetWEBURL() + "Gy_Material/getDecByID",  //请求地址
                    async: false,   //是否开启异步
                    type: "GET",   //请求类型
                    data: {   //定义发送到服务器的数据
                        "HMaterID": HMaterID     //  å°†hmaterid作为请求参数发送
                    },
                    success: function (result) {   // å½“请求成功时,执行这个函数
                        if (result.code == 1) { // å¦‚果服务器返回的数据中的`code字段等于1,这可能表示审核操作成功执行
                            var data = result.data; //声明data变量,并将其赋值为result对象中的data属性
                            resultData = data[0];   //将data数组(或类数组对象)的第一个元素赋值给变量resultData
                        }
                        //else {
                        //    layer.alert(result.Message, { icon: 5, btn: ['退出'], time: 100000, offset: 't' }); //result.msg对象,提示弹窗 ç±»åž‹ä¸º5, æŒ‰é’®ï¼Œå’ŒæŒ‰é’®çš„名称为退出  æ—¶é—´ ä¸º100秒,以及偏移量(`offset: 't'
                        //}
                    }, error: function () {
                        layer.alert("发生错误!", { icon: 5 });  //提示弹窗 å‘生错误 ï¼Œè­¦ç¤ºæ ‡å¿—为5的
                    }
                });
                return resultData;
            }
            //#endregion
            //#region ä¿å­˜åŽæµè§ˆæ–¹æ³•
            function ReRoadBillMain() {