1
duhe
2024-08-15 40cd70d9a9d13001c1b6c2269334e8a363c562c3
WebTM/views/²É¹º¹ÜÀí/±¨¼Ûµ¥/Sup_QuotePriceBillEdit.html
@@ -419,25 +419,73 @@
                                //按钮【按钮一】的回调
                                var iframeWindow = window['layui-layer-iframe' + index];
                                var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');
                                if (checkStatus.data.length === 0) {
                                    return layer.msg('请选择数据');
                                if (checkStatus.data.length != 1) {
                                    return layer.msg('请选择一条数据');
                                }
                                obj.update({
                                    HMaterName: checkStatus.data[0].HName
                                    , HMaterID: checkStatus.data[0].HItemID
                                    , HMaterNumber: checkStatus.data[0].HNumber
                                    , HMaterModel: checkStatus.data[0].HModel
                                    , HUnitID: checkStatus.data[0].HUnitID
                                    , HUnitNumber: checkStatus.data[0].HUnitNumber
                                    , HUnitName: checkStatus.data[0].HUnitName
                                });
                                OptionData = checkStatus.data[0];
                                layer.close(layer.index);
                            }
                            , btn2: function (index, layero) {
                            },
                            end: function () {
                                //通过供应商id获取税率
                                var HSupID = $("#HSupID").val();
                                if (HSupID != 0 && typeof (OptionData.HItemID) != "undefined") {
                                    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"];  //金额精度
                                    $.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;            //价税合计=金额+税额
                                            var HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                                            //数字精度
                                            HQty = Number(HQty.toFixed(HQtyDec));
                                            HPrice = Number(HPrice.toFixed(HPriceDec));
                                            HMoney = Number(HMoney.toFixed(HMoneyDec));
                                            HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                                            HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                                            HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                                            obj.update({ //更新表格数据
                                                "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                                , "物料代码": OptionData.HNumber
                                                , "物料名称": OptionData.HName
                                                , "规格型号": OptionData.HModel
                                                , "HUnitID": OptionData.HUnitID
                                                , "计量单位": OptionData.HUnitName
                                                , "HTaxRate": HTaxRate * 100
                                                , HQty: HQty                               //更新HQty字段,HQty
                                                , HPrice: HPrice                         //更新HPrice字段,HPrice
                                                , HMoney: HMoney                      //更新HMoney字段,HMoney
                                                , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                                , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                                , HTaxPrice, HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                                            })
                                        }
                                    });
                                } else if (typeof (OptionData.HItemID) != "undefined") {
                                    obj.update({ //更新表格数据
                                        "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                        , "物料代码": OptionData.HNumber
                                        , "物料名称": OptionData.HName
                                        , "规格型号": OptionData.HModel
                                        , "HUnitID": OptionData.HUnitID
                                        , "计量单位": OptionData.HUnitName
                                    })
                                }
                            }
                        });
                    }
