1
cwjbxqmz
2024-01-15 a9ae83b7277095faaee79b0cb3fcb975bd494357
WebTM/views/ÏúÊÛ¹ÜÀí/ÏúÊÛ¶©µ¥/Add_Edit_Xs_SeOrderBillList.html
@@ -45,6 +45,8 @@
                    <div class="layui-card-header">
                        <div class="layui-btn-group">
                            <button type="button" id="add-btn" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="set_SaveBill">保存</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="set_CheckBill">审核</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="btn-print">打印</button>
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit">退出</button>
                        </div>
                    </div>
@@ -69,8 +71,8 @@
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">日期<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="date" class="layui-input" lay-verify="HDate" name="HDate" id="HDate" style="padding-left: 80px;">
                                            <div class="layui-input-block">
                                                <input type="date" class="layui-input" lay-verify="HDate" name="HDate" id="HDate" style="width:190px;">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
@@ -96,6 +98,16 @@
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">客户<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HCusName" id="HCusName" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;">
                                                <input type="hidden" name="HCusID" id="HCusID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HCusList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">销售币别<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HCurName" id="HCurName" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;">
@@ -109,16 +121,6 @@
                                            <label class="layui-form-label">汇率<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HExRate" id="HExRate" autocomplete="off" value="0" style="background-color: #efefef4d;" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline" style="width:900px;">
                                            <label class="layui-form-label">客户<label style="color:red"> * </label></label>
                                            <div class="layui-input-inline" style="width:700px;">
                                                <input type="text" name="HCusName" id="HCusName" class="layui-input" value="" style="float: left; width: 465px; background-color: #efefef4d;" readonly>
                                                <input type="hidden" name="HCusID" id="HCusID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HCusList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
@@ -144,27 +146,9 @@
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">摘要</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HExplanation" id="HExplanation" autocomplete="off" style="width: 501px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">销售主管</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HManagerName" id="HManagerName" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;" readonly>
                                                <input type="hidden" name="HManagerID" id="HManagerID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HManagerList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">联系人</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HLinkMan" id="HLinkMan" autocomplete="off" value="" >
                                                <input class="layui-input" name="HLinkMan" id="HLinkMan" autocomplete="off" value="">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
@@ -173,18 +157,38 @@
                                                <input class="layui-input" name="HLinkPhone" id="HLinkPhone" autocomplete="off" value="">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">内部订单号</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HInnerBillNo" id="HInnerBillNo" style="background-color: #efefef4d;" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">备注</label>
                                            <div class="layui-input-block">
                                                <input class="layui-input" name="HRemark" id="HRemark" autocomplete="off" style="width: 1135px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">客户余额<i class="layui-icon layui-icon-tips" id="tips-HCusBalance"></i></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HCusBalance" id="HCusBalance" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">信用额度</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HCreditRating_Now" id="HCreditRating_Now" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">可用额度<i class="layui-icon layui-icon-tips" id="tips-HAvailableBalance"></i></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HAvailableBalance" id="HAvailableBalance" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">需求金额<i class="layui-icon layui-icon-tips" id="tips-HBillMoney"></i></label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HBillMoney" id="HBillMoney" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                    </div>
@@ -197,21 +201,33 @@
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">客户余额</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="" id="" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">客户信用额度</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="" id="" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <!--隐藏字段:暂时没有用处-->
                                    <div class="layui-row" style="display:none;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">销售主管</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="HManagerName" id="HManagerName" class="layui-input" value="" style="float: left; width: 150px; background-color: #efefef4d;" readonly>
                                                <input type="hidden" name="HManagerID" id="HManagerID" class="layui-input" value="0" style="float:left;width:150px;">
                                                <button type="button" lay-submit="" class="layui-btn" lay-filter="HManagerList" style="width:40px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">内部订单号</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HInnerBillNo" id="HInnerBillNo" style="background-color: #efefef4d;" autocomplete="off" readonly>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">摘要</label>
                                            <div class="layui-input-inline">
                                                <input class="layui-input" name="HExplanation" id="HExplanation" autocomplete="off" style="width: 501px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row" style="display:none;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">结算日期</label>
