移动系统liao
2024-05-09 5d6cb15ac86d9174393cb9d1538d69b567e2c26c
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
<title>门店表</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
 
<!--当前位置结束-->
<style>
    #storeTable + .layui-table-view .layui-table-tool-temp { padding-right: 0; }
    #storeTable + .layui-table-view .layui-table-body tbody > tr td { cursor: pointer; }
    #storeTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click { background-color: #fff3e0; }
        #storeTable + .layui-table-view .layui-table-body tbody > tr.layui-table-click td:last-child > div:before { position: absolute; right: 6px; content: "\e602"; font-size: 12px; font-style: normal; font-family: layui-icon !important; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsStore/GetIndex" lay-done="layui.data.done(d);">
    <div class="layui-fluid" style="padding-bottom: 0;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <!-- 表格工具栏1 -->
                        <form class="layui-form coreshop-toolbar-search-form">
                            <div class="layui-form-item" style="margin-bottom: 10px;">
                                <input name="storeName" class="layui-input" placeholder="输入门店名称"
                                       style="max-width: 140px;display: inline-block;" />&emsp;
                                <button class="layui-btn layui-btn-sm icon-btn" lay-filter="dictTbSearch" lay-submit>
                                    <i class="layui-icon">&#xe615;</i>搜索
                                </button>
                            </div>
                        </form>
                        <!-- 数据表格1 -->
                        <table id="storeTable" lay-filter="storeTable"></table>
                    </div>
                </div>
            </div>
            <div class="layui-col-md9">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <!-- 表格工具栏2 -->
                        <form class="layui-form coreshop-toolbar-search-form">
                            <div class="layui-form-item" style="margin-bottom: 10px;">
                                <div class="layui-inline">
                                    <label class="layui-form-label">用户昵称:</label>
                                    <div class="layui-input-inline">
                                        <input name="nickName" class="layui-input" placeholder="输入用户昵称" />
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">手机号码:</label>
                                    <div class="layui-input-inline">
                                        <input name="mobile" class="layui-input" placeholder="输入用户手机号码" />
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    &emsp;
                                    <button class="layui-btn layui-btn-sm icon-btn" lay-filter="dictDataTbSearch" lay-submit>
                                        <i class="layui-icon">&#xe615;</i>搜索
                                    </button>
                                </div>
                            </div>
                        </form>
                        <!-- 数据表格2 -->
                        <table id="storeClerkTable" lay-filter="storeClerkTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>
 
<!-- 表格操作列 -->
<script type="text/html" id="storeClerkBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs"
       data-dropdown="#dictTbDelDrop{{d.LAY_NUM}}" no-shade="true">删除</a>
    <div class="dropdown-menu-nav dropdown-popconfirm dropdown-top-right layui-hide"
         id="dictTbDelDrop{{d.LAY_NUM}}"
         style="max-width: 200px;white-space: normal;min-width: auto;margin-left: 10px;">
        <div class="dropdown-anchor"></div>
        <div class="dropdown-popconfirm-title">
            <i class="layui-icon layui-icon-help"></i>
            确定要删除{{d.nickName}}吗?
        </div>
        <div class="dropdown-popconfirm-btn">
            <a class="layui-btn layui-btn-primary" btn-cancel>取消</a>
            <a class="layui-btn layui-btn-normal" lay-event="del">确定</a>
        </div>
    </div>
</script>
 
<script>
    var indexData;
    var debug = layui.setter.debug;
    var storeId;
    layui.data.done = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d); }
 
        indexData = d.data;
        layui.use(['index', 'table', 'laydate', 'util', 'coredropdown', 'coreHelper', 'tableX'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , tableX = layui.tableX
                    , view = layui.view;
 
                var selObj;  // 左表选中数据
 
                /* 渲染表格 */
                var insTb = table.render({
                    elem: '#storeTable',
                    url: layui.setter.apiUrl + 'Api/CoreCmsStore/GetPageList',
                    method: 'Post',
                    page: true,
                    height: 'full-175',
                    limit: 20,
                    toolbar: ['<p>',
                        '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
                        '<button lay-event="edit" class="layui-btn layui-btn-sm layui-btn-warm icon-btn"><i class="layui-icon">&#xe642;</i>修改</button>&nbsp;',
                        '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
                        '</p>'].join(''),
                    defaultToolbar: [],
                    cols: [[
                        { type: 'numbers' },
                        { field: 'id', title: '序列', width: 60 },
                        { field: 'storeName', title: '门店名称' },
                        {
                            field: 'isDefault', title: '是否默认', width: 80, sort: true, templet: function (d) {
                                if (d.isDefault) {
                                    return '<button type="button" class="layui-btn layui-btn-xs ">是</button>';
                                } else {
                                    return '<button type="button" class="layui-btn  layui-btn-xs  layui-btn-disabled">否</button>'
                                }
 
                            }
                        },
                    ]],
                    done: function (res, curr, count) {
                        $('#storeTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
                    }
                });
 
                /* 表格搜索 */
                form.on('submit(dictTbSearch)', function (data) {
                    insTb.reload({ where: data.field });
                    return false;
                });
 
                /* 表格头工具栏点击事件 */
                table.on('toolbar(storeTable)', function (obj) {
                    if (obj.event === 'add') { // 添加
                        doCreate();
                    } else if (obj.event === 'edit') { // 修改
                        doEdit(selObj);
                    } else if (obj.event === 'del') { // 删除
                        doDelete(selObj);
                    }
                });
 
                /* 监听行单击事件 */
                table.on('row(storeTable)', function (obj) {
                    selObj = obj;
                    storeId = obj.data.id;
                    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                    insTb2.reload({
                        where: { storeId: obj.data.id },
                        page: { curr: 1 },
                        url: layui.setter.apiUrl + 'Api/CoreCmsStore/GetClerkPageList'
                    });
                });
 
                //执行创建操作
                function doCreate() {
                    coreHelper.Post("Api/CoreCmsStore/GetCreate", null, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '创建门店数据',
                                area: ['380px', '600px'],
                                id: 'LAY-popup-CoreCmsStore-create',
                                success: function (layero, index) {
                                    view(this.id).render('shop/store/create', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsStore-createForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
                                                field.isDefault = field.isDefault == 'on';
 
                                                if (!!!field.areaId) {
                                                    layer.msg("请选择完整【门店地区】");
                                                    return false;
                                                }
 
                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后,关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsStore/DoCreate", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        insTb.reload();
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    });
                                    // 禁止弹窗出现滚动条
                                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsStore-createForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行编辑操作
                function doEdit(obj) {
                    coreHelper.Post("Api/CoreCmsStore/GetEdit", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '编辑门店',
                                area: ['380px', '630px'],
                                id: 'LAY-popup-CoreCmsStore-edit',
                                success: function (layero, index) {
                                    view(this.id).render('shop/store/edit', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsStore-editForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
                                                field.isDefault = field.isDefault == 'on';
 
                                                if (!!!field.areaId) {
                                                    layer.msg("请选择完整【门店地区】");
                                                    return false;
                                                }
 
                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后,关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsStore/DoEdit", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        insTb.reload();
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                    // 禁止弹窗出现滚动条
                                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsStore-editForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行单个删除
                function doDelete(obj) {
                    layer.confirm('确定删除吗?删除后将无法恢复。', function (index) {
                        coreHelper.Post("Api/CoreCmsStore/DoDelete", { id: obj.data.id }, function (e) {
                            if (debug) { console.log(e); } //开启调试返回数据
                            insTb.reload();
                            layer.msg(e.msg);
                        });
                    });
                }
 
                /* 渲染表格2 */
                var insTb2 = tableX.render({
                    elem: '#storeClerkTable',
                    method: 'Post',
                    height: 'full-175',
                    page: true,
                    toolbar: ['<p>',
                        '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
                        '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>&nbsp;',
                        '</p>'].join(''),
                    cellMinWidth: 100,
                    cols: [[
                        { type: 'checkbox' },
                        { type: 'numbers' },
                        { field: 'storeName', title: '门店名称', sort: false },
                        {
                            field: 'avatarImage', title: '头像', sort: false,
                            templet: function (d) {
                                if (d.avatarImage) {
                                    return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + d.avatarImage + '")><image style="max-width:28px;max-height:28px;" src="' + d.avatarImage + '" /></a>';
                                } else {
                                    return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                                }
                            }, width: 80
                        },
                        { field: 'nickName', title: '店员昵称', sort: false },
                        { field: 'mobile', title: '手机号码', sort: false },
                        { field: 'createTime', title: '关联时间', sort: false },
                        { title: '操作', toolbar: '#storeClerkBar', align: 'center', width: 120, minWidth: 120 }
                    ]]
                });
 
                /* 表格2搜索 */
                form.on('submit(dictDataTbSearch)', function (data) {
                    data.field.storeId = storeId;
                    insTb2.reload({
                        where: data.field,
                        page: { curr: 1 }
                    });
                    return false;
                });
 
                /* 表格2工具条点击事件 */
                table.on('tool(storeClerkTable)', function (obj) {
                    if (obj.event === 'edit') { // 修改
                        doEditData(obj);
                    } else if (obj.event === 'del') { // 删除
                        doDeleteData(obj);
                    }
                });
 
                /* 表格2头工具栏点击事件 */
                table.on('toolbar(storeClerkTable)', function (obj) {
                    if (obj.event === 'add') { // 添加
                        doCreateData();
                    } else if (obj.event === 'del') { // 删除
                        doBatchDeleteData();
                    }
                });
 
                //执行创建操作
                function doCreateData() {
                    coreHelper.Post("Api/CoreCmsStore/GetClerkCreate", null, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '创建用户数据',
                                area: ['380px', '200px'],
                                id: 'LAY-popup-CoreCmsStore-GetClerkCreate',
                                success: function (layero, index) {
                                    view(this.id).render('shop/store/clerkCreate', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsStore-clerkCreateForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
 
                                                field.deleted = field.deleted == 'on';
                                                field.storeId = selObj.data.id;
 
                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后,关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsStore/DoClerkCreate", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        insTb2.reload({ page: { curr: 1 } });
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    });
                                    // 禁止弹窗出现滚动条
                                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsStore-clerkCreateForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行编辑操作
                function doEditData(obj) {
                    coreHelper.Post("Api/CoreCmsStore/GetClerkEdit", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '编辑用户数据',
                                area: ['380px', '200px'],
                                id: 'LAY-popup-CoreCmsStore-clerkEdit',
                                success: function (layero, index) {
                                    view(this.id).render('shop/store/clerkedit', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsStore-clerkEdit-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
 
                                                field.deleted = field.deleted == 'on';
 
                                                if (debug) { console.log(field); } //开启调试返回数据
                                                //提交 Ajax 成功后,关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsStore/DoClerkEdit", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        insTb2.reload({ page: { curr: 1 } });
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                    // 禁止弹窗出现滚动条
                                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsStore-clerkEdit-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
 
                //执行批量删除
                function doBatchDeleteData() {
                    var checkRows = table.checkStatus('storeClerkTable');
                    if (checkRows.data.length === 0) {
                        layer.msg('请选择要删除的数据', { icon: 2, anim: 6 });
                        return;
                    }
                    var ids = checkRows.data.map(function (d) {
                        return d.id;
                    });
                    layer.confirm('确定删除吗?删除后将无法恢复。',
                        function (index) {
                            coreHelper.Post("Api/CoreCmsStore/DoClerkBatchDelete", { id: ids }, function (e) {
                                if (debug) { console.log(e); } //开启调试返回数据
                                insTb2.reload({ page: { curr: 1 } });
                                layer.msg(e.msg);
                            });
                        });
                }
 
                //执行单个删除
                function doDeleteData(obj) {
                    coreHelper.Post("Api/CoreCmsStore/DoClerkDelete", { id: obj.data.id }, function (e) {
                        if (debug) { console.log(e); } //开启调试返回数据
                        insTb2.reload({ page: { curr: 1 } });
                        layer.msg(e.msg);
                    });
                }
 
            });
    };
</script>