/** * date: * author: neeler */ //test data start // var data_getList = Mock.mock('/company/getList.htm', {code: 0, 'list|5-20': [{id: 'id', companyNo: 'companyNo', note: 'note', name: 'name'}], pages: 12}) // var data_doDel = Mock.mock('/company/delItem.htm', {code: 0, errmsg: 'errmsg'}) // var data_doSave = Mock.mock('/company/saveItem.htm', {code: 0, errmsg: 'errmsg'}) //test data end var YWDY = [{'name': '河南明泰铝业股份有限公司', 'code': '101'}, {'name': '河南明泰科技发展有限公司', 'code': '103'}, {'name': '郑州明泰实业有限公司', 'code': '102'}, {'name': '河南泰鸿新材料有限公司', 'code': '113'}, {'name': '河南明晟新材料科技有限公司', 'code': '111'}, {'name': '河南义瑞新材料科技有限公司', 'code': '114'}, ]; window.I = { PZ: 30, keyword: $('#keyword'), searchBtn: $('#searchBtn'), pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, keywordValue: $('#k').val(), newObj: $('#newObj'), modal: $('#modal'), save: $('#save') } var Obj = { id: 0, companyNo: '', name: '', note: '', hasSPR: false //has self pickup right } var ViewModel = function() { var self = this; self.o = ko.observable(ko.mapping.fromJS(Obj)); self.keyword = ko.observable(I.keywordValue); self.list = ko.observableArray(); //业务单元value self.yvList = ko.observableArray(); //业务单元 self.ywdyList=ko.observableArray(YWDY); self.edit = function(item) { doEdit(item); } self.del = function(item) { delConfirm(item); } } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); $(".chosen-select").chosen(); $("#dp_chosen").width(270); autoHeight(); doSearch(); pageInit(); }); function pageInit() { $('.table-responsive').scroll(function() { $('.th').css('top', $(this).scrollTop()); }) I.save.click(function(event) { if (valid()) { doSave(); } }); I.newObj.click(function(event) { vm.o(ko.mapping.fromJS(Obj)); vm.yvList.removeAll(); 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(); } }); } function doOpen() { var k = $.trim(vm.keyword()); getList(k, 0, I.PZ, 1); } function doSearch() { doOpen(); } function getList(keyword, page, pagesize, pages) { I._page = page; $.post('/company/getList.htm', { searchword: 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.hasSPR=ko.observable(val.hasSPR=='true'?true:false); val.ywdyNames =''; if(isList(val.ywList)){ for(var k=0;k 1) { $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ getList(keyword, num - 1, pagesize, 0); }); } } return; } }, 'json'); } function valid(){ var isValid = false; var iF = $('#form'); iF.validate({ rules: { 'companyNo': { required: true }, 'name': { required: true } }, messages: { 'companyNo': { required: '不能为空!' }, 'name': { required: '不能为空!' } }, 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)); vm.yvList.removeAll(); if(isList(item.ywList)){ $.each(item.ywList, function(index, val) { vm.yvList.push(val.code); }); } $('#dp').val(vm.yvList()).trigger("chosen:updated"); 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('/company/delItem.htm', {companyNo: item.companyNo}, 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); parent.showErrmsg('删除成功!'); return; } }, 'json'); } function doSave() { if (!I.AjaxSaveItem &&valid()) { I.AjaxSaveItem = true; I.save.prop('disabled', true); var o = ko.mapping.toJS(vm.o()); o.ywdyNos=vm.yvList().join(','); o.hasSPR = $('#hasSPR').prop('checked'); $.post('/company/saveItem.htm', o, function(data, textStatus, xhr) { I.AjaxSaveItem = false; I.save.prop('disabled', false); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { parent.showErrmsg('保存成功!'); I.modal.modal('hide'); getList($.trim(vm.keyword()), I._page, I.PZ, 1); return; } }, 'json'); } } function clearError() { $('#form input').removeClass('error'); $('#form .text-error').html(''); } function autoHeight() { $('.page-content').css('min-height', $(parent.window).height() - 117); $('.table-responsive').css('height', $(parent.window).height() - 217); }