Administrator
2023-04-19 40ec16bbb7c9d23df625aa31ae42ac36e901749d
提交 | 用户 | 时间
58d006 1 // 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: '铝箔分厂'}]});
A 2 // var data_changeLoginDepart = Mock.mock('/syslogin/changeLoginDepart.htm', {code: 0, })
3 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":"左侧菜单栏"}}])
4
5 window.G = {
6     CANEDITOBS: $('#CANEDITOBS').val(),
7     LOGINID: $('#LOGINID').val(),
8     loginId: $('#loginId').val(),
9     loginUserid: $('#loginUserid').val(),
10     loginCompanyNo: $('#loginCompanyNo').val(),
11     loginUsername: $('#loginUsername').val(),
12     loginLoginside: $('#loginLoginside').val(),
13     loginCompanyName: $('#loginCompanyName').val(),
14     loginWorkerName: $('#loginWorkerName').val(),
15     loginUtype: $('#loginUtype').val(),
16     isAdmin: $('#loginUtype').val() === 'admin',
17     hasFdRole: $('#loginFdUtype').val() === 'true' || $('#loginFdUtype').val() == true
18 }
19
20 $(function() {
21     window.vm = new ViewModel();
22     ko.applyBindings(vm);
23     getMenu();
24     autoHeight();
25     tmpInit();
26     // getAllDepart();
27     $('#sidebar').css('overflow-y', $('#sidebar').hasClass('menu-min') ? 'visible' : 'scroll');
28     var cc  =(new CalendarConverter).solar2lunar(new Date());
29     $('#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>');
30     $('#switchDepart').click(function (e) {
31         e.preventDefault();
32         $('#modal').modal('show');
33     });
34     $('#changeDepartBtn').click(function (e) {
35         e.preventDefault();
36         var needRefresh = $('.sysDepartBtn.btn-primary').text() != $.trim($('#sysDepartName').text());
37         var bianhao = $('.departBtn.btn-primary').attr('data-no');
38         var departName = $('.departBtn.btn-primary').text();
39         var isDefault = $('#objUsed').prop('checked');
40         changeLoginDepart(bianhao, isDefault, needRefresh, departName);
41     });
42 })
43
44 function changeLoginDepart(bianhao, isDefault, needRefresh, departName) {
45     $.post("/syslogin/changeLoginDepart.htm", {bianhao: bianhao, isDefault: isDefault},
46         function (data, textStatus, jqXHR) {
47             if (data.code >= 1) {
48                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
49                 return;
50             }
51             if (data.code == 0) {
52                 if (!needRefresh) {
53                     showErrmsg('切换成功!');
54                     $('#departNameText').text(departName);
55                     $('#modal').modal('hide');
56                 } else {
57                     window.open("/index.jsf", "_self");
58                 }
59                 return;
60             }
61         },
62         "json"
63     );
64 }
65
66 function getAllDepart() {
67     $.post("/enterprise/enterworker/getAllDepart.htm", {gonghao: $.trim($('#workerno').text())},
68         function (data, textStatus, jqXHR) {
69             if (data.code >= 1) {
70                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
71                 return;
72             }
73             if (data.code == 0) {
74                 var obj = {};
75                 if (isList(data.list)) {
76                     $.each(data.list, function (index, value) {
77                          if (!!obj[value.sdepartNo]) {
78                                 obj[value.sdepartNo].children.push(value);
79                          } else {
80                              obj[value.sdepartNo] = value;
81                              obj[value.sdepartNo].children = [];
82                              obj[value.sdepartNo].children.push(value);
83                          }
84                     });
85                 }
86                 for (attr in obj) {
87                     var a = {
88                         selected: ko.observable(false),
89                         sname: obj[attr].sdepartName,
90                         sno: obj[attr].sdepartNo,
91                         list: []
92                     };
93                     $.each(obj[attr].children, function (index, value) {
94                          a.list.push({
95                             selected: ko.observable(!index),
96                             name: value.departName,
97                             no: value.departNo
98                          })
99                     });
100                     vm.sysDepartList.push(a);
101                 }
102                 btnInit();
103                 return;
104             }
105         },
106         "json"
107     );
108 }
109
110 function btnInit() {
111     var sysDepartName = $.trim($('#sysDepartName').text());
112     var departName = $.trim($('#departName').text());
113     $.each($('.sysDepartBtn'), function (index, value) {
114          if ($(value).text() === sysDepartName) {
115              $(value).trigger('click');
116          }
117     });
118     $.each($('.departBtn'), function (index, value) {
119         if ($(value).text() === departName) {
120             $(value).trigger('click');
121         }
122    });
123 }
124
125 $.validator.addMethod("isPlateNumber",function(value,element){
126     var platenumber = /^[\u4e00-\u9fa5]{1}[A-Za-z]{1}[A-Za-z_0-9]{5,6}$/;
127     return this.optional(element) || platenumber.test(value);
128 },"请输入正确的车牌号!");
129
130 $.validator.addMethod("isPhone",function(value,element){
131     var mobile = /^[1][0-9]{10}$/;
132     return this.optional(element) || mobile.test(value);
133 },"请输入正确的手机号!");
134
135 var ViewModel = function() {
136     var self = this;
137     self.menuList = ko.observableArray();
138     self.sysDepartList = ko.observableArray();
139     self.departList = ko.observableArray();
140
141     self.setSysDepart = function (item) {
142         $.each(self.sysDepartList(), function (index, value) {
143              value.selected(false);
144         });
145         item.selected(true);
146         self.departList(item.list);
147     }
148     self.setDepart = function (item) {
149         G._departNo = item.no;
150         $.each(self.departList(), function (index, value) {
151             value.selected(false);
152        });
153        item.selected(true);
154     }
155     self.isDefault = ko.observable(false);
156 }
157
158 function getMenu() {
159     $.post("/config/menu.json", {mtname:'lftmenus'},
160         function (data, textStatus, jqXHR) {
161        // console.log(data)
162             var arr = [];
163             if (isList(data)) {
164                 // $.each(data, function (index, value) {
165                 data.forEach( (value,index)=> {
166                     if (!G.isAdmin && !value.isOpen) {
167                         return true;
168                     }
169                     if (value.isFd) {
170                         if (!G.hasFdRole && !G.isAdmin)
171                           return true;
172                     }
173                     if (value.level == 1) {
174                         value.children = [];
175                         arr.push(value);
176                     }
177                     if (value.level == 2) {
178                         value.children = [];
179                         arr[arr.length - 1].children.push(value);
180                     }
181                     if (value.level == 3) {
182                         arr[arr.length - 1].children[arr[arr.length - 1].children.length - 1].children.push(value);
183                     }
184                 });
185                 vm.menuList(arr);
186                 $('#navList a[href != "javascript:;"]').click(function(){
187                     $('body,html').animate({scrollTop:0}, 500);
188                 });
189             }
190             navEvent();
191         },
192         "json"
193     );
194 }
195
196 if (!Array.prototype.indexOf){
197   Array.prototype.indexOf = function(elt /*, from*/){
198     var len = this.length >>> 0;
199
200     var from = Number(arguments[1]) || 0;
201     from = (from < 0)
202          ? Math.ceil(from)
203          : Math.floor(from);
204     if (from < 0)
205       from += len;
206
207     for (; from < len; from++){
208       if (from in this && this[from] === elt)
209         return from;
210     }
211     return -1;
212   };
213 }
214
215 function fullScreen() {
216     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)
217 }
218
219 function autoHeight() {
220     $('#sidebar').height($(window).height() - 45);
221     $('.tab-content').height($(window).height() - 117);
222     // $('.tab-content').height($(window).height() - 220);
223 }
224
225 $(window).resize(function() {
226     autoHeight();
227 })
228
229 function tmpInit() {
230     $('#sidebar-collapse').click(function (e) {
231         e.preventDefault();
232         $('#sidebar').css('overflow-y', $('#sidebar').hasClass('menu-min') ? 'scroll' : 'visible');
233     });
234 }