Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 /**
A 2 * date: 
3 * author: neeler 
4 */
5
6 //test data start
7 // var data_getList = Mock.mock('/basicinfo/businesstype/getList.htm', {"rowCount":0,"pagesize":0,"pages":1,"page":0,"items":null,"list":[{"direct":"in","departname":null,"weighing":true,"companytype":0,"processKey":"business_process","planitem":false,"candidateGroups":"","departNo":null,"spNos":null,"id":2,"wuzis":"成品","name":"铝锭采购","factory":false,"rownumber":1,"businesstypeNo":"businesstype00001","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":3,"wuzis":null,"name":"产品销售","factory":false,"rownumber":2,"businesstypeNo":"businesstype00002","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":5,"wuzis":null,"name":"物资采购","factory":false,"rownumber":3,"businesstypeNo":"businesstype00003","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":6,"wuzis":null,"name":"物资采购退货","factory":false,"rownumber":4,"businesstypeNo":"businesstype00004","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":7,"wuzis":null,"name":"销售退货","factory":false,"rownumber":5,"businesstypeNo":"businesstype00005","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":8,"wuzis":null,"name":"外出维修出","factory":true,"rownumber":6,"businesstypeNo":"businesstype00006","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":9,"wuzis":null,"name":"外出维修入","factory":false,"rownumber":7,"businesstypeNo":"businesstype00007","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":12,"wuzis":null,"name":"内转半成品出","factory":false,"rownumber":8,"businesstypeNo":"businesstype00008","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":13,"wuzis":null,"name":"内转半成品入","factory":false,"rownumber":9,"businesstypeNo":"businesstype00009","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":14,"wuzis":null,"name":"内转木材出","factory":false,"rownumber":10,"businesstypeNo":"businesstype00010","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":15,"wuzis":null,"name":"内转木材入","factory":false,"rownumber":11,"businesstypeNo":"businesstype00011","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":16,"wuzis":null,"name":"铝废料内转出","factory":false,"rownumber":12,"businesstypeNo":"businesstype00014","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":17,"wuzis":null,"name":"铝废料内转入","factory":false,"rownumber":13,"businesstypeNo":"businesstype00015","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":18,"wuzis":null,"name":"废旧物资处理","factory":false,"rownumber":14,"businesstypeNo":"businesstype00016","note":null},{"direct":"out","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":19,"wuzis":null,"name":"内转外加工出","factory":false,"rownumber":15,"businesstypeNo":"businesstype00012","note":null},{"direct":"in","departname":null,"weighing":true,"companytype":null,"processKey":"business_process","planitem":true,"candidateGroups":"","departNo":null,"spNos":null,"id":20,"wuzis":null,"name":"内转外加工入","factory":false,"rownumber":16,"businesstypeNo":"businesstype00013","note":null}],"hint":null,"errmsg":null,"code":0})
8 // var data_doDel = Mock.mock('/basicinfo/businesstype/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
9 // var data_doSave = Mock.mock('/basicinfo/businesstype/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
10 //test data end
11
12 var DIRECT = [{name: '进厂', value: 'in'}, {name: '出厂', value: 'out'}]//, {name: '进出', value: 'inout'}
13 var directName = {in: '进厂', out: '出厂'}//inout: '进出'
14 var TYPE = ['成品', '半成品', '其他']// '原料', '辅料', '木料',
15 var COMPANYTYPE = ['厂外公司', '厂内部门', '内转厂部门']    //0 厂外公司,1 厂内部门  2  内转厂部门
16
17 window.I = {
18     PZ: 30,
19     keyword: $('#keyword'),
20     searchBtn: $('#searchBtn'),
21     pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0,
22     keywordValue: $('#k').val(),
23     newObj: $('#newObj'),
24     modal: $('#modal'),
25     save: $('#save'),
26     departModal: $('#departModal'),
27     departName: $('#departName'),
28     saveDepart: $('#saveDepart')
29 }
30
31 var Obj = {
32     id: '',
33     processKey: '',
34     name: '',
35     businesstypeNo: '',
36     note: '',
37     candidateGroups: '',
38     planitem: true,
39     factory: false,
40     direct: 'in',
41     weighing: true,
42     departNo: '',
43     spNos: '',
44     wuzis: TYPE[0],
45     companytype: COMPANYTYPE[0],
46     departname: ''
47 }
48
49 var ViewModel = function() {
50     var self = this;
51     self.o = ko.observable(ko.mapping.fromJS(Obj));
52
53     self.keyword = ko.observable(I.keywordValue);
54     self.list = ko.observableArray();
55     self.dList = ko.observableArray(DIRECT);
56     self.cList = ko.observableArray(COMPANYTYPE);
57     self.tList = ko.observableArray(TYPE);
58     self.sList = ko.observableArray();
59     self.rList = ko.observableArray();
60     self.dpList = ko.observableArray();
61
62     self.edit = function(item) {
63         doEdit(item);
64     }
65     self.del = function(item) {
66         delConfirm(item);
67     }
68 }
69
70 $(function () {
71     window.vm = new ViewModel();
72     ko.applyBindings(vm);
73     getDepartList();
74     // getShipmentgareaList();
75     // doSearch();
76     pageInit();
77
78 });
79
80 function pageInit() {
81     I.saveDepart.click(function(event) {
82         vm.o().departNo(I.selected.original.bianhao);
83         vm.o().departname(I.selected.original.text);
84     });
85     I.departName.click(function(event) {
86         I.departModal.modal('show');
87     });
88     I.save.click(function(event) {
89         if (valid()) {
90             doSave();
91         }
92     });
93     I.newObj.click(function(event) {
94         vm.o(ko.mapping.fromJS(Obj));
95         getNewNo();
96         I.modal.modal('show');
97     });
98     I.searchBtn.click(function(event) {
99         doOpen();
100     });
101     I.modal.on('hidden.bs.modal', function (e) {
102         clearError();
103         $('#dp').val(vm.rList([])).trigger("chosen:updated");
104     });
105     I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
106         if (event.keyCode == 13) {
107             doOpen();
108         }
109     });
110 }
111
112 function doOpen() {
113     var k = $.trim(vm.keyword());
114     k = !!k ? '?keyword=' + k : '';
115     window.open('businesstype.jsf' + k, '_self');
116 }
117
118 function doSearch() {
119     getList(vm.keyword(), I.pageValue, I.PZ, 1);
120 }
121
122 function getList(keyword, page, pagesize, pages) {
123     $.post('/basicinfo/businesstype/getList.htm', {
124         keyword: keyword,
125         page: page,
126         pagesize: pagesize,
127         pages: pages
128     }, function(data, textStatus, xhr) {
129         vm.list.removeAll();
130         if (data.code >= 1) {
131             // parent.showErrmsg(data.errmsg);
132              swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
133             return;
134         }
135         if (data.code == 0) {
136             if (isList(data.list)) {
137                 $.each(data.list, function(index, val) {
138                     val.directName = directName[val.direct];
139                     val.companytype = COMPANYTYPE[val.companytype];
140                     vm.list.push(val);
141                 });
142             }
143             if (!!pages) {
144                 pages = data.pages;
145                 $('#pagdiv').unbind('page').empty();
146                 if (pages > 1) {
147                     $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
148                         var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : '';
149                         window.open('businesstype.jsf?page=' + num + k, '_self');
150                     });
151                 }
152             }
153             return;
154         }
155     }, 'json');
156 }
157
158 function valid(){
159     var isValid = false;
160     var iF = $('#form');
161     iF.validate({
162         rules: {
163             'businesstypeNo': {
164                 required: true
165             },
166             'name': {
167                 required: true
168             },
169             'departname': {
170                 required: true
171             }
172         },
173         messages: {
174             'businesstypeNo': {
175                 required: '不能为空!'
176             },
177             'name': {
178                 required: '不能为空!'
179             },
180             'departname': {
181                 required: '不能为空!'
182             }
183         },
184         errorPlacement: function (err, element) {
185             var p = element.parents('.form-group').eq(0);
186             var d = p.find('.text-error').eq(0);
187             d.css('color', '#D9534F');
188             err.appendTo(d);
189         }
190     })
191     isValid = iF.valid();
192     return isValid;
193 }
194
195 function doEdit(item) {
196     vm.o(ko.mapping.fromJS(item));
197     var arr = item.spNos != null ? item.spNos.split(',') : [];
198     vm.rList(arr);
199     $('#dp').val(vm.rList()).trigger("chosen:updated");
200     I.modal.modal('show');
201 }
202
203 function delConfirm(item) {
204     $("#modalContent").html('确定要删除【' + item.name + '】吗?');
205     $("#dialog-confirm").removeClass('hide').dialog({
206         resizable: false,
207         width: '320',
208         modal: true,
209         title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
210         title_html: true,
211         position: { my: "center", at: "center", of: window },
212         buttons: [
213             {
214                 html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 确定",
215                 "class" : "btn btn-danger btn-minier",
216                 click: function() {
217                     $( this ).dialog( "close" );
218                     doDel(item);
219                 }
220             }
221             ,
222             {
223                 html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
224                 "class" : "btn btn-minier",
225                 click: function() {
226                     $( this ).dialog( "close" );
227                 }
228             }
229         ]
230     });
231 }
232
233 function doDel(item) {
234     if (!!I.AjaxDelItem) return;
235     I.AjaxDelItem = true;
236     $.post('/basicinfo/businesstype/delItem.htm', {id: item.id}, function(data, textStatus, xhr) {
237         I.AjaxDelItem = false;
238         if (data.code >= 1) {
239             // parent.showErrmsg(data.errmsg);
240             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
241             return;
242         }
243         if (data.code == 0) {
244             vm.list.remove(item);
245             location.replace(location.href);
246             return;
247         }
248     }, 'json');
249 }
250
251 function doSave() {
252     if (!I.AjaxSaveItem &&valid()) {
253         I.AjaxSaveItem = true;
254         var o = ko.mapping.toJS(vm.o());
255         o.planitem = $('#objPlanitemd').prop('checked');
256         o.factory = $('#objFactory').prop('checked');
257         o.weighing = $('#objWeighing').prop('checked');
258         o.companytype = COMPANYTYPE.indexOf(vm.o().companytype());
259         o.spNos = vm.rList().join(',');
260         $.post('/basicinfo/businesstype/saveItem.htm', o, function(data, textStatus, xhr) {
261             I.AjaxSaveItem = false;
262             if (data.code >= 1) {
263                 // parent.showErrmsg(data.errmsg);
264                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
265                 return;
266             }
267             if (data.code == 0) {
268                 location.replace(location.href);
269                 return;
270             }
271         }, 'json');
272     }
273 }
274
275 function clearError() {
276     $('#form input').removeClass('error');
277     $('#form .text-error').html('');
278 }
279
280
281 function getShipmentgareaList() {
282     // $.post('/weight/shipmentgarea/getUsedList.htm', null,
283     $.post('/weight/shipmentgarea/getList.htm', null,
284      function(data, textStatus, xhr) {
285         vm.sList.removeAll();
286         if (data.code >= 1) {
287             // parent.showErrmsg(data.errmsg);
288             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
289             return;
290         }
291         if (data.code == 0) {
292             if (isList(data.list)) {
293                 $.each(data.list, function(index, val) {
294                     vm.sList.push(val);
295                 });
296                 $('.chosen-select').chosen({search_contains: true});
297                 doSearch();
298             }
299         }
300     }, 'json');
301 }
302
303 function getDepartList(keyword, page, pagesize, pages) {
304     $.post('/enterprise/depart/getList.htm', {
305         keyword: keyword,
306         page: page,
307         pagesize: pagesize,
308         pages: pages
309     }, function(data, textStatus, xhr) {
310         var allId = [];
311         vm.dpList.removeAll();
312         if (data.code >= 1) {
313            // parent.showErrmsg(data.errmsg);
314            swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
315             return;
316         }
317         if (data.code == 0) {
318             getShipmentgareaList();
319             if (!!$('#jstree_Enterprise').jstree(true)) {
320                 $('#jstree_Enterprise').jstree(true).refresh();
321             }
322             I.DB_ep = {};
323             I.DB_epnn = {};
324             if (isList(data.list)) {
325                 var Arr = [];
326                 var level = 0;
327                 $.each(data.list, function(index, val) {
328                     vm.dpList.push(val);
329                     allId.push(val.id);
330                     I.DB_ep[val.id] = val;
331                     I.DB_epnn[val.name] = val.bianhao;
332                     if (val.level === 2) {
333                         Arr.push({
334                             text: val.name,
335                             bianhao: val.bianhao,
336                             id: val.id,
337                             children: [],
338                             state: index === 0 ? {selected: true} : ''
339                         });
340                     } else {
341                         var j = 3;
342                         var children = Arr[Arr.length - 1].children;
343                        while (j < val.level) {
344                             children = children[children.length - 1].children;
345                             j++;
346                         }
347                         children.push({
348                             text: val.name,
349                             bianhao: val.bianhao,
350                             id: val.id,
351                             children: []
352                         })
353                     }
354                 });
355                 // console.log(allId);
356                 if (allId.indexOf(I.dValue) != -1) {
357                     vm.did(I.dValue);
358                 }
359                 $('#jstree_Enterprise')
360                 .jstree({
361                     core: {
362                         check_callback : true,
363                         data: Arr
364                     },
365                     "plugins" : [
366                       'search'
367                     ]
368                 })
369                 .on("changed.jstree", function (e, data) {
370                     if(data.selected.length) {
371                         // console.log(data.instance.get_node(data.selected[0]));
372                         var selected = data.instance.get_node(data.selected[0]);
373                         I.selected = selected;
374                     }
375                 })
376             }
377             return;
378         }
379     }, 'json');
380 }
381
382 function getNewNo() {
383     $.post("/basicconfig/prefix/getNewNo.htm", {type: 'businesstype'},
384         function (data, textStatus, jqXHR) {
385             if (data.code >= 1) {
386                // parent.showErrmsg(data.errmsg);
387                swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
388                 return;
389             }
390             if (data.code == 0) {
391                 // vm.o().visitNo(data.number);
392                 $('#businesstypeNo').val(data.number);
393                 return;
394             }
395         },
396         "json"
397     );
398 }