/** * date: * author: neeler */ //test data start // var data_getList = Mock.mock('/basicconfig/prefix/getList.htm', {code: 0, 'list|3-20': [ // {id: 1,title: '名称',prefix: 'OP',surfix: 'ED',bitnum: 10,leveling: 2,currents: 'OP012345ED', note: 'nnnnnote'} // ], pages: 12}) // var data_doDel = Mock.mock('/basicconfig/prefix/delItem.htm', {code: 0, errmsg: '删除失败!'}) // var data_doSave = Mock.mock('/basicconfig/prefix/saveItem.htm', {code: 0, errmsg: '保存失败!'}) //test data end var TITLE = [{name: '往来单位', value: 'company'}, {name: '人员来访', value: 'persionvisit'}, {name: '门禁编号', value: 'gates'}, {name: '发卡点', value: 'cardplace'}, {name: '卡编号', value: 'card'}, {name: '物资', value: 'materiel'}, {name: '设备', value: 'cequipment'}, {name: '客户端', value: 'mclient'}, {name: '员工', value: 'ewer'}, {name: '部门', value: 'depart'}, {name: '长期卡', value: 'longvisit'}, {name: '携带物资', value: 'peoplematetialsheet'}, {name: '铝锭采购', value: 'albuy'}, {name: '铝锭退货', value: 'alback'}, {name: '装卸点', value: 'shipmentarea'}, {name: '现场记录', value: 'shipment'}, {name: '业务类型', value: 'businesstype'}, {name: '排队配置', value: 'gatesqueue'}, {name: '供应采购', value: 'materialbuy'}, {name: '供应退货', value: 'materialback'}, {name: '产品销售', value: 'productsale'}, {name: '产品退货', value: 'productback'}, {name: '外出维修出厂', value: 'fixout'}, {name: '外出维修入场', value: 'fixin'}, {name: '半成品内转出', value: 'inturnSemiOut'}, {name: '半成品内转人', value: 'inturnSemiIn'}, {name: '铝内转入', value: 'inturnAlIn'}, {name: '铝内转出', value: 'inturnAlOut'}, {name: '普通物资内转出', value: 'inturnMaterilOut'}, {name: '普通物资内转入', value: 'inturnMaterialIn'}, {name: '废旧物资处理', value: 'wasteProcess'}, {name: '其他运输出厂', value: 'materielOut'}, {name: '其他运输进厂', value: 'materielIn'}, {name: '来料加工', value: 'Machining'},{name: '废料采购', value: 'scrapPurchase'},{name: 'vehicleOMsheet', value: 'vehicleOMsheet'}]; 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, title: '', prefix: '', surfix: '', bitnum: '', leveling: 1, currents: '', note: '', } var Obj = { id: 0, name: '', title: '', prefix: '', surfix: '', datestr: true, lvl: true, concatupper: true, bitnum: '', leveling: '', currents: '', note: '', tablename: '', fieldname: '', } var ViewModel = function() { var self = this; self.keyword = ko.observable(I.keywordValue); self.list = ko.observableArray(); self.o = ko.observable(ko.mapping.fromJS(Obj)); self.edit = function(item) { doEdit(item); } self.del = function(item) { delConfirm(item); } self.tList = ko.observableArray(TITLE); } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); doSearch(); pageInit(); }); function pageInit() { I.save.click(function(event) { if (valid()) { doSave(); } }); I.searchBtn.click(function(event) { doOpen(); }); I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { if (event.keyCode == 13) { doOpen(); } }); I.newObj.click(function(event) { vm.o(ko.mapping.fromJS(Obj)); I.modal.modal('show'); }); I.modal.on('hidden.bs.modal', function (e) { clearError(); }); } function doOpen() { var k = $.trim(vm.keyword()); k = !!k ? '?keyword=' + k : ''; window.open('prefix.jsf' + k, '_self'); } function doSearch() { getList(vm.keyword(), I.pageValue, I.PZ, 1); } function getList(keyword, page, pagesize, pages) { $.post("/basicconfig/prefix/getList.htm", { keyword: keyword, page: page, pagesize: pagesize, pages: pages }, 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 (isList(data.list)) { $.each(data.list, function (indexInArray, valueOfElement) { // valueOfElement.title += indexInArray; valueOfElement.title ; vm.list.push(valueOfElement); }); } 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('prefix.jsf?page=' + num + k, '_self'); }); } } return; } }, "json" ); } function doEdit(item) { vm.o(ko.mapping.fromJS(item)); I.modal.modal('show'); } function delConfirm(item) { $("#modalContent").html('确定要删除【' + item.title + '】吗?'); $("#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('/basicconfig/prefix/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()); o.datestr = $('#objDatestr').prop('checked'); o.lvl = $('#objLvl').prop('checked'); o.concatupper = $('#objConcatupper').prop('checked'); $.post('/basicconfig/prefix/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 valid(){ var isValid = false; var iF = $('#form'); iF.validate({ rules: { 'name': { required: true }, // 'prefix': { // required: true // }, // 'surfix': { // required: true // }, 'bitnum': { required: true, digits: true, min: 1 } }, messages: { 'name': { required: '名称不能为空!' }, // 'prefix': { // required: '前缀不能为空!' // }, // 'surfix': { // required: '后缀不能为空!' // }, 'bitnum': { required: '位数不能为空!', digits: '必须为整数!', min: '必须大于0', } }, 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 clearError() { $('#form input').removeClass('error'); $('#form .text-error').html(''); }