// 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('
农历' + cc.lunarMonth + '月' + cc.lunarDay + '
' + cc.sYear + '/' + (cc.sMonth < 10 ? '0' + cc.sMonth : cc.sMonth) + '/' + (cc.sDay < 10 ? '0' + cc.sDay : cc.sDay) + ' 星期' + cc.week + '
'); $('#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'); }); }