jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
var wmsAdmin = new Vue({
    el: '#wmsAdmin',
    mixins: [useAutoHeight],
    watch: {
        themeColor: function (val) {
            document.documentElement.style.setProperty("--theme-color", val);
            var $content = $('.admin-nav-card .layui-tab-content');
            $content.find('iframe').each(function () {
                var currentIframeDocument = $(this).context.contentDocument;
                if (currentIframeDocument) {
                    currentIframeDocument.documentElement.style.setProperty("--theme-color", val);
                }
            });
            this.setCookie("WmsThemeColor", val);
        }
    },
    data: {
        //默认颜色
        themeColor: "#3a93d4",
        //一级菜单数组
        firstMenu: [],
        //不包括一级菜单
        otherMenu: [],
        //当前选中菜单id
        currentId: "",
        //弹窗table列表属行初始化
        dialogList: {
            title: '',
            condition: '',
            show: false,
            itemCols: [],
            paging: true,
            url: null,
            data: {},
            height: 330,
            single: false,
            btnSure: function (selections) { }
        },
        dialogFrame: {
            title: '',
            show: false,
            url: '',
            dh: 0,
            height: "50%",
            width: "80%",
            btn: false,
            callBack: function (frame) { },
            cb: function () { }
        },
        //dialog列表为item时查询条件
        formItem: {
            itemCode: '',
            itemName: '',
            itemModel: '',
            itemFigureNo: ''
        },
        formCustomer: {
            customerName: ''
        },
        formVendor: {
            vendorName: ''
        },
        loading: null,
        pageSetList: [],
        pageSetReadOnly: []
    },
    computed: {
        dialogFrameHeight: function () {
            if (this.dialogFrame.dh == 0)
                return this.dialogFrame.height;
            return (this.autoHeight - this.dialogFrame.dh) + "px";
        }
    },
    methods: {
        updatePassword: function () {
            this.showDialogFrame({
                title: '修改密码',
                height: "160px",
                width: "400px",
                url: "../Home/UpdatePassword"
            });
        },
        setCookie: function (name, value) {//设置cookie,时间30天
            var days = 30;
            var expires = new Date();
            expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + expires.toGMTString();
        },
        getCookie: function (name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(name + "=")
                if (c_start != -1) {
                    c_start = c_start + name.length + 1
                    c_end = document.cookie.indexOf(";", c_start)
                    if (c_end == -1) c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return ""
        },
        loadingById: function (id) {
            var $this = this;
            var styles = getComputedStyle(document.documentElement);
            var value = styles.getPropertyValue("--theme-color");
            $(id).loading({
                loadingWidth: 120,
                title: '正在加载...',
                name: 'content',
                discription: '',
                direction: 'column',
                type: 'origin',
                originBg: value,
                originDivWidth: 40,
                originDivHeight: 40,
                originWidth: 6,
                originHeight: 6,
                smallLoading: false,
                titleColor: value,
                loadingBg: 'rgba(0,0,0,0)',
                //loadingMaskBg: 'rgba(0,0,0,0.1)'
            });
        },
        showWmsContentLoading: function () {
            this.loadingById('#_wmsContent');
        },
        closeLoading: function () {
            removeLoading('content');
        },
        showDialogFrame: function (options) {
            var $this = this;
            $this.loadingById('#_dialogFrame');
            $this.dialogFrame.btn = false;
            this.dialogFrame.dh = 0;
            $this.dialogFrame = $.extend($this.dialogFrame, options);
            if ($this.dialogFrame.url.indexOf("?") > 0) {
                $this.dialogFrame.url += ("&_t=" + (new Date()).valueOf());
            } else {
                $this.dialogFrame.url += ("?_t=" + (new Date()).valueOf());
            }
            $this.dialogFrame.cb = function () {
                if ($this.$refs.iframeDialog) {
                    $this.dialogFrame.callBack($this.$refs.iframeDialog.contentWindow);
                    $this.dialogFrame.show = false;
                }
            };
            $this.dialogFrame.show = true;
        },
        searchItem: function () {
            var $this = this;
            this.$refs.parentDialogList.pagingOptions.pageIndex = 1;
            var searchModel = {
                itemCode: $this.formItem.itemCode,
                itemName: $this.formItem.itemName,
                itemModel: $this.formItem.itemModel,
                itemFigureNo: $this.formItem.itemFigureNo
            };
            searchModel = $.extend(searchModel, $this.dialogList.data);
            this.$refs.parentDialogList.loadData(searchModel);
        },
        searchCustomer: function () {
            var $this = this;
            this.$refs.parentDialogList.pagingOptions.pageIndex = 1;
            var searchModel = {
                customerName: $this.formCustomer.customerName,
            };
            this.$refs.parentDialogList.loadData(searchModel);
        },
        searchVendor: function () {
            var $this = this;
            this.$refs.parentDialogList.pagingOptions.pageIndex = 1;
            var searchModel = {
                vendorName: $this.formVendor.vendorName,
            };
            this.$refs.parentDialogList.loadData(searchModel);
        },
        //退出登录
        exit: function () {
            this.confirm("确认退出登录吗?", function () {
                $.ajax({
                    type: 'GET',
                    async: false,
                    data: { endType: "hand" },
                    url: '/Home/Exit',
                    success: function (data) {
                        location.href = 'Login';
                    }
                });
            });
        },
        customConfirm: function (options) {
            var defaultOptions = {
                title: "提示",
                content: "",
                confirmText: "确定",
                cancelText: "取消",
                customClass: "",
                showConfirmButton: true,
                dangerouslyUseHTMLString: true,
                callback: function () { }
            };
            var option = $.extend(defaultOptions, options);
            this.$confirm(option.content, option.title, {
                dangerouslyUseHTMLString: option.dangerouslyUseHTMLString,
                confirmButtonText: option.confirmText,
                cancelButtonText: option.cancelText,
                showConfirmButton: option.showConfirmButton,
                customClass: option.customClass,
                callback: option.callback
            });
        },
        //确认框
        confirm: function (confirmMsg, then, catchEvent) {
            this.$confirm(confirmMsg, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(function () {
                if (then)
                    then();
            }).catch(function () {
                if (catchEvent)
                    catchEvent();
            });
        },
        //根据OperateResult实体弹出消息
        showMsg: function (data, successCallBack, errorCallBack, warningCallBack) {
            if (data) {
                if (data.Success) {
                    if (successCallBack)
                        successCallBack();
                    else {
                        this.success("保存成功");
                    }
                }
                else {
                    switch (data.Status) {
                        case 0:
                            this.error(data.Msg);
                            break;
                        case 2:
                            this.warning(data.Msg);
                            break;
                        default:
                            this.error(data.Msg);
                    }
                    if (errorCallBack)
                        errorCallBack();
                    if (warningCallBack)
                        warningCallBack();
                }
            } else
                this.error("系统错误");
        },
        //成功消息
        success: function (msg) {
            this.$message({
                showClose: true,
                message: msg,
                type: 'success'
            });
        },
        //警告消息
        warning: function (msg) {
            this.$message({
                showClose: true,
                message: msg,
                type: 'warning'
            });
        },
        //错误消息
        error: function (msg) {
            this.$message({
                showClose: true,
                message: msg,
                type: 'error'
            });
        },
        //弹窗table列表
        showDialogList: function (options) {
            var $this = this;
            //每次打开先清空上次选中
            this.formItem.itemCode = '';
            this.formItem.itemName = '';
            this.formItem.itemModel = '';
            this.formItem.itemFigureNo = '';
            this.formCustomer.customerName = '';
            this.formVendor.vendorName = '';
            if (options.url == $this.dialogList.url) {
                this.$refs.parentDialogList.pagingOptions.pageIndex = 1;
                this.$refs.parentDialogList.param = {};
                this.$refs.parentDialogList.loadData();
            }
            $this.dialogList.show = true;
            $this.dialogList.single = false;
            $this.dialogList.paging = true;
            $this.dialogList.condition = '';
            $this.dialogList.data = {};
            $this.dialogList = $.extend($this.dialogList, options);
        },
        //弹窗table列表确认事件
        dialogListBtnSure: function () {
            //dialog中选中的物料集合
            var selections = this.$refs.parentDialogList.selections;
            //调用确定回调函数
            this.dialogList.btnSure(selections);
            this.dialogList.show = false;
        },
        //id获取菜单
        getMenuById: function (id) {
            var menus = [];
            for (var i = 0; i < this.otherMenu.length; i++) {
                if (this.otherMenu[i].pId == id) {
                    var menuEntity = {
                        id: this.otherMenu[i].id,
                        title: this.otherMenu[i].name,
                        icon: this.otherMenu[i].iconSkin,
                        spread: false,
                        href: this.otherMenu[i].url
                    };
                    menus.push(menuEntity);
                }
            }
            return menus;
        },
        //获取当前菜单的所有子菜单
        getCurrentMenuChildren: function (menu) {
            var $this = this;
            var secondMenu = $this.getMenuById(menu.id);
            if (secondMenu.length > 0) secondMenu[0].spread = true;
            secondMenu.forEach(function (m) {
                m.children = $this.getMenuById(m.id);
            });
            return secondMenu;
        },
        //初始化菜单
        setNavbar: function (setMenu) {
            var currentSecondMenu = this.getCurrentMenuChildren(setMenu);
            navbar.set({
                spreadOne: true,
                elem: '#admin-navbar-side',
                cached: true,
                data: currentSecondMenu
            });
            //渲染navbar
            navbar.render();
            //监听点击事件
            navbar.on('click(side)', function (data) {
                tab.tabAdd(data.field);
            });
        },
        //一级菜单点击事件
        firstMenuClick: function (id) {
            var $this = this;
            $this.currentId = id;
            var currentMenu = null;
            $.each($this.firstMenu, function (i, n) {
                if (n.id == id) {
                    currentMenu = n;
                    n.open = true;
                } else n.open = false;
            });
            if (currentMenu)
                $this.setNavbar(currentMenu);
        },
        loadMenu: function () {//初始化菜单
            var $this = this;
            $.ajax({
                type: 'GET',
                async: false,
                url: '../Power/GetMenu',
                success: function (d) {
                    var d_json = (new Function("return " + d))();
                    var flag = true;
                    d_json.UserMenuList.forEach(function (m, n) {
                        var _menu = {
                            id: m.id,
                            name: m.name,
                            open: false,
                            pId: m.pId,
                            iconSkin: "&" + m.iconSkin,
                            url: m.url
                        };
                        if (m.pId == "-1") {
                            $this.firstMenu.push(_menu);
                            //默认选中第一个
                            if (flag) {
                                _menu.open = true;
                                flag = false;
                            }
                        } else
                            $this.otherMenu.push(_menu);
                    });
                },
                error: function (msg) {
                    $this.error("获取菜单异常!");
                }
            });
        },
        loadThemeColor: function () {
            var wmsThemeColor = this.getCookie("WmsThemeColor") || "#3a93d4";
            document.documentElement.style.setProperty("--theme-color", wmsThemeColor);
            this.themeColor = wmsThemeColor;
        },
        loadPageSetList: function () {
            var $this = this;
            if (this.pageSetList.length == 0) {
                $.ajax({
                    type: 'GET',
                    async: false,
                    dataType: 'json',
                    url: "/Sys/PageSet/GetPageSetList",
                    success: function (data) {
                        $this.showMsg(data, function () {
                            var readonlyData = Enumerable.From(data.Data).Where("x=>x.CN_B_READONLY").ToArray();
                            $this.pageSetReadOnly = readonlyData.map(function (n) {
                                return $.trim(n.CN_S_POWER_CODE);
                            });
                            $this.pageSetList = Enumerable.From(data.Data).Where("x=>!x.CN_B_READONLY").ToArray();
                        });
                    }
                });
            }
        }
    },
    //页面初始化
    mounted: function () {
        //初始化菜单
        this.loadMenu();
        //初始化主题颜色
        this.loadThemeColor();
        //初始化功能配置数据
        this.loadPageSetList();
    }
});