/** * date: * author: neeler */ //test data start // var data_getBizTypeList = Mock.mock('/basicinfo/businesstype/getList.htm', {code: 0, list: [{id: 22, processKey: 'asdfkjasdklfkj123', name: '人员来访短期', businesstypeNo: 'bn123123123', note: 'nnnn', candidateGroups: '12222candidateGroups22', planitem: true, factory: true, direct: 'inout',}, {id: 33, processKey: 'asdfkjasdklfkj123', name: '人员来访长期', businesstypeNo: 'bn222222', note: 'nnnn', candidateGroups: '12222candidateGroups22', planitem: true, factory: true, direct: 'inout',}], pages: 12}) // var data_getList = Mock.mock('/weight/gatesQueue/getList.htm', {code: 0, 'list|3-18': [{id: 3, name: 'nnnn1', sdID: 10, sdname: '企管部', countnum: 10, innernum: 7, outernum: 3}], pages: 12}) // var data_doDel = Mock.mock('/weight/gatesQueue/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) // var data_doSave = Mock.mock('/weight/gatesQueue/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) // var data_getList = Mock.mock('/basicconfig/gates/getList.htm', {code: 0, list: [{id: 1, gatesNo: '0001', name: '门禁1', cantruck: true, canperson: false, cancar: true, departname: '部门1', depart: 1}], pages: 12}) // var data_getGid = Mock.mock('/weight/gatesQueue/getGid.htm', {code: 0, item: 'bn123123123,bn222222' }) // var data_saveGid = Mock.mock('/weight/gatesQueue/saveGid.htm', {code: 0 }) //test data end window.I = { PZ: 30, keyword: $('#keyword'), searchBtn: $('#searchBtn'), pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, keywordValue: $('#k').val(), newObj: $('#newObj'), modal: $('#modal'), save: $('#save'), gatesModal: $('#gatesModal'), saveGid: $('#saveGid') } var Obj = { id: 0, name: '', sdID: '', sdname: '', countnum: 0, innernum: 0, outernum: 0, gatesNo: '' } var ViewModel = function() { var self = this; self.o = ko.observable(ko.mapping.fromJS(Obj)); self.keyword = ko.observable(I.keywordValue); self.list = ko.observableArray(); self.edit = function(item) { doEdit(item); } self.del = function(item) { delConfirm(item); } self.used = function (item) { doUsed(item); } self.gates = function(item) { setGates(item); } self.gList = ko.observableArray(); self.rList = ko.observableArray(); self.dList = ko.observableArray(); self.gatesList = ko.observableArray(); } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); getBizTypeList(); getDepartList(); getGatesList(); pageInit(); }); function pageInit() { I.saveGid.click(function (e) { e.preventDefault(); saveGid(); }); I.save.click(function(event) { if (valid()) { doSave(); } }); I.newObj.click(function(event) { vm.o(ko.mapping.fromJS(Obj)); I.modal.modal('show'); }); I.searchBtn.click(function(event) { doOpen(); }); I.modal.on('hidden.bs.modal', function (e) { clearError(); }); I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { if (event.keyCode == 13) { doOpen(); } }); I.gatesModal.on('hidden.bs.modal', function (e) { vm.rList.removeAll(); }); } function setGates(item) { getGid(item.id); $('#dp').val(vm.rList()).trigger("chosen:updated"); I.gatesModal.modal('show'); } function getGid(sid) { I._sid = sid; $.post("/weight/gatesQueue/getGid.htm", {gqID: sid}, function (data, textStatus, jqXHR) { if (data.code >= 1) { // parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (data.item) { vm.rList(data.item.split(',')); } else { vm.rList([]); } $('#dp').val(vm.rList()).trigger("chosen:updated"); return; } }, "json" ); } function saveGid() { $.post("/weight/gatesQueue/saveGid.htm", {gqID: I._sid, businesstypeNos: vm.rList().join(',')}, function (data, textStatus, jqXHR) { if (data.code >= 1) { // parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { parent.showErrmsg('保存成功!'); return; } }, "json" ); } function doOpen() { var k = $.trim(vm.keyword()); k = !!k ? '?keyword=' + k : ''; window.open('gatesQueue.jsf' + k, '_self'); } function doSearch() { getList(vm.keyword(), I.pageValue, I.PZ, 1); } function getList(keyword, page, pagesize, pages) { $.post('/weight/gatesQueue/getList.htm', { keyword: keyword, page: page, pagesize: pagesize, pages: pages }, function(data, textStatus, xhr) { vm.list.removeAll(); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function(index, val) { val.used = ko.observable(val.used); vm.list.push(val); }); } if (!!pages) { pages = data.pages; $('#pagdiv').unbind('page').empty(); if (pages > 1) { $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; window.open('gatesQueue.jsf?page=' + num + k, '_self'); }); } } return; } }, 'json'); } function valid(){ var isValid = false; var iF = $('#form'); iF.validate({ rules: { 'name': { required: true }, 'countnum': { required: true, digits: true }, 'innernum': { required: true, digits: true }, 'outernum': { required: true, digits: true } }, messages: { 'name': { required: '不能为空!' }, 'countnum': { required: '不能为空!', digits: '必须为整数!' }, 'innernum': { required: '不能为空!', digits: '必须为整数!' }, 'outernum': { required: '不能为空!', digits: '必须为整数!' } }, errorPlacement: function (err, element) { var p = element.parents('.form-group').eq(0); var d = p.find('.text-error').eq(0); d.css('color', '#D9534F'); err.appendTo(d); } }) isValid = iF.valid(); return isValid; } function doEdit(item) { vm.o(ko.mapping.fromJS(item)); I.modal.modal('show'); } function delConfirm(item) { $("#modalContent").html('确定要删除【' + item.name + '】吗?'); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "
", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ { html: " 确定", "class" : "btn btn-danger btn-minier", click: function() { $( this ).dialog( "close" ); doDel(item); } } , { html: " 取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); } function doDel(item) { if (!!I.AjaxDelItem) return; I.AjaxDelItem = true; $.post('/weight/gatesQueue/delItem.htm', {id: item.id}, function(data, textStatus, xhr) { I.AjaxDelItem = false; if (data.code >= 1) { // parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { vm.list.remove(item); location.replace(location.href); return; } }, 'json'); } function doSave() { if (!I.AjaxSaveItem &&valid()) { I.AjaxSaveItem = true; var o = ko.mapping.toJS(vm.o()); delete o.sdname; $.post('/weight/gatesQueue/saveItem.htm', o, function(data, textStatus, xhr) { I.AjaxSaveItem = false; if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { location.replace(location.href); return; } }, 'json'); } } function clearError() { $('#form input').removeClass('error'); $('#form .text-error').html(''); } function doUsed(item) { return; if (!I.AjaxChangeUsed) { var used = !item.used(); I.AjaxChangeUsed = true; $.post('/basicconfig/company/changeUsed.htm', {id: item.id, used: used}, function(data, textStatus, xhr) { I.AjaxChangeUsed = false; if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { item.used(used); return; } }, 'json'); } } function getBizTypeList(keyword, page, pagesize, pages) { $.post('/basicinfo/businesstype/getList.htm', { keyword: keyword, page: page, pagesize: pagesize, pages: pages }, function(data, textStatus, xhr) { vm.gList.removeAll(); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function(index, val) { vm.gList.push(val); }); $('.chosen-select').chosen({search_contains: true}); } return; } }, 'json'); } function getDepartList(keyword, page, pagesize, pages) { $.post('/enterprise/depart/getList.htm', { keyword: keyword, page: page, pagesize: pagesize, pages: pages }, function(data, textStatus, xhr) { vm.dList.removeAll(); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function (indexInArray, valueOfElement) { vm.dList.push(valueOfElement); }); } return; } }, 'json'); } function getGatesList() { $.post('/basicconfig/gates/getList.htm', { keyword: null, depart: null, page: 0, pagesize: null, pages: 0 }, function(data, textStatus, xhr) { vm.gatesList.removeAll(); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function(index, val) { vm.gatesList.push(val); }); // $('.chosen-select').chosen({search_contains: true}); } doSearch(); return; } }, 'json'); }