yusijie
2024-03-25 9416e867ca3428032a6f8989d9be46242d73cd0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>用户关联客户导入</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/Scripts/json2.js"></script>
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 2px;background-color: #efefef;">
            <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="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>
                    </div>
 
                    <table class="" id="mainTable" lay-filter="mainTable"></table>
                    <script type="text/html" id="toolbarDemo">
                        <div class="layui-btn-container">
                        </div>
                    </script>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
 
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['tree', 'index', 'form', 'table', 'element', 'laypage', 'laydate', 'util', 'upload'], function () {
        //#region 公用变量
        var $ = layui.$
            , admin = layui.admin
            , layer = layui.layer
            , table = layui.table
            , form = layui.form
            , element = layui.element
            , laypage = layui.laypage
            , laydate = layui.laydate
            , util = layui.util
            , tree = layui.tree
            , util = layui.util
            , upload = layui.upload
 
 
        var option = [];
 
        //记录验证标记
        var confirmBar = 0;
        //#endregion
 
        //#region 进入页面即加载
        //#region 初始化界面
        set_ClearBill();
        //#endregion
        //#endregion
 
        //#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
        //#region 表头按钮触发事件
        //#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_confirm(data);
            }
        })
        //#endregion
 
        //#region 文件上传
        upload.render({
            elem: '#UpLoad',
            url: GetWEBURL() + '/Xt_User/Gy_UserCustomer_ImportByExcel',
            contentType: 'application/json',
            exts: 'xls|xlsx', //允许上传的类型
            //data: {
            //    "WorkBookName": function () {
            //        return $("#WorkBookName").val();
            //    },
            //    "HOrgID": function () {
            //        return sessionStorage["OrganizationID"];
            //    }
            //},
            //before: function (data) {
            //    loadIndex = layer.load(2);
            //    this.data = {
            //        "WorkBookName": $("#WorkBookName").val(),
            //        "HOrgID": sessionStorage["OrganizationID"]
 
            //    }
            //},
            done: function (data1) {
                if (data1.count == 1) {
                    option.data = data1.data;
                    table.render(option);
                } else {
                    layer.alert(data1.code + data1.Message, { icon: 5 });
                }
            },
            error: function (err) {
                debugger
                layer.alert('导入出现异常', { icon: 2 });
            }
        });
        //#endregion
 
        //#region 退出
        form.on('submit(Cancel)', function () {
            Pub_Close(1);
        })
        //#endregion
        //#endregion
 
        //#region 子表触发事件
        //#region 行内事件
        table.on('tool(mainTable)', function (obj) {
            set_GridDelete(obj);   //行内删除
        });
        //#endregion
        //#endregion 
        //#endregion
 
        //#region 此页面所有的方法
        //#region 初始化界面
        function set_ClearBill() {
            //初始化表格
            set_InitGrid();
        }
        //#endregion
 
        //#region 初始化表格
        function set_InitGrid() {
            option = {
                elem: '#mainTable'
                , toolbar: '#toolbarDemo'
                , height: 'full-120'
                , page: true
                , cellMinWidth: 90
                , limit: 50
                , limits: [50, 500, 5000, 20000]
                , loading: false
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { 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);
            //DisPlay_HideColumn();
        }
        //#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, saveType) {
            var num = [];
            for (var i = 0; i < option.data.length; i++) {
                if (option.data[i] != "") {
                    num.push(option.data[i])
                }
            }
 
            //data.field.HOrgID = sessionStorage["OrganizationID"];//组织
            //var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"] + '&和' + saveType;
            var index = layer.load();
 
            $.ajax({
                type: "POST",
                url: GetWEBURL() + "/Xt_User/Gy_UserCustomer_ImportByExcel_Save",
                async: true,
                data: { "sMainSub": sMainSub },
                dataType: "json",
                success: function (data) {
                    if (data.count == 1) {
                        layer.close(index);
                        layer.msg(data.Message);
                        option.data = null;
                        table.cache["mainTable"] = null;
                        table.render(option);
                    }
                    else {
                        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;
                }
            });
        }
        //#endregion
 
        //#region 数据校验
        function AllowLoadData() {
            //获取表格数据
            var data = table.cache["mainTable"];
 
            //判断表格是否有数据
            if (data == null || data == "") {
                layer.msg("无数据,请先导入数据!");
                return false;
            }
 
            //if (confirmBar == 0) {
            //    layer.msg("数据存在问题,请在修改数据后重新校验!");
            //    return false;
            //}
 
            //关键字重复校验
            var num = [];
            var temp = "";
            for (var i = 0; i < data.length; i++) {
                temp = data[i]["客户代码"] + "," + data[i]["组织代码"];
                if ($.inArray(temp, num) == -1) {
                    num.push(temp);
                } else {
                    layer.msg("第" + (i + 1) + "行,客户代码和组织代码存在重复记录!");
                    return false;
                }
            }
            return true;
        }
        //#endregion
 
        //#region 行内删除
        function set_GridDelete(obj) {
            var data = obj.data;
            var rowIndex = $(obj.tr).attr("data-index");
            if (obj.event === 'del') {
                layer.confirm('真的删除行吗?', function (index) {
                    console.log("索引为:" + rowIndex);
                    if (rowIndex === '0') {
                        layer.msg('首行无法删除!!!');
                    } else {
                        var oldData = option.data;
                        oldData.splice(obj.tr.data('index'), 1)
                        option.data = oldData;//将数据绑定到data上
                        table.render(option);
                        layer.close(index);
                    }
                });
            }
        }
        //#endregion
        //#endregion
    });
 
</script>