@@ -392,11 +408,27 @@
            //#endregion 
            //#region åˆ¤æ–­å¹¶è®¾ç½®æ“ä½œç±»åž‹ã€é¡µé¢åˆå§‹åŒ–
            if (OperationType == null || OperationType == 1) {                            //新增
            if (OperationType == null || OperationType == 1) {                          //新增
                //新增页面初始化
                Init_setAdd();
            }
            else if (OperationType == 3) {                                                 //编辑
            else if (OperationType == 2) {                                              //复制
                //子表初始化
                set_InitGrid();
                //加载表体和表体数据
                RoadBillMain(linterid);
                //生成并设置主表的内码和单据号
                createBillNo();
                //相关文本框信息初始化
                $("#HDate").val(Format(new Date(), "yyyy-MM-dd"));
                $("#HSSDate").val(Format(new Date(), "yyyy-MM-dd"));
                $("#HMaker").val(sessionStorage["HUserName"]);
                $("#HMakeDate").val(Format(new Date(), "yyyy-MM-dd"));
            }
            else if (OperationType == 3) {                                              //编辑
                $("#HInterID").val(linterid);
                //子表初始化
                set_InitGrid();
@@ -407,6 +439,10 @@
            //#region åˆå§‹åŒ–组织
            Organ();
            //#endregion
            //#region é¡µé¢åˆå§‹åŒ–后,根据客户获取客户余额
            getCustomerBalance( $("#HCusID").val() );
            //#endregion
            //#region åˆ—设置:子表1
@@ -474,6 +510,18 @@
            });
            //#endregion
            //#region å®¡æ ¸æŒ‰é’®
            form.on('submit(set_CheckBill)', function (data) {
                set_CheckBill(0);
            });
            //#endregion
            //#region æ‰“印按钮
            form.on('submit(btn-print)', function (data) {
                get_PrintReport();
            });
            //#endregion
            //#region é€€å‡ºæŒ‰é’®
            form.on('submit(Exit)', function () {
                if (params[1] != null) {
@@ -496,6 +544,9 @@
                    "HMaterID": "0",
                    "物料代码": "",
                    "物料名称": "",
                    "HItemID": "0",
                    "订单等级代码": "",
                    "订单等级名称": "",
                    "规格型号": "",
                    "HUnitID": "0",
                    "计量单位": "",
@@ -601,7 +652,13 @@
                        var HTaxMoney = HMoney * HTaxRate;              //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        //设置数据小数位数
                        HQty = dealDoubleToFixed(HQty, 1);
                        HPrice = dealDoubleToFixed(HPrice, 3);
                        HTaxRate = HTaxRate;
                        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
                        HMoney = dealDoubleToFixed(HMoney, 2);
                        HlineTotal = dealDoubleToFixed(HlineTotal, 2);
                        //同步更新表格和缓存对应的值
                        obj.update({
@@ -613,6 +670,8 @@
                            , HlineTotal: HlineTotal
                        });
                        table.render(option);
                        //设置表头所需金额
                        set_HBillMoney();
                        break;
                    case "HPrice":                                                       //单价
                        //数据格式校验
@@ -641,7 +700,13 @@
                        var HTaxMoney = HMoney * HTaxRate;              //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        //设置数据小数位数
                        HQty = dealDoubleToFixed(HQty, 1);
                        HPrice = dealDoubleToFixed(HPrice, 3);
                        HTaxRate = HTaxRate;
                        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
                        HMoney = dealDoubleToFixed(HMoney, 2);
                        HlineTotal = dealDoubleToFixed(HlineTotal, 2);
                        //同步更新表格和缓存对应的值
                        obj.update({
@@ -653,18 +718,20 @@
                            , HlineTotal: HlineTotal
                        });
                        table.render(option);
                        //设置表头所需金额
                        set_HBillMoney();
                        break;
                    case "HTaxRate":                                                       //数量
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp) || temp == 0) {
                        if (!ref.test(temp)) {
                            //恢复数据到编辑前
                            obj.update({
                                HTaxRate: oldText
                            });
                            table.render(option);
                            layer.msg("税率请输入大于0的数字!");
                            layer.msg("税率请输入不小于0的数字!");
                            return;
                        }
@@ -681,7 +748,13 @@
                        var HTaxMoney = HMoney * HTaxRate;              //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        //设置数据小数位数
                        HQty = dealDoubleToFixed(HQty, 1);
                        HPrice = dealDoubleToFixed(HPrice, 3);
                        HTaxRate = HTaxRate;
                        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
                        HMoney = dealDoubleToFixed(HMoney, 2);
                        HlineTotal = dealDoubleToFixed(HlineTotal, 2);
                        //同步更新表格和缓存对应的值
                        obj.update({
@@ -693,11 +766,86 @@
                            , HlineTotal: HlineTotal
                        });
                        table.render(option);
                        //设置表头所需金额
                        set_HBillMoney();
                        break;
                    case "HTaxPrice":                                                       //数量
                        //数据格式校验
                        temp = value + "";
                        if (!ref.test(temp)) {
                            //恢复数据到编辑前
                            obj.update({
                                HTaxPrice: oldText
                            });
                            table.render(option);
                            layer.msg("含税单据请输入不小于0的数字!");
                            return;
                        }
                        //数据校验合格,重算记录
                        var HQty = obj.data.HQty * 1;                   //数量
                        var HTaxRate = obj.data.HTaxRate * 0.01;        //税率
                        var HTaxPrice = value * 1;                          //含税单价=单价*(1+税率)
                        var HPrice = HTaxPrice / (1 + HTaxRate);        //单价=含税单据/(1+税率)
                        /*var HDiscountRate = obj.data.HDiscountRate * 1; //折扣率*/
                        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;   //实际含税单价=含税单价*折扣率*/
                        //折扣额 = å«ç¨Žå•ä»· * (1 - æŠ˜æ‰£çއ) * æ•°é‡
                        var HMoney = HQty * HPrice;                     //金额=数量*单价
                        var HTaxMoney = HMoney * HTaxRate;              //税额=金额*税率
                        var HlineTotal = HMoney + HTaxMoney;            //价税合计=金额+税额
                        //设置数据小数位数
                        HQty = dealDoubleToFixed(HQty, 1);
                        HPrice = dealDoubleToFixed(HPrice, 3);
                        HTaxRate = HTaxRate;
                        HTaxPrice = dealDoubleToFixed(HTaxPrice, 3);
                        HMoney = dealDoubleToFixed(HMoney, 2);
                        HlineTotal = dealDoubleToFixed(HlineTotal, 2);
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HQty: HQty
                            , HPrice: HPrice
                            , HTaxRate: HTaxRate * 100
                            , HTaxPrice: HTaxPrice
                            , HMoney: HMoney
                            , HlineTotal: HlineTotal
                        });
                        table.render(option);
                        //设置表头所需金额
                        set_HBillMoney();
                        break;
                    default:
                }
            });
            //#endregion
            //#endregion
            //#region æ–‡æœ¬æ¡†ç›‘听
            $(document).ready(function () {
                //#region å®¢æˆ·ä½™é¢æç¤ºä¿¡æ¯
                $("#tips-HCusBalance").on('click', function (data) {
                    var tips_Message = "客户余额 = æœŸåˆ+本期收款(已审核)-本期退款(已审核)-本期出库(已审核)+本期退货(已审核)";
                    layer.alert(tips_Message, { icon: 0, btn: ['退出'], time: 100000, offset: 't' });
                });
                //#endregion
                //#region å¯ç”¨ä½™é¢æç¤ºä¿¡æ¯
                $("#tips-HAvailableBalance").on('click', function (data) {
                    var tips_Message = "可用额度 = å®¢æˆ·ä½™é¢ + ä¿¡ç”¨é¢åº¦ - ï¼ˆæœ¬æœŸé”€å”®è®¢å•总金额 * 0.5)";
                    layer.alert(tips_Message, { icon: 0, btn: ['退出'], time: 100000, offset: 't' });
                });
                //#endregion
                //#region éœ€æ±‚金额
                $("#tips-HBillMoney").on('click', function (data) {
                    var tips_Message = "需求金额 = ä»·ç¨Žåˆè®¡ * 0.5";
                    layer.alert(tips_Message, { icon: 0, btn: ['退出'], time: 100000, offset: 't' });
                });
                //#endregion
            });
            //#endregion
            //#endregion
@@ -807,24 +955,28 @@
                option = {
                    elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , totalRow: true
                    , limit: 500
                    , height: 500
                    , loading: false
                    , cols: [[ //子表
                        { type: 'checkbox', totalRowText: '合计行', style: 'background-color:#efefef4d;' }
                        , { type: 'numbers', title: '序号', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { type: 'numbers', title: '序号', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HMaterID', title: 'HMaterID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '物料代码', title: '物料代码', width: 150, edit: 'text', event: "HMaterID" }//f7
                        , { field: '物料名称', title: '物料名称', width: 150, style: 'background-color:#efefef4d;' }
                        , { field: 'HOrderLevID', title: 'HOrderLevID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '订单等级代码', title: '订单等级代码', width: 150, edit: 'text', event: "HOrderLevID" }//f7
                        , { field: '订单等级名称', title: '订单等级名称', width: 150, style: 'background-color:#efefef4d;' }
                        , { field: '规格型号', title: '规格型号', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HUnitID', title: 'HUnitID', width: 100, hide: true, style: 'background-color:#efefef4d;' }
                        , { field: '计量单位', title: '计量单位', width: 100, style: 'background-color:#efefef4d;' }//f7
                        , { field: 'HQty', title: '数量', width: 100, edit: 'text' }
                        , { field: 'HQty', title: '数量', width: 100, totalRow: true, edit: 'text' }
                        , { field: 'HPrice', title: '单价', width: 100, edit: 'text' }
                        , { field: 'HTaxRate', title: '税率', width: 100, edit: 'text' }
                        , { field: 'HTaxPrice', title: '含税单价', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HMoney', title: '金额', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HlineTotal', title: '价税合计', width: 100, style: 'background-color:#efefef4d;' }
                        , { field: 'HTaxPrice', title: '含税单价', width: 100, edit: 'text' }
                        , { field: 'HMoney', title: '金额', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HlineTotal', title: '价税合计', width: 100, totalRow: true, style: 'background-color:#efefef4d;' }
                        , { field: 'HDate', title: '交货日期', event: "HDate", width: 120 }
                        , { field: 'HRemark', title: '备注', width: 100, edit: 'text' }
@@ -843,6 +995,9 @@
                    "HMaterID": "0",
                    "物料代码": "",
                    "物料名称": "",
                    "HOrderLevID": "0",
                    "订单等级代码": "",
                    "订单等级名称": "",
                    "规格型号": "",
                    "HUnitID": "0",
                    "计量单位": "",
@@ -864,6 +1019,9 @@
                option.data = rowdata;
                table.render(option);
                //设置表头所需金额
                set_HBillMoney();
            }
            //#endregion
@@ -931,6 +1089,7 @@
                                , "HLinkMan": data.联系人
                                , "HExplanation": data.摘要
                                , "HLinkPhone": data.联系电话
                                , "HCreditRating_Now": data.HCreditRating_Now
                                , "HRemark": data.表头备注
                                , "HMaker": data.制单人
                                , "HMakeDate": data.制单人 == "" ? "" :formatDate(data.制单日期)
@@ -948,6 +1107,8 @@
                            //组织的值HOrgID变化,重新渲染
                            HOrgIDBar = data.HOrgID;
                            //获取税率(用于子表税率的默认值)
                            getHTaxRateByCusID(data.HCusID);
                            //子表  èµ‹å€¼
                            var rowdata = [];
@@ -957,18 +1118,21 @@
                                        "HMaterID": result.data[i]["HMaterID"],
                                        "物料代码": result.data[i]["物料代码"],
                                        "物料名称": result.data[i]["物料名称"],
                                        "HOrderLevID": result.data[i]["HOrderLevID"],
                                        "订单等级代码": result.data[i]["订单等级代码"],
                                        "订单等级名称": result.data[i]["订单等级名称"],
                                        "规格型号": result.data[i]["规格型号"],
                                        "HUnitID": result.data[i]["HUnitID"],
                                        "计量单位": result.data[i]["计量单位"],
                                        "HQty": result.data[i]["数量"],
                                        "HPrice": result.data[i]["单价"],
                                        "HTaxPrice": result.data[i]["含税单价"],
                                        "HMoney": result.data[i]["金额"],
                                        "HQty": dealDoubleToFixed(result.data[i]["数量"], 1),
                                        "HPrice": dealDoubleToFixed(result.data[i]["单价"], 3),
                                        "HTaxPrice": dealDoubleToFixed(result.data[i]["含税单价"], 3),
                                        "HMoney": dealDoubleToFixed(result.data[i]["金额"],2),
                                        "HDiscountRate": result.data[i]["折扣率"],
                                        "HRelTaxPrice": result.data[i]["实际含税单价"],
                                        "HTaxRate": result.data[i]["税率"],
                                        "HTaxMoney": result.data[i]["税额"],
                                        "HlineTotal": result.data[i]["价税合计"],
                                        "HlineTotal": dealDoubleToFixed(result.data[i]["价税合计"],2),
                                        "HlineTotalBB": result.data[i]["本位币价税合计"],
                                        "HDate": formatDate(result.data[i]["交货日期"]),
                                        "HOutStockQty": result.data[i]["出库数量"],
@@ -984,6 +1148,9 @@
                            option.cols[0][20].edit = null;
                            table.render(option);
                            //设置表头所需金额
                            set_HBillMoney();
                            layer.close(ajaxLoad);
                        } else {
                            layer.close(ajaxLoad);
@@ -1039,6 +1206,9 @@
                            return layer.msg('请选择数据');
                        }
                        getCustomerByCusID(checkStatus.data[0].HItemID);
                        //根据客户获取客户余额
                        getCustomerBalance(checkStatus.data[0].HItemID);
                        layer.close(index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                    }
                    , btn2: function (index, layero) { }
@@ -1485,6 +1655,8 @@
                table.cache["mainTable"].push(NewRow);
                option.data = table.cache["mainTable"];
                table.render(option);
                //设置表头所需金额
                set_HBillMoney();
                //rows++;
                layer.msg('增加一行按钮!')
            }
@@ -1506,6 +1678,8 @@
                    }
                    option.data = tables;
                    table.render(option);
                    //设置表头所需金额
                    set_HBillMoney();
                } else {
                    layer.msg('请选择一行数据编辑!');
                }
@@ -1530,6 +1704,8 @@
                    option.data[option.data.length - 1].HWeight = "0";
                    table.render(option);//将数据渲染到表格上
                    //设置表头所需金额
                    set_HBillMoney();
                }
            }
            //#endregion
@@ -1554,6 +1730,8 @@
                            option.data[i - 1] = data[0];
                            option.data[i] = tables[0];
                            table.render(option);
                            //设置表头所需金额
                            set_HBillMoney();
                            break;
                        }
                    }
@@ -1585,6 +1763,8 @@
                            option.data[i + 1] = data[0];
                            option.data[i] = tables[0];
                            table.render(option);
                            //设置表头所需金额
                            set_HBillMoney();
                            break;
                        }
                    }
@@ -1610,6 +1790,8 @@
                            oldData.splice(obj.tr.data('index'), 1);
                            option.data = oldData;
                            table.render(option);
                            //设置表头所需金额
                            set_HBillMoney();
                            layer.close(index);
                        }
                    });
@@ -1623,6 +1805,8 @@
                    if (event.key == "F7") {
                        //物料
                        if (obj.event == "HMaterID") {
                            var HOrgID = $("#HOrgID").val();
                            layer.open({
                                type: 2
                                , skin: "layui-layer-rim" //加上边框
@@ -1631,26 +1815,78 @@
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置最大最小按钮是否显示
                                , content: ['../../Baseset/基础资料/Gy_MaterialList.html', 'yes']
                                , 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("请选择一条数据");
                                    }
                                    //if (checkStatus.data.length != 1) {
                                    //    return layer.msg("请选择一条数据");
                                    //}
                                    //更新表格缓存的数据
                                    obj.update({
                                        "HMaterID": checkStatus.data[0].HItemID
                                        , "物料代码": checkStatus.data[0].HNumber
                                        , "物料名称": checkStatus.data[0].HName
                                        , "规格型号": checkStatus.data[0].HModel
                                        , "HUnitID": checkStatus.data[0].HUnitID
                                        , "计量单位": checkStatus.data[0].HUnitName
                                    })
                                    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", "计量单位": "", "HQty": "0", "HPrice": "0", "HTaxPrice": "0"
                                                , "HMoney": "0", "HDiscountRate": "0", "HRelTaxPrice": "0", "HTaxRate": "0", "HTaxMoney": "0", "HlineTotal": "0", "HlineTotalBB": "0"
                                                , "HDate": Format(new Date(), 'yyyy-MM-dd'), "HOutStockQty": "0", "HInvoiceQty": "0", "HRemark": ""
                                            }
                                            btnAddLine(NewRow);
                                        }
                                        //获取选中的物料信息
                                        var resultData = checkStatus.data[i];
                                        //数值格式校验工具
                                        var ref = /^\d+(\.\d+)?$/;                                  //非负数正则表达式
                                        var temp = "";
                                        //获取选择物料前后的税率
                                        var value = subHTaxRate;                                    //选择物料后根据客户得到的税率
                                        var oldText = option.data[rowIndex + i].HTaxRate;           //该记录中原有的税率
                                        //税率数据格式校验,若根据客户获取的税率不合法,则使用记录中原有的税率,并提示
                                        temp = value + "";
                                        if (!ref.test(temp)) {
                                            value = oldText;
                                            layer.msg("获取到的税率不合法,已自动变更为原有税率!");
                                        }
                                        //数据校验合格,重算记录
                                        var HQty = option.data[rowIndex + i].HQty;                  //数量
                                        var HPrice = option.data[rowIndex + i].HPrice;              //单价
                                        var HTaxRate = value * 0.01;                                //税率
                                        /*var HDiscountRate = obj.data.HDiscountRate * 1;           //折扣率*/
                                        var HTaxPrice = HPrice * (1 + HTaxRate);                    //含税单价=单价*(1+税率)
                                        /*var HRelTaxPrice = HTaxPrice * HDiscountRate;             //实际含税单价=含税单价*折扣率*/
                                        //折扣额 = å«ç¨Žå•ä»· * (1 - æŠ˜æ‰£çއ) * æ•°é‡
                                        var HMoney = HQty * HPrice;                                 //金额=数量*单价
                                        var HTaxMoney = HMoney * HTaxRate;                          //税额=金额*税率
                                        var HlineTotal = HMoney + HTaxMoney;                        //价税合计=金额+税额
                                        option.data[rowIndex + i].HMaterID = resultData.HItemID;
                                        option.data[rowIndex + i].物料代码 = resultData.物料代码;
                                        option.data[rowIndex + i].物料名称 = resultData.物料名称;
                                        option.data[rowIndex + i].规格型号 = resultData.规格型号;
                                        option.data[rowIndex + i].HUnitID = resultData.HUnitID;
                                        option.data[rowIndex + i].计量单位 = resultData.计量单位名称;
                                        option.data[rowIndex + i].HQty = HQty;
                                        option.data[rowIndex + i].HPrice = HPrice;
                                        option.data[rowIndex + i].HTaxRate = HTaxRate * 100;
                                        option.data[rowIndex + i].HTaxPrice = HTaxPrice;
                                        option.data[rowIndex + i].HMoney = HMoney;
                                        option.data[rowIndex + i].HlineTotal = HlineTotal;
                                    }
                                    table.render(option);
                                    //设置表头所需金额
                                    set_HBillMoney();
                                    layer.close(index);//关闭弹窗
                                }
                            })
@@ -1684,6 +1920,37 @@
                                }
                            })
                        }
                        //订单等级
                        if (obj.event == "HOrderLevID") {
                            layer.open({
                                type: 2
                                , skin: "layui-layer-rim" //加上边框
                                , title: "订单等级列表"  //标题
                                , closeBtn: 1  //窗体右上角关闭 çš„ æ ·å¼
                                , shift: 2 //弹出动画
                                , area: ["90%", "90%"] //窗体大小
                                , maxmin: true //设置最大最小按钮是否显示
                                , content: ['../../基础资料/公用基础资料/Gy_OrderLev.html', '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("请选择一条数据");
                                    }
                                    //更新表格缓存的数据
                                    obj.update({
                                        "订单等级名称": checkStatus.data[0].订单等级
                                        , "订单等级代码": checkStatus.data[0].订单等级代码
                                        , "HOrderLevID": checkStatus.data[0].HItemID
                                    })
                                    layer.close(index);//关闭弹窗
                                }
                            })
                        }
                        obj.event = "";
                        return false;
                    }
@@ -1819,15 +2086,120 @@
            }
            //#endregion
            //#region åå®¡æ ¸/审核数据
            function set_CheckBill(num) {
                var InterID = $("#HInterID").val();
                //逻辑审核方法
                $.ajax({
                    type: "GET",
                    url: GetWEBURL() + "/Xs_SeOrderBill/AuditXs_SeOrderBill", //方法所在页面和方法名
                    data: { "HInterID": InterID, "IsAudit": num, "CurUserName": sessionStorage["HUserName"] },
                    success: function (result) {
                        if (result.count == 1) {
                            layer.msg(result.Message, { time: 1 * 1000, icon: 1 }, function () {
                                // å¾—到frame索引
                                var index = layer.getFrameIndex(window.name);
                                //关闭当前frame
                                layer.close(index);
                            });
                        } else {
                            layer.alert(result.code + result.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
            //#endregion
            //#region æ‰“印
            function get_PrintReport() {
                //#region åˆ¤æ–­æºå•状态
                var HSourceBillData = "";
                var HSourceBillData = getSourceBillStatus_SeOrderBill();            //获取源单数据
                if (HSourceBillData != "none") {
                    if (HSourceBillData.length == 0) {
                        layer.alert("打印失败!未查询到单据信息!", { icon: 5 });
                        return;
                    } else if (HSourceBillData[0]["状态"] != "已审核") {
                        layer.alert("打印失败!单据状态未为'已审核'状态!", { icon: 5 });
                        return;
                    }
                } else {
                    return;
                }
                //#endregion
                var InterID = $("#HInterID").val();
                $.ajax({
                    type: "GET",
                    url: GetWEBURL() + "/Xs_SeOrderBill/CheckSeOrderBill_IsExist", //方法所在页面和方法名
                    data: { "HInterID": InterID},
                    success: function (result) {
                        if (result.count == 1) {
                            layer.open({
                                type: 2
                                , area: ['50%', '50%']
                                , title: '打印模版选择'
                                , shade: 0.6 //遮罩透明度
                                , maxmin: false //允许全屏最小化
                                , anim: 0 //0-6的动画形式,-1不开启
                                , content: ['../../BaseSet/SRM_OpenTmpList.html?linterid=' + InterID + '&MyMsg=' + InterID + '&Type=Xs_SeOrderBill', 'yes']
                                , resize: false
                            })
                        } else {
                            layer.alert(result.code + result.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
            //#endregion
            //#region è®¾ç½®è¡¨å¤´æ‰€éœ€é‡‘额
            function set_HBillMoney() {
                var HBillMoney = 0;
                for (var i = 0; i < option.data.length; i++) {
                    HBillMoney += option.data[i]["HlineTotal"] * 1;
                }
                $("#HBillMoney").val(HBillMoney * 0.5);
            }
            //#endregion
            //#region èŽ·å–æºå•-销售订单单据状态
            function getSourceBillStatus_SeOrderBill() {
                var HSourceBillData = "none";
                var sWhere = " and hmainid = " + $("#HInterID").val();
                $.ajax({
                    url: GetWEBURL() + '/Xs_SeOrderBill/list',
                    async: false,
                    type: "GET",
                    data: { "sWhere": sWhere, "user": sessionStorage["HUserName"] },
                    success: function (data1) {
                        if (data1.count == 1) {
                            HSourceBillData = data1.data;
                        } else {
                            layer.alert(data1.code + "单据状态判断失败!", { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
                return HSourceBillData;
            }
            //#endregion
            //#endregion
            //以上是layui模块
        });
        //子表税率,根据客户带出
        var subHTaxRate = 0;
        // åŸºç¡€èµ„料返回数据
        function GetHEmpValue(obj)  //返回业务员
        {
@@ -1839,7 +2211,10 @@
        {
            //$("#HCusName").val(obj[0].HName);
            //$("#HCusID").val(obj[0].HItemID);
            //根据客户获取相关信息
            getCustomerByCusID(obj[0].HItemID);
            //根据客户获取客户余额
            getCustomerBalance(obj[0].HItemID);
        }
        function GetHManagerValue(obj)  //返回主管
@@ -1854,7 +2229,19 @@
            $("#HDeptID").val(obj[0].HItemID);
        }
        //#region æ ¹æ®å®¢æˆ·èŽ·å–å¸åˆ«ã€æ±‡çŽ‡ã€ç»“ç®—æ–¹å¼
        function GetSettleStyleValue(obj)           //返回结算方式
        {
            $("#HSSName").val(obj[0].HName);
            $("#HSSID").val(obj[0].HItemID);
        }
        function GetSellStyleValue(obj)           //返回销售方式
        {
            $("#HSellSName").val(obj[0].HName);
            $("#HSellSID").val(obj[0].HItemID);
        }
        //#region æ ¹æ®å®¢æˆ·èŽ·å–å¸åˆ«ã€æ±‡çŽ‡ã€ç»“ç®—æ–¹å¼ã€å®¢æˆ·ä¿¡ç”¨é¢åº¦ã€è”ç³»äººã€è”ç³»ç”µè¯
        function getCustomerByCusID(HCusID) {
            $.ajax({
                url: GetWEBURL() + "/Xs_SeOrderBill/getCustomerByCusID",
@@ -1874,7 +2261,11 @@
                        $("#HExRate").val(data.HExRate);
                        $("#HSSID").val(data.HSSID);
                        $("#HSSName").val(data.HSSName);
                        $("#HCreditRating_Now").val(data.HCreditRating_Now);
                        $("#HLinkMan").val(data.HLinkMan);
                        $("#HLinkPhone").val(data.HLinkPhone);
                        subHTaxRate = data.HTaxRate;
                    } else {
                        layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
@@ -1885,6 +2276,92 @@
            });
        }
        //#endregion
        //#region æ ¹æ®å®¢æˆ·èŽ·å–å®¢æˆ·å¯¹åº”ç¨ŽçŽ‡
        function getHTaxRateByCusID(HCusID) {
            $.ajax({
                url: GetWEBURL() + "/Xs_SeOrderBill/getCustomerByCusID",
                async: false,
                type: "GET",
                data: {
                    "HCusID": HCusID
                },
                success: function (result) {
                    if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                        var data = result.data[0];
                        subHTaxRate = data.HTaxRate;
                    } else {
                        layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                    }
                }, error: function () {
                    layer.alert("发生错误!", { icon: 5 });
                }
            });
        }
        //#endregion
        //#region æ ¹æ®å®¢æˆ·èŽ·å–å®¢æˆ·ä½™é¢
        function getCustomerBalance(HCusID) {
            $.ajax({
                url: GetWEBURL() + "/Xs_CusRatingChangeBill/getCustomerBalance",
                async: false,
                type: "GET",
                data: {
                    "HCusID": HCusID
                },
                success: function (result) {
                    if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                        var data = result.data[0];
                        $("#HCusBalance").val(data.HCusBalance == null ? 0 : data.HCusBalance);
                        $("#HCreditRating_Now").val(data.HCreditRating_Now == null ? 0 : data.HCreditRating_Now);
                        $("#HAvailableBalance").val(data.HAvailableBalance == null ? 0 : data.HAvailableBalance);
                    } else {
                        layer.alert(result.Message, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                    }
                }, error: function () {
                    layer.alert("发生错误!", { icon: 5 });
                }
            });
        }
        //#endregion
        //#region å¤„理小数显示位数(data:需要处理的数据;num:数据的类型(如1:数量;2:金额;3:单价))
        function dealDoubleToFixed(data, num) {
            //用于设置小数位数
            var dotLength = 0;
            if (num == 1) {                                    //当数据为数量时,最多保留6位小数
                //设置最多保留6位小数
                dotLength = 6;
            } else if (num == 2) {                             //当数据为金额时,最多保留2位小数
                //设置最多保留2位小数
                dotLength = 2;
            } else if (num == 3) {                             //当数据为单价时,最多保留4位小数
                //设置最多保留4位小数
                dotLength = 4;
            }
            //判断是否存在小数点及其索引位置
            data = data + "";
            var index = data.indexOf(".");
            //处理数据并返回
            if (index < 0) {
                return data * 1;
            } else {
                //获取小数位数
                var length = data.length - index - 1;
                if (length <= dotLength) {
                    return data * 1;
                } else {
                    data = data * 1;
                    return data.toFixed(dotLength);
                }
            }
        }
            //#endregion
    </script>
</body>
</html>