@@ -480,6 +528,92 @@
                }
            })
            //#endregion
            //双击
            $('.layui-table-box tbody td[data-field="HMaterNumber"]').off('dblclick').on('dblclick', function () {
                layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    title: '产品列表',
                    closeBtn: 1,
                    shift: 2,
                    area: ['90%', '90%'],
                    maxmin: true,
                    content: ['../../../views/Baseset/基础资料/Gy_MaterialList.html', 'yes'],
                    btn: ['确定', '取消']
                    , btn1: function (index, layero) {
                        //按钮【按钮一】的回调
                        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];
                        layer.close(layer.index);
                    }
                    , btn2: function (index, layero) {
                    },
                    end: function () {
                        //通过供应商id获取税率
                        var HSupID = $("#HSupID").val();
                        if (HSupID != 0 && typeof (OptionData.HItemID) != "undefined") {
                            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"];  //金额精度
                            $.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;            //价税合计=金额+税额
                                    var HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                                    //数字精度
                                    HQty = Number(HQty.toFixed(HQtyDec));
                                    HPrice = Number(HPrice.toFixed(HPriceDec));
                                    HMoney = Number(HMoney.toFixed(HMoneyDec));
                                    HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                                    HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                                    HTaxPrice = Number(HTaxPrice.toFixed(HPriceDec));
                                    obj.update({ //更新表格数据
                                        "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                        , "物料代码": OptionData.HNumber
                                        , "物料名称": OptionData.HName
                                        , "规格型号": OptionData.HModel
                                        , "HUnitID": OptionData.HUnitID
                                        , "计量单位": OptionData.HUnitName
                                        , "HTaxRate": HTaxRate * 100
                                        , HQty: HQty                               //更新HQty字段,HQty
                                        , HPrice: HPrice                         //更新HPrice字段,HPrice
                                        , HMoney: HMoney                      //更新HMoney字段,HMoney
                                        , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                                        , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                                        , HTaxPrice, HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                                    })
                                }
                            });
                        } else if (typeof (OptionData.HItemID) != "undefined"){
                            obj.update({ //更新表格数据
                                "HMaterID": OptionData.HItemID             //设置HItemID的值为“HBillNo”字段的值HItemID`的值
                                , "物料代码": OptionData.HNumber
                                , "物料名称": OptionData.HName
                                , "规格型号": OptionData.HModel
                                , "HUnitID": OptionData.HUnitID
                                , "计量单位": OptionData.HUnitName
                            })
                        }
                    }
                });
            });
        });
@@ -487,50 +621,183 @@
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            var HQty = 0; //数量
            var HPrice = 0; //单价
            var HMoney = 0; //金额
            var HTaxRate = 0; //税率
            var HTaxMoney = 0; //税额
            var HTaxPrice = 0; //含税单价
            var HlineTotal = 0; //价税合计
            var HlineTotalBB = 0; //本位币价税合计
            if (obj.data.HQty != undefined) {
                HQty = parseFloat(obj.data.HQty);
            }
            if (obj.data.HPrice != undefined) {
                HPrice = parseFloat(obj.data.HPrice);
            }
            if (obj.data.HMoney != undefined) {
                HMoney = parseFloat(obj.data.HMoney);
            }
            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 ref = /^\d+(\.\d+)?$/;          //非负数正则表达式
            var temp = "";                         //定义一个空字符串变量 temp
            // å•元格编辑之前的值
            var oldText = $(this).prev().text();
            switch (field) {
                case "HQty":
                    console.log(obj.data.HMoney);
                    obj.update({
                        HMoney: Math.ceil(parseFloat(obj.value) * parseFloat(obj.data.HPrice)),
                case "HQty":                                         //数量
                    //数据格式校验
                    temp = value + "";                       //修改后的值 è½¬ä¸ºå­—符串 èµ‹å€¼ç»™  å˜é‡temp
                    if (!ref.test(temp) || temp == 0) { //使用表达式来判断字符串是否为0           // å®šä¹‰çš„æ­£åˆ™è¡¨è¾¾å¼ref(用于匹配非负数的字符串表示,但注意它不会匹配单独的0作为有效输入,因为.\d+部分是可选的,且前面没有允许0作为整数部分的单独情况)来测试temp字符串
                        //恢复数据到编辑前
                        obj.update({   //使用obj.update方法更新表格中某一行的数据
                            HQty: oldText    //将hqty字段恢复到保存单元格的值
                        });
                        table.render(option);  //渲染表格
                        layer.msg("数量请输入大于0的数字!");  //提示数量请输入大于
                        return;
                    }
                    //数据校验合格,重算记录
                    var HQty = value * 1;                           //数量
                    var HPrice = obj.data.HPrice * 1;               //单价
                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                    var HTaxRate = obj.data.HTaxRate * 0.01;           //税率
                    var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    //var HExRate = $("#HExRate").val();                      //汇率
                    //var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));      //本位币价税合计=(税额+金额)*汇率
                    //数字精度
                    HQty = Number(HQty.toFixed(HQtyDec));
                    HPrice = Number(HPrice.toFixed(HPriceDec));
                    HMoney = Number(HMoney.toFixed(HMoneyDec));
                    HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                    HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                    //同步更新表格和缓存对应的值
                    obj.update({     //更新表格数据                æ–¹æ³•是该对象提供的一个方法,用于更新其内部状态或与之关联的数据源
                        HQty: HQty                            //更新HQty字段,其值来自变量HQty
                        , HPrice: HPrice                             //更新HPrice字段,其值来自变量HPrice
                        , HMoney: HMoney                         //更新HMoney字段,其值来自变量HMoney
                        , HTaxMoney: HTaxMoney                       //更新HTaxMoney字段,HTaxMoney
                        , HlineTotal: HlineTotal                         //更新HlineTotal字段,其值来自变量HlineTotal
                        /*, HlineTotalBB: HlineTotalBB                     //更新HlineTotalBB字段,其值来自变量HlineTotalBB*/
                    });
                    console.log(obj.data.HMoney);
                    obj.update({
                        HTaxMoney: Math.ceil(parseFloat(obj.value) / 100 * parseFloat(obj.data.HMoney)),
                    });
                    table.render(option)
                    break;
                case "HPrice":
                    obj.update({
                        HMoney: Math.ceil(parseFloat(obj.value) * parseFloat(obj.data.HQty)),
                case "HPrice":                                         //单价
                    //数据格式校验
                    temp = value + "";     //修改后的值 è½¬ä¸ºå­—符串 èµ‹å€¼ç»™  å˜é‡temp
                    // ref很可能是一个正则表达式对象,用于匹配特定的字符串模式。ref.test(temp)会检查变量temp(即转换后的单价字符串)是否符合ref定义的模式。如果test方法返回false
                    if (!ref.test(temp)) { //检查单价字符串是否符合预期的格式
                        //恢复数据到编辑前
                        obj.update({            //更新表格某一行数据
                            HPrice: oldText     //将hprice字段恢复到保存前的值
                        });
                        table.render(option);
                        layer.msg("单价请输入数字!");   //请输入单价的数值
                        return;
                    }
                    //数据校验合格,重算记录
                    var HQty = obj.data.HQty * 1;                   //数量
                    var HPrice = value * 1;
                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                    var HTaxRate = obj.data.HTaxRate * 0.01;           //税率
                    var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    var HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                    //var HExRate = $("#HExRate").val();                      //汇率
                    //var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));     //本位币价税合计=(税额+金额)*汇率
                    //数字精度
                    HQty = Number(HQty.toFixed(HQtyDec));
                    HPrice = Number(HPrice.toFixed(HPriceDec));
                    HMoney = Number(HMoney.toFixed(HMoneyDec));
                    HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                    HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                    HTaxPrice = Number(HPrice.toFixed(HPriceDec));
                    //同步更新表格和缓存对应的值
                    obj.update({                    //更新表格数据                æ–¹æ³•是该对象提供的一个方法,用于更新其内部状态或与之关联的数据源
                        HQty: HQty                               //更新HQty字段,HQty
                        , HPrice: HPrice                         //更新HPrice字段,HPrice
                        , HMoney: HMoney                      //更新HMoney字段,HMoney
                        , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                        , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                        , HTaxPrice: HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                        /*, HlineTotalBB: HlineTotalBB              //更新HlineTotalBB字段,其值来自变量HlineTotalBB*/
                    });
                    obj.update({
                        HTaxMoney: Math.ceil(parseFloat(obj.value) / 100 * parseFloat(obj.data.HMoney)),
                    table.render(option)
                    break;
                case "HTaxRate":                                                       //税率
                    //数据格式校验
                    temp = value + "";             //修改后的值 è½¬ä¸ºå­—符串 èµ‹å€¼ç»™  å˜é‡temp
                    if (!ref.test(temp)) {  //判断税率字符串是否符合预期格式
                        //恢复数据到编辑前
                        obj.update({                //更新表格某一行数据
                            HTaxRate: oldText       //  å°†å­—段HTaxRate的数据恢复到更新之前的数据
                        });
                        table.render(option);
                        layer.msg("税率请输入数字!"); //提示请输入税率的数值
                        return;
                    }
                    //数据校验合格,重算记录
                    var HTaxRate = obj.data.HTaxRate * 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 HTaxPrice = Number((HPrice * (1 + HTaxRate)).toFixed(4));        //含税单价=单价*(1+税率)
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    //var HExRate = $("#HExRate").val();                       //汇率
                    //var HlineTotalBB = Number(((HMoney + HTaxMoney) * HExRate).toFixed(4));       //本位币价税合计=(税额+金额)*汇率
                    //数字精度
                    HQty = Number(HQty.toFixed(HQtyDec));
                    HPrice = Number(HPrice.toFixed(HPriceDec));
                    HMoney = Number(HMoney.toFixed(HMoneyDec));
                    HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                    HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                    HTaxPrice = Number(HPrice.toFixed(HPriceDec));
                    //同步更新表格和缓存对应的值
                    obj.update({   //更新表格数据
                        HTaxRate: HTaxRate * 100
                        , HQty: HQty
                        , HPrice: HPrice
                        , HMoney: HMoney
                        , HTaxMoney: HTaxMoney
                        , HTaxPrice: HTaxPrice
                        , HlineTotal: HlineTotal
                    });
                    table.render(option)
                    break;
                case "HTaxRate":
                     obj.update({
                         HTaxMoney: Math.ceil(parseFloat(obj.value) / 100 * parseFloat(obj.data.HMoney)),
                     });
                case "HTaxPrice":                                         //含税单价
                    //数据格式校验
                    temp = value + "";     //修改后的值 è½¬ä¸ºå­—符串 èµ‹å€¼ç»™  å˜é‡temp
                    if (!ref.test(temp)) { //检查单价字符串是否符合预期的格式
                        //恢复数据到编辑前
                        obj.update({            //更新表格某一行数据
                            HTaxPrice: oldText     //将hprice字段恢复到保存前的值
                        });
                        table.render(option);
                        layer.msg("含税单价请输入数字!");   //请输入单价的数值
                        return;
                    }
                    //数据校验合格,重算记录
                    var HQty = obj.data.HQty * 1;                   //数量
                    var HTaxPrice = value * 1;                    //含税单价
                    var HTaxRate = obj.data.HTaxRate * 0.01;           //税率
                    var HPrice = Number((HTaxPrice / (1 + HTaxRate)).toFixed(4));                         //单价 = å«ç¨Žå•ä»·/(1+税率)
                    var HMoney = HQty * HPrice;                     //金额=数量*单价
                    var HTaxMoney = Number((HMoney * HTaxRate).toFixed(4));         //税额=金额*税率
                    var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                    //数字精度
                    HQty = Number(HQty.toFixed(HQtyDec));
                    HPrice = Number(HPrice.toFixed(HPriceDec));
                    HMoney = Number(HMoney.toFixed(HMoneyDec));
                    HTaxMoney = Number(HTaxMoney.toFixed(HMoneyDec));
                    HlineTotal = Number(HlineTotal.toFixed(HMoneyDec));
                    HTaxPrice = Number(HPrice.toFixed(HPriceDec));
                    //同步更新表格和缓存对应的值
                    obj.update({                    //更新表格数据                æ–¹æ³•是该对象提供的一个方法,用于更新其内部状态或与之关联的数据源
                        HQty: HQty                               //更新HQty字段,HQty
                        , HPrice: HPrice                         //更新HPrice字段,HPrice
                        , HMoney: HMoney                      //更新HMoney字段,HMoney
                        , HTaxMoney: HTaxMoney                  //更新HTaxMoney字段,HTaxMoney
                        , HlineTotal: HlineTotal             //更新HlineTotal字段,HlineTotal
                        , HTaxPrice:HTaxPrice                   //更新HTaxPrice字段,HTaxPrice
                    });
                    table.render(option)
                    break;
                default:
            }
        });
@@ -814,6 +1081,32 @@
        }
            //#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
        //编辑 é¡µé¢èµ‹å€¼
        function RoadBillMain(linterid)//加载表头
        {