yangle
2024-01-10 450c5ef57e10dfa81c623186952899eedeb789f5
WebTM/views/ϵͳ¹ÜÀí/Óû§¹ÜÀí/Gy_UserCustomer_ImportByExcel.html
@@ -18,16 +18,57 @@
            <div class="layui-card-body" style="padding: 1px;">
                <form class="layui-form" action="" lay-filter="formData" style="background-color:white;">
                    <div style="padding: 10px; ">
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave" id="btnSave">导入数据</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="Cancel" id="Cancel">退出</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="UpLoad" id="UpLoad">文件上传</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="Confirm" id="Confirm">数据验证</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave_ReWrite" id="btnSave_ReWrite">覆盖导入</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave_Add" id="btnSave_Add">追加导入</button>
                        <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="Cancel" id="Cancel">退出</button>
                    </div>
                    <div class="layui-tab" lay-filter="tab-POStockInBill">
                        <div class="layui-tab-content">
                            <!--基本信息-->
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item" style="padding-top: 10px;">
                                    <div class="layui-row">
                                        <div class="layui-col-xs4 layui-inline" style="width:100%;">
                                            <label class="layui-form-label">导入字段(任选其一):</label>
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHUserID" id="checkboxHUserID" lay-skin="primary" lay-filter="checkboxHUserID" value="true" title="用户代码">
                                                <input type="hidden" value="false" name="HUserID" id="HUserID">
                                            </div>
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHUserName" id="checkboxHUserName" lay-skin="primary" lay-filter="checkboxHUserName" value="true" title="用户名称">
                                                <input type="hidden" value="false" name="HUserName" id="HUserName">
                                            </div>
                                            <!--<div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHCusNumber" id="checkboxHCusNumber" lay-skin="primary" lay-filter="checkboxHCusNumber" value="true" title="客户代码">
                                                <input type="hidden" value="false" name="HCusNumber" id="HCusNumber">
                                            </div>
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHCusName" id="checkboxHCusName" lay-skin="primary" lay-filter="checkboxHCusName" value="true" title="客户名称">
                                                <input type="hidden" value="false" name="HCusName" id="HCusName">
                                            </div>-->
                                        </div>
                                        <div class="layui-col-xs4 layui-inline" style="width:100%;">
                                            <label class="layui-form-label">导入字段(任选其一):</label>
                                            <!--<div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHCusNumber" id="checkboxHCusNumber" lay-skin="primary" lay-filter="checkboxHCusNumber" value="true" title="客户代码">
                                                <input type="hidden" value="false" name="HCusNumber" id="HCusNumber">
                                            </div>
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHCusName" id="checkboxHCusName" lay-skin="primary" lay-filter="checkboxHCusName" value="true" title="客户名称">
                                                <input type="hidden" value="false" name="HCusName" id="HCusName">
                                            </div>-->
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHOrgNumber" id="checkboxHOrgNumber" lay-skin="primary" lay-filter="checkboxHOrgNumber" value="true" title="组织代码">
                                                <input type="hidden" value="false" name="HOrgNumber" id="HOrgNumber">
                                            </div>
                                            <div class="layui-input-inline">
                                                <input type="checkbox" name="checkboxHOrgName" id="checkboxHOrgName" lay-skin="primary" lay-filter="checkboxHOrgName" value="true" title="组织名称">
                                                <input type="hidden" value="false" name="HOrgName" id="HOrgName">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
@@ -70,6 +111,9 @@
        var option = [];
        //记录验证标记
        var confirmBar = 0;
        //#endregion
        //#region è¿›å…¥é¡µé¢å³åŠ è½½
@@ -80,10 +124,58 @@
        //#region è§¦å‘事件:包括form.on(){}格式的所有点击事件、选择事件等
        //#region è¡¨å¤´æŒ‰é’®è§¦å‘事件
        //#region å¯¼å…¥  ä¿å­˜æ•°æ®
        form.on('submit(btnSave)', function (data) {
        //#region è¦†ç›–导入  ä¿å­˜æ•°æ®
        form.on('submit(btnSave_ReWrite)', function (data) {
            if (confirmBar == 1) {
                set_AddNew(data,1);
            } else {
                var reConfirmBar = 1;
                for (var i = 0; i < option.data.length; i++) {
                    if ( (option.data[i].判定结果 != "" && option.data[i].判定结果 != "用户已经关联该客户;") || (option.data[i].客户内码 === null || option.data[i].客户内码 == "") ) {
                        reConfirmBar = 0;
                        break;
                    }
                }
                if (reConfirmBar == 1) {
                    set_AddNew(data, 1);
                } else {
                    layer.msg("保存失败,数据未通过校验,请在修改后重新校验!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                }
            }
        })
        //#endregion
        //#region è¿½åР坼入  ä¿å­˜æ•°æ®
        form.on('submit(btnSave_Add)', function (data) {
            if (confirmBar == 1) {
                set_AddNew(data, 2);
            } else {
                layer.msg("保存失败,数据未通过校验,请在修改后重新校验!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
            }
        })
        //#endregion
        //#region å¯¼å…¥  æ•°æ®éªŒè¯
        form.on('submit(Confirm)', function (data) {
            var HUserID = document.getElementById("checkboxHUserID").checked;
            var HUserName = document.getElementById("checkboxHUserName").checked;
            //var HCusNumber = document.getElementById("checkboxHCusNumber").checked;
            //var HCusName = document.getElementById("checkboxHCusName").checked;
            var HOrgNumber = document.getElementById("checkboxHOrgNumber").checked;
            var HOrgName = document.getElementById("checkboxHOrgName").checked;
            if (!((HUserID == true && HUserName == false) || (HUserID == false && HUserName == true))) {
                layer.msg("请在用户代码和用户名称之间任选一个作为导入字段!");
                return false;
            }
            if (!((HOrgNumber == true && HOrgName == false) || (HOrgNumber == false && HOrgName == true))) {
                layer.msg("请在组织代码和组织名称之间任选一个作为导入字段!");
                return false;
            }
            if (AllowLoadData()) {
                set_AddNew(data);
                set_confirm(data);
            }
        })
        //#endregion
@@ -162,13 +254,27 @@
                , loading: false
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'HUserID', title: '用户代码', width: 120 }
                    , { field: '用户名称', title: '用户名称', width: 120 }
                    , { field: 'HCusID', title: '客户内码', width: 120, hide: true }
                    , { field: '客户代码', title: '客户代码', width: 120 }
                    , { field: '客户名称', title: '客户名称', width: 120 }
                    , { field: '用户代码', title: '用户代码', edit: "true", width: 120 }
                    , { field: '用户名称', title: '用户名称', edit: "true", width: 120 }
                    , { field: '客户内码', title: '客户内码', edit: "true", width: 120, hide: true }
                    , { field: '客户代码', title: '客户代码', edit: "true", width: 120 }
                    , { field: '客户名称', title: '客户名称', edit: "true", width: 120 }
                    , { field: '组织代码', title: '组织代码', edit: "true", width: 120 }
                    , { field: '组织名称', title: '组织名称', edit: "true", width: 120 }
                    , { field: '判定结果', title: '判定结果', edit: "true", width: 240 }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                ]]
                , done: function (res, curr, count) {
                    //循环表数据根据flag状态给行上色
                    $.each(res['data'], function (i, j) {
                        if (j['判定结果'] != '') {
                            Layui_SetDataTableRowColor('table', i + 1, 'red');
                        } else {
                            Layui_SetDataTableRowColor('table', i + 1, 'black');
                        }
                    });
                }
            };
            //渲染页面
            table.render(option);
@@ -176,8 +282,96 @@
        }
        //#endregion
        //#region ç»™table行上色
        function Layui_SetDataTableRowColor(TabDivId, RowIndex, ColorString) {
            try {
                var div = $("[lay-id='mainTable'] tr:eq(" + RowIndex + ")");
                if (div != null) //找到对象了
                {
                    // console.log(div);
                    div.css("color", ColorString);
                } else {
                    console.log('没有找到对象');
                }
            } catch (e) {
                console.log(e.message);
            }
        }
        //#endregion
        //#region å¯¼å…¥(数据验证)
        function set_confirm(data) {
            var num = [];
            for (var i = 0; i < option.data.length; i++) {
                if (option.data[i] != "") {
                    num.push(option.data[i])
                }
            }
            //获取导入字段
            var HUserID = document.getElementById("checkboxHUserID").checked;
            var HUserName = document.getElementById("checkboxHUserName").checked;
            //var HCusNumber = document.getElementById("checkboxHCusNumber").checked;
            //var HCusName = document.getElementById("checkboxHCusName").checked;
            var HOrgNumber = document.getElementById("checkboxHOrgNumber").checked;
            var HOrgName = document.getElementById("checkboxHOrgName").checked;
            var importList = "";
            if (HUserID == true) {
                importList += "HUserID;";
            } else if (HUserName == true) {
                importList += "HUserName;";
            }
            if (HOrgNumber == true) {
                importList += "HOrgNumber;";
            } else if (HOrgName == true) {
                importList += "HOrgName;";
            }
            //data.field.HOrgID = sessionStorage["OrganizationID"];//组织
            //var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"] + '&和' + importList;
            var index = layer.load();
            $.ajax({
                type: "POST",
                url: GetWEBURL() + "/Xt_User/Gy_UserCustomer_ImportByExcel_Confirm",
                async: true,
                data: { "sMainSub": sMainSub },
                dataType: "json",
                success: function (data) {
                    if (data.count == 1) {
                        if (data.Message == "1") {
                            confirmBar = 1;
                            for (var i = 0; i < option.cols[0].length; i++) {
                                option.cols[0][i].edit = "false";
                            }
                        } else {
                            confirmBar = 0;
                            for (var i = 0; i < option.cols[0].length; i++) {
                                option.cols[0][i].edit = "true";
                            }
                        }
                        option.data = data.data;
                        table.render(option);
                        layer.close(index);
                    }
                    else {
                        layer.close(index);
                        layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                },
                error: function (err) {
                    layer.close(index);
                    layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                }
            });
        }
        //#endregion
        //#region å¯¼å…¥(保存)
        function set_AddNew(data) {
        function set_AddNew(data, saveType) {
            var num = [];
            for (var i = 0; i < option.data.length; i++) {
                if (option.data[i] != "") {
@@ -188,7 +382,7 @@
            //data.field.HOrgID = sessionStorage["OrganizationID"];//组织
            //var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"];
            var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"] + '&和' + saveType;
            var index = layer.load();
            $.ajax({
@@ -209,10 +403,12 @@
                        layer.close(index);
                        layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                    confirmBar = 0;
                },
                error: function (err) {
                    layer.close(index);
                    layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    confirmBar = 0;
                }
            });
        }
@@ -229,15 +425,20 @@
                return false;
            }
            //if (confirmBar == 0) {
            //    layer.msg("数据存在问题,请在修改数据后重新校验!");
            //    return false;
            //}
            //关键字重复校验
            var num = [];
            var temp = "";
            for (var i = 0; i < data.length; i++) {
                temp = data[i]["HUserID"] + "," + data[i]["客户代码"];
                temp = data[i]["用户代码"] + "," + data[i]["客户代码"] + "," + data[i]["组织代码"];
                if ($.inArray(temp, num) == -1) {
                    num.push(temp);
                } else {
                    layer.msg("第" + (i + 1) + "行,用户编码与客户代码存在重复记录!");
                    layer.msg("第" + (i + 1) + "行,用户代码、客户代码和组织代码存在重复记录!");
                    return false;
                }
            }