Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
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
// var data_getAllDepart = Mock.mock('/enterprise/enterworker/getAllDepart.htm', {code: 0, list: [{sysDepartNo: '01',sysDepartName: '河南明泰', departNo: '0105', departName: '企管部'}, {sysDepartNo: '01',sysDepartName: '河南明泰', departNo: '0103', departName: '河南明泰'}, {sysDepartNo: '02',sysDepartName: '高精板带', departNo: '0201', departName: '政务部'}, {sysDepartNo: '04',sysDepartName: '明泰科技', departNo: '0401', departName: '办公室'}, {sysDepartNo: '04',sysDepartName: '明泰科技', departNo: '0402', departName: '企管部'}, {sysDepartNo: '04',sysDepartName: '明泰科技', departNo: '040401', departName: '铝箔分厂'}]});
// var data_changeLoginDepart = Mock.mock('/syslogin/changeLoginDepart.htm', {code: 0, })
var data_getMenu = Mock.mock('/admin/bmenucon/ftmenu.htm', [{"id":108,"title":"基础数据","icon":"fa-th","url":"javascript:;","valid":true,"trget":null,"permission":0,"lft":243,"rgt":264,"level":1,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"运输公司管理","icon":null,"url":"/basic/company.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"车辆管理","icon":null,"url":"/basic/vehicle.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"人员管理","icon":null,"url":"/basic/user.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"销售分单","icon":null,"url":"/basic/formSplit.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"已分单列表","icon":null,"url":"/basic/doneForm.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"车辆任务列表","icon":null,"url":"/basic/vehicleTasks.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}},{"id":109,"title":"已完成装车","icon":null,"url":"/basic/doneList.jsf","valid":true,"trget":null,"permission":0,"lft":246,"rgt":247,"level":2,"ordering":0,"ctime":"2017-03-06","menutype":{"id":1,"title":"lftmenus","note":"左侧菜单栏"}}])
 
window.G = {
    CANEDITOBS: $('#CANEDITOBS').val(),
    LOGINID: $('#LOGINID').val(),
    loginId: $('#loginId').val(),
    loginUserid: $('#loginUserid').val(),
    loginCompanyNo: $('#loginCompanyNo').val(),
    loginUsername: $('#loginUsername').val(),
    loginLoginside: $('#loginLoginside').val(),
    loginCompanyName: $('#loginCompanyName').val(),
    loginWorkerName: $('#loginWorkerName').val(),
    loginUtype: $('#loginUtype').val(),
    isAdmin: $('#loginUtype').val() === 'admin',
    hasFdRole: $('#loginFdUtype').val() === 'true' || $('#loginFdUtype').val() == true
}
 
$(function() {
    window.vm = new ViewModel();
    ko.applyBindings(vm);
    getMenu();
    autoHeight();
    tmpInit();
    // getAllDepart();
    $('#sidebar').css('overflow-y', $('#sidebar').hasClass('menu-min') ? 'visible' : 'scroll');
    var cc  =(new CalendarConverter).solar2lunar(new Date());
    $('#lunarDate').html('<p class="nong">农历' + cc.lunarMonth + '月' + cc.lunarDay + '</p><p>' + cc.sYear + '/' + (cc.sMonth < 10 ? '0' + cc.sMonth : cc.sMonth) + '/' + (cc.sDay < 10 ? '0' + cc.sDay : cc.sDay) + ' 星期' + cc.week + '</p>');
    $('#switchDepart').click(function (e) {
        e.preventDefault();
        $('#modal').modal('show');
    });
    $('#changeDepartBtn').click(function (e) {
        e.preventDefault();
        var needRefresh = $('.sysDepartBtn.btn-primary').text() != $.trim($('#sysDepartName').text());
        var bianhao = $('.departBtn.btn-primary').attr('data-no');
        var departName = $('.departBtn.btn-primary').text();
        var isDefault = $('#objUsed').prop('checked');
        changeLoginDepart(bianhao, isDefault, needRefresh, departName);
    });
})
 
function changeLoginDepart(bianhao, isDefault, needRefresh, departName) {
    $.post("/syslogin/changeLoginDepart.htm", {bianhao: bianhao, isDefault: isDefault},
        function (data, textStatus, jqXHR) {
            if (data.code >= 1) {
                swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
                return;
            }
            if (data.code == 0) {
                if (!needRefresh) {
                    showErrmsg('切换成功!');
                    $('#departNameText').text(departName);
                    $('#modal').modal('hide');
                } else {
                    window.open("/index.jsf", "_self");
                }
                return;
            }
        },
        "json"
    );
}
 
function getAllDepart() {
    $.post("/enterprise/enterworker/getAllDepart.htm", {gonghao: $.trim($('#workerno').text())},
        function (data, textStatus, jqXHR) {
            if (data.code >= 1) {
                swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
                return;
            }
            if (data.code == 0) {
                var obj = {};
                if (isList(data.list)) {
                    $.each(data.list, function (index, value) {
                         if (!!obj[value.sdepartNo]) {
                                obj[value.sdepartNo].children.push(value);
                         } else {
                             obj[value.sdepartNo] = value;
                             obj[value.sdepartNo].children = [];
                             obj[value.sdepartNo].children.push(value);
                         }
                    });
                }
                for (attr in obj) {
                    var a = {
                        selected: ko.observable(false),
                        sname: obj[attr].sdepartName,
                        sno: obj[attr].sdepartNo,
                        list: []
                    };
                    $.each(obj[attr].children, function (index, value) {
                         a.list.push({
                            selected: ko.observable(!index),
                            name: value.departName,
                            no: value.departNo
                         })
                    });
                    vm.sysDepartList.push(a);
                }
                btnInit();
                return;
            }
        },
        "json"
    );
}
 
function btnInit() {
    var sysDepartName = $.trim($('#sysDepartName').text());
    var departName = $.trim($('#departName').text());
    $.each($('.sysDepartBtn'), function (index, value) {
         if ($(value).text() === sysDepartName) {
             $(value).trigger('click');
         }
    });
    $.each($('.departBtn'), function (index, value) {
        if ($(value).text() === departName) {
            $(value).trigger('click');
        }
   });
}
 
$.validator.addMethod("isPlateNumber",function(value,element){
    var platenumber = /^[\u4e00-\u9fa5]{1}[A-Za-z]{1}[A-Za-z_0-9]{5,6}$/;
    return this.optional(element) || platenumber.test(value);
},"请输入正确的车牌号!");
 
$.validator.addMethod("isPhone",function(value,element){
    var mobile = /^[1][0-9]{10}$/;
    return this.optional(element) || mobile.test(value);
},"请输入正确的手机号!");
 
var ViewModel = function() {
    var self = this;
    self.menuList = ko.observableArray();
    self.sysDepartList = ko.observableArray();
    self.departList = ko.observableArray();
 
    self.setSysDepart = function (item) {
        $.each(self.sysDepartList(), function (index, value) {
             value.selected(false);
        });
        item.selected(true);
        self.departList(item.list);
    }
    self.setDepart = function (item) {
        G._departNo = item.no;
        $.each(self.departList(), function (index, value) {
            value.selected(false);
       });
       item.selected(true);
    }
    self.isDefault = ko.observable(false);
}
 
function getMenu() {
    $.post("/config/menu.json", {mtname:'lftmenus'},
        function (data, textStatus, jqXHR) {
       // console.log(data)
            var arr = [];
            if (isList(data)) {
                // $.each(data, function (index, value) {
                data.forEach( (value,index)=> {
                    if (!G.isAdmin && !value.isOpen) {
                        return true;
                    }
                    if (value.isFd) {
                        if (!G.hasFdRole && !G.isAdmin)
                          return true;
                    }
                    if (value.level == 1) {
                        value.children = [];
                        arr.push(value);
                    }
                    if (value.level == 2) {
                        value.children = [];
                        arr[arr.length - 1].children.push(value);
                    }
                    if (value.level == 3) {
                        arr[arr.length - 1].children[arr[arr.length - 1].children.length - 1].children.push(value);
                    }
                });
                vm.menuList(arr);
                $('#navList a[href != "javascript:;"]').click(function(){
                    $('body,html').animate({scrollTop:0}, 500);
                });
            }
            navEvent();
        },
        "json"
    );
}
 
if (!Array.prototype.indexOf){
  Array.prototype.indexOf = function(elt /*, from*/){
    var len = this.length >>> 0;
 
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;
 
    for (; from < len; from++){
      if (from in this && this[from] === elt)
        return from;
    }
    return -1;
  };
}
 
function fullScreen() {
    document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement ? document.exitFullscreen ? document.exitFullscreen() : document.msExitFullscreen ? document.msExitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen && document.webkitExitFullscreen() : document.documentElement.requestFullscreen ? document.documentElement.requestFullscreen() : document.documentElement.msRequestFullscreen ? document.documentElement.msRequestFullscreen() : document.documentElement.mozRequestFullScreen ? document.documentElement.mozRequestFullScreen() : document.documentElement.webkitRequestFullscreen && document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)
}
 
function autoHeight() {
    $('#sidebar').height($(window).height() - 45);
    $('.tab-content').height($(window).height() - 117);
    // $('.tab-content').height($(window).height() - 220);
}
 
$(window).resize(function() {
    autoHeight();
})
 
function tmpInit() {
    $('#sidebar-collapse').click(function (e) {
        e.preventDefault();
        $('#sidebar').css('overflow-y', $('#sidebar').hasClass('menu-min') ? 'scroll' : 'visible');
    });
}