中扬CRM客户关系管理系统
#
lsh
2024-04-15 13a34d2197b001799ef8f0f09e5b48af2add0926
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
var pageCurr;
var pageCount = 0;
var treeCond;
var admin;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).extend({
    cascader: 'cascader/cascader',
}).use(['table','laydate', 'form', 'admin', 'xmSelect', 'element', 'cascader', 'tree', 'dropdown'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    admin = layui.admin;
    var xmSelect = layui.xmSelect;
    var cascader = layui.cascader;
    var tree = layui.tree;
    var dropdown = layui.dropdown;
 
    $('#organization').html(localStorage.getItem('nickname') + ' <i class="layui-icon">&#xe61a;</i>');
 
    // 部门人员 筛选
    dropdown.render({
        elem: '#organization'
        ,content: ['<div id="organizationTree" style="height: calc(100vh - 525px);border: none"></div>'].join('')
        ,style: 'width: 370px; height: 350px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
        ,ready: function(){
            loadTree();
        }
    });
 
    // 数据同步
    dropdown.render({
        elem: '#data-btn'
        ,align: 'right'
        ,style: 'border-radius: 5px;'
        ,className: 'site-dropdown-demo'
        ,data: [
            {
                title: '模板下载'
                ,templet: '<i class="layui-icon layui-icon-template-1"></i>{{d.title}}'
                ,id: 1
            },
            {
                title: '导入 Excel'
                ,templet: '<i class="layui-icon layui-icon-upload"></i>{{d.title}}'
                ,id: 2
            },
            {type: '-'}, //分割线
            {
                title: '导出 Excel'
                ,templet: '<i class="layui-icon layui-icon-export"></i>{{d.title}}'
                ,id: 3
            }
        ]
        ,click: async function(item){
            switch (item.id) {
                case 1:
                    // 模板下载
                    layer.load(1, {shade: [0.1,'#fff']});
                    location.href = baseUrl + "/mould/客户信息导入模板.xls";
                    layer.closeAll('loading');
                    break
                case 2:
                    // 导入 Excel
                    $("#importExcel").trigger("click");
                    // let arrFileHandle = await window.showOpenFilePicker()
                    // let file = await arrFileHandle[0].getFile();
                    // upload(file);
                    break
                case 3:
                    // 导出 Excel
                    layer.msg("来不及做,等等", {icon: 6});
                    break
                default:
                    break
            }
        }
    });
 
    // 树形图
    var organizationTree;
    window.loadTree = function(followerName,conditionName,condition){
        var loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl+"/dept/user/tree/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                'followerName' : followerName,
                'conditionName' : conditionName,
                'condition' : condition
            },
            method: 'POST',
            success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200){
                    organizationTree = tree.render({
                        elem: '#organizationTree',
                        id: 'organizationTree',
                        onlyIconControl: true,
                        data: res.data,
                        click: function (obj) {
                            treeCond = {
                                key: obj.data.key,
                                val: obj.data.id
                            }
                            $('#organization').html(obj.data.title + ' <i class="layui-icon">&#xe61a;</i>');
                            $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                            $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                            clearFormVal($('#search-box'));
                            tableIns.reload({
                                where: {[obj.data.key]: obj.data.id},
                                page: {curr: 1}
                            });
                        }
                    });
                    treeData = res.data;
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }
 
    // 数据渲染
    tableIns = table.render({
        elem: '#cstmr',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/cstmr2/page/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        // cellMinWidth: 100,
        height: 'full-148',
        // size: 'sm',
        skin: 'line',
        cols: [[
            // {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: 'ID'}
            // ,{field: 'hostId$', align: 'center',title: '所属商户'},
            {field: 'name', align: 'left',title: '客户名称', style: 'color: #1890ff;cursor:pointer', event: 'more', width: 350}
            ,{field: 'simple', align: 'left',title: '客户简称', hide: true}
            ,{field: 'uuid', align: 'left',title: '客户代号', hide: false}
            ,{field: 'addr', align: 'left',title: '详细地址', hide: false, templet:function(d){return emptyShow(d.addr)}}
            ,{field: 'tel', align: 'left',title: '电话', hide: false, templet:function(d){return emptyShow(d.tel)}}
            ,{field: 'weeklyDailyReality', align: 'center',title: '行程',hide : false, toolbar: '#tbLookReality'}
            ,{field: 'remarks', align: 'left',title: '备注', hide: false, templet:function(d){return emptyShow(d.remarks)}}
            ,{field: 'cstmrType$', align: 'left',title: '客户类别', hide: false}
            ,{field: 'cstmrGrade$', align: 'left',title: '客户等级', hide: false}
            ,{field: 'industry', align: 'left',title: '客户行业', hide: false}
            ,{field: 'productCategory', align: 'left',title: '产品类型', hide: false}
            ,{field: 'userId$', align: 'left',title: '添加人员', hide: true}
            ,{field: 'createTime$', align: 'left',title: '添加时间', hide: false}
            ,{field: 'deptId$', align: 'left',title: '所属部门', hide: true}
            ,{field: 'rela', align: 'left',title: '客户关系', hide: true}
            ,{field: 'contacts', align: 'left',title: '客户联系人', hide: true}
            ,{field: 'director$', align: 'left',title: '负责人', hide: false}
            ,{field: 'province', align: 'left',title: '省', hide: true}
            ,{field: 'city', align: 'left',title: '市', hide: true}
            ,{field: 'district', align: 'left',title: '县', hide: true}
            ,{field: 'town', align: 'left',title: '镇', hide: true}
            ,{field: 'type$', align: 'left',title: '区分', hide: true}
            ,{field: 'files', align: 'left',title: '附件', hide: true}
            ,{field: 'status$', align: 'left',title: '状态', hide: true}
            // ,{field: 'createBy$', align: 'center',title: '添加人员', hide: true}
            ,{field: 'updateBy$', align: 'left',title: '修改人员', hide: true}
            ,{field: 'updateTime$', align: 'left',title: '修改时间', hide: true}
            ,{field: 'memo', align: 'left',title: '注释', hide: true}
 
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            pageCount = count;
            limit();
        }
    });
 
    // 添加
    $("#cstmrAddBtn1").click(function () {
        form.verify({
            account: function(value, item){
                var min = item.getAttribute('lay-min');
                if(value.length < min){
                    return '客户名称不能小于'+min+'个字符的长度';
                }
            }
        });
        showEditModel2();
    });
 
    // 添加
    $("#cstmrAddBtn").click(function () {
        form.verify({
            account: function(value, item){
                var min = item.getAttribute('lay-min');
                if(value.length < min){
                    return '客户名称不能小于'+min+'个字符的长度';
                }
            }
        });
        showEditModel();
    });
 
    // 删除
    form.on('submit(cstmrDel)', function (data) {
        let checkStatus = layui.table.checkStatus('cstmr').data;
        if (checkStatus.length === 0) {
            layer.msg('请选择要删除的数据', {icon: 2});
            return;
        }
        del(checkStatus.map(function (d) {
            return d.id;
        }));
    });
 
    // 监听排序事件
    table.on('sort(cstmr)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
 
    // 监听行工具事件
    table.on('tool(cstmr)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'more':
                top.cstmrByMore = data.id;
                admin.popupRight({
                    type: 1,
                    window: "top",
                    area: "1250px",
                    url: "cstmr_more.html",
                    end: function () {
                        // $(".layui-laypage-btn")[0].click();
                    }
                })
                break;
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
            case "lookReality":
                var $a = $(obj.tr).find('a[lay-event="lookReality"]');
                var offset = $a.offset();
                var top2 = offset.top;
                var left = offset.left;
                layer.open({
                    type: 1,
                    title: false,
                    area: '1100px',
                    offset: [top2 + 'px', (left - 830 + $a.outerWidth()) + 'px'],
                    shade: .01,
                    shadeClose: true,
                    fixed: false,
                    content: '<table id="lookSSXMTable" lay-filter="lookSSXMTable"></table>',
                    success: function (layero) {
                        table.render({
                            elem: '#lookSSXMTable',
                            headers: {token: localStorage.getItem('token')},
                            url: baseUrl+'/weeklyDailyReality/list/auth',
                            where: {
                                cstmr_id: data.id
                            },
                            page: true,
                            cellMinWidth: 100,
                            cols: [[
                                {type: 'numbers'}
                                // ,{field: 'weeklyDay$', align: 'center',title: '星期'}
                                ,{field: 'dailyTime$',width : 120, align: 'center',title: '日期'}
                                ,{field: 'workContent', align: 'center', title: '工作内容及目的', edit:false}
                                // ,{field: 'workPurpose', title: '工作目的', edit:false}
                                ,{field: 'comment', title: '评论', edit:false}
                                ,{field: 'weeklyMatter', title: '需协助事项',  edit:false}
                                // ,{field: 'dailyTime$', align: 'center',title: '日报日期'}
                                // ,{field: 'settleMsg', align: 'center',title: '审核进度'}
                                ,{field: 'director$', align: 'center',title: '负责人'}
                                // ,{field: 'settleSize', align: 'center',title: '流程长度'}
                                // ,{field: 'settleCurrent', align: 'center',title: '当前进度'}
                                // ,{field: 'cstmrId', align: 'center',title: '甲方单位ID'}//, templet: function () { return htmlCstme;}
                                ,{field: 'memo', align: 'center',title: '备注',   edit:false}
                            ]],
                            request: {
                                pageName: 'curr',
                                pageSize: 'limit'
                            },
                            parseData: function (res) {
                                return {
                                    'code': res.code,
                                    'msg': res.msg,
                                    'count': res.data.total,
                                    'data': res.data.records
                                }
                            },
                            response: {
                                statusCode: 200
                            },
                            done: function () {
                                $(layero).find('.layui-table-view').css('margin', '0');
                            },
                            size: ''
                        });
                    }
                });
                break;
        }
    });
 
    /* 弹窗 - 新增、修改 */
    function showEditModel(data) {
        if (data) {//修改
            console.log(data)
            showEditModel2(data);
        }else {
            showEditModel1();
        }
    }
 
    function showEditModel1(mData) {
        admin.open({
            type: 1,
            area: '1500px',
            title: (mData ? '修改' : '添加') + '客户信息',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                let loadNameXml = loadNameXmlSel()
                let method = mData?'update':'add';
                if (mData) {
                    $('#cascaderVal').val(mData.pcd);
                    if (mData.name) { loadNameXml.setValue([{name: mData.name, value: mData.name}]); }
                }
                if (method === 'update'){
                    var directorNone = document.getElementById("directorNone");
                    directorNone.style.display = "block";
                }
                form.verify({
                    name: function(value, item){
                        var min = item.getAttribute('lay-min');
                        if(value.length < min){
                            return '客户名称不能小于'+min+'个字符的长度';
                        }
                    }
                });
                if (mData) {
                    $('#cascaderVal').val(mData.pcd);
                }
                layDateRender(mData);
                cascaderRender();
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    data.field.name = loadNameXml.getValue()[0] ? loadNameXml.getValue()[0].name : null;
                    //将公司数据全部返回
                    companyData = loadNameXml.getValue()[0] ? loadNameXml.getValue()[0].value : null;//将公司数据全部返回
                    if (companyData != null) {
                        data.field.creditCode = companyData.creditCode
                        data.field.issueTime = companyData.issueTime
                        data.field.companyType = companyData.companyType
                        data.field.companyPerson = companyData.companyPerson
                        data.field.companyStatus = companyData.companyStatus
                        data.field.regMoney = companyData.regMoney
                    }
 
                    if (!data.field.name) {
                        layer.msg("客户名称不能为空", {icon: 2});
                        return false;
                    }
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/cstmr2/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload()
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        });
    }
 
    /* 弹窗 - 新增、修改 */
    function showEditModel2(mData) {
        admin.open({
            type: 1,
            area: '1500px',
            title: (mData ? '修改' : '添加') + '客户信息',
            content: $('#editDialog2').html(),
            success: function (layero, dIndex) {
                let loadNameXml = loadNameXmlSel2()
                let method = mData?'update':'add';
                if (mData) {
                    $('#cascaderVal').val(mData.pcd);
                    if (mData.name) { loadNameXml.setValue([{name: mData.name, value: mData.name}]); }
                }
                if (method === 'update'){
                    var directorNone = document.getElementById("directorNone");
                    directorNone.style.display = "block";
                }
                form.verify({
                    name: function(value, item){
                        var min = item.getAttribute('lay-min');
                        if(value.length < min){
                            return '客户名称不能小于'+min+'个字符的长度';
                        }
                    }
                });
                if (mData) {
                    $('#cascaderVal').val(mData.pcd);
                }
                layDateRender(mData);
                cascaderRender();
                form.val('detail2', mData);
                form.on('submit(editSubmit2)', function (data) {
                    data.field.name = loadNameXml.getValue()[0] ? loadNameXml.getValue()[0].name : null;
                    //将公司数据全部返回
                    companyData = loadNameXml.getValue()[0] ? loadNameXml.getValue()[0].value : null;//将公司数据全部返回
                    if (companyData != null) {
                        data.field.creditCode = companyData.creditCode
                        data.field.issueTime = companyData.issueTime
                        data.field.companyType = companyData.companyType
                        data.field.companyPerson = companyData.companyPerson
                        data.field.companyStatus = companyData.companyStatus
                        data.field.regMoney = companyData.regMoney
                    }
 
                    if (!data.field.name) {
                        layer.msg("客户名称不能为空", {icon: 2});
                        return false;
                    }
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/cstmr/"+(mData?'update':'add2')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload()
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        });
    }
 
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl+"/cstmr/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
        });
    }
 
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        pageCount = 0;
        tableReload();
    });
 
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
 
        }, 300);
    }
    layDateRender();
 
    // 省市区选择
    function cascaderRender() {
        cascader.render({
            elem: '#cascaderVal',
            data: citysData,
            itemHeight: '250px',
            filterable: true,
            onChange: function (values, data) {
                // console.log(values);console.log(data);
            }
        });
    }
 
    window.loadNameXmlSel = function () {
        return xmSelect.render({
            el: '#nameXmlSel',
            autoRow: true,
            filterable: true,
            remoteSearch: true,
            clickClose: true,
            radio: true,
            remoteMethod: function (val, cb, show) {
                $.ajax({
                    url: baseUrl + "/cstmr2/all/get/kv",
                    headers: {'token': localStorage.getItem('token')},
                    data: {
                        condition: val
                    },
                    method: 'POST',
                    success: function (res) {
                        if (res.code === 200) {
                            cb(res.data)
                        } else {
                            cb([]);
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                });
            },
            // on: function (data) {
            //     console.log(data)
            //     let arr = data.arr
            //     let change = data.change;
            //     if (arr.length > 0 && change.length>0) {
            //         let name = arr[0].name;
            //         $.ajax({
            //             url: baseUrl + "/cstmr/name/check/auth",
            //             headers: {'token': localStorage.getItem('token')},
            //             data: {
            //                 name: name
            //             },
            //             method: 'POST',
            //             success: function (res) {
            //                 if (res.code === 200) {
            //                 } else {
            //                     layer.msg(res.msg, {icon: 2});
            //                 }
            //             }
            //         });
            //     }
            // }
        });
    }
 
    window.loadNameXmlSel2 = function () {
        return xmSelect.render({
            el: '#nameXmlSel2',
            autoRow: true,
            filterable: true,
            remoteSearch: true,
            clickClose: true,
            radio: true,
            remoteMethod: function (val, cb, show) {
                $.ajax({
                    url: baseUrl + "/cstmrSearch/auth",
                    headers: {'token': localStorage.getItem('token')},
                    data: {
                        condition: val
                    },
                    method: 'POST',
                    success: function (res) {
                        if (res.code === 200) {
                            cb(res.data)
                        } else {
                            cb([]);
                            layer.msg(res.msg, {icon: 2});
                        }
                    }
                });
            },
            on: function (data) {
                console.log(data)
                let arr = data.arr
                let change = data.change;
                if (arr.length > 0 && change.length>0) {
                    let name = arr[0].name;
                    $.ajax({
                        url: baseUrl + "/cstmr/name/check/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: {
                            name: name
                        },
                        method: 'POST',
                        success: function (res) {
                            if (res.code === 200) {
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    });
                }
            }
        });
    }
 
});
 
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
 
function tableReload() {
    if (pageCount === 0) {
        let searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        if (treeCond) {
            searchData[treeCond.key] = treeCond.val;
        }
        tableIns.reload({
            where: searchData,
            page: {curr: pageCurr}
        });
    } else {
        $(".layui-laypage-btn")[0].click();
    }
}
 
function upload(obj){
    if(!obj.files) {
        return;
    }
    var file = obj.files[0];
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
        layer.load(1, {shade: [0.1,'#fff']});
        var url = baseUrl + "/cstmr/excel/import/auth";
        var form = new FormData();
        form.append("file", file);
        let xhr = new XMLHttpRequest();
        xhr.open("post", url, true);
        xhr.setRequestHeader('token', localStorage.getItem('token'));
        xhr.onload = uploadComplete;
        xhr.onerror =  uploadFailed;
        xhr.onloadend = function () {
            layer.closeAll('loading');
        };
        // xhr.upload.onprogress = progressFunction;
        xhr.upload.onloadstart = function(){
            ot = new Date().getTime();
            oloaded = 0;
        };
        xhr.send(form);
    }, function(index){
    });
}
function uploadComplete(evt) {
    let res = JSON.parse(evt.target.responseText);
    if(res.code === 200) {
        layer.msg(res.msg, {icon: 1});
        tableReload();
    } else {
        alert(res.msg);
        // layer.msg(res.msg, {icon: 2});
    }
}
function uploadFailed(evt) {
    let res = JSON.parse(evt.target.responseText);
    alert(res.msg);
    // layer.msg(res.msg, {icon: 2});
}