Ext.QuickTips.init(); Ext.define('erp.controller.pm.make.MakeBase', { extend: 'Ext.app.Controller', requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'], views:[ 'core.form.Panel','pm.make.MakeBase','core.toolbar.Toolbar','core.form.MultiField','core.form.YnField', 'core.button.Save','core.button.MakeDownPut','core.button.Add','core.button.Submit','core.button.ResAudit', 'core.button.Audit','core.button.ResMakeDownPut','core.button.Close','core.button.Delete','core.button.Update','core.button.ResSubmit', 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.grid.YnColumn','core.button.Flow','core.button.UpdateTeamcode', 'core.trigger.MultiDbfindTrigger','core.button.EnforceEnd','core.button.End', 'core.button.ResEnd','core.button.ModifyMaterial', 'core.button.SubRelation','core.button.UpdateRemark','erp.view.core.grid.HeaderFilter','core.button.MakeSNCode', 'core.button.MakeStop','core.button.MakeResStop','core.button.ModifyDetail','core.button.Modify','core.button.VindicateMake', 'core.button.CopyByConfigs','core.button.DecomSetting','core.button.UpdateMaCraft' ], init:function(){ var me = this; me.FormUtil = Ext.create('erp.util.FormUtil'); me.GridUtil = Ext.create('erp.util.GridUtil'); me.BaseUtil = Ext.create('erp.util.BaseUtil'); this.control({ '#ma_remark':{ beforerender: function(field){ field.readOnly=false; } }, /* '#ma_firstitemcheck':{ change:function(f){ if (f.value==-1) { Ext.getCmp('ma_allowpronum').setFieldStyle("color:#000000"); Ext.getCmp('ma_allowpronum').allowBlank=false; }else { Ext.getCmp('ma_allowpronum').allowBlank=true; } } },*/ '#ma_teamcode':{ beforerender: function(field){ field.readOnly=false; } }, '#ma_style':{ beforerender: function(field){ field.readOnly=false; } }, 'erpGridPanel2': { afterrender: function(grid){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'ENTERING' ){ grid.setReadOnly(true); } }, reconfigure:function(grid){ var items = grid.store.data.items; var totaluseqty = grid.store.getSum(items, 'mm_totaluseqty'); var havegetqty = grid.store.getSum(items, 'mm_havegetqty'); if( totaluseqty!=0 || havegetqty!=0){ /*Ext.getCmp('resAudit').hide(); Ext.getCmp('resCheck').hide();*/ } }, itemclick: function(view,record){ me.itemclick(view,record,me); } }, 'field[name=ma_currency]': { beforetrigger: function(field) { var value = Ext.getCmp('ma_date').value; if(value) { field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym'); } } }, 'erpMakeSNCodeButton':{ click: function(){ var id = Ext.getCmp('ma_id').value; /*var url = "jsps/pm/make/makeIMEI.jsp?whoami=Make!MakeSN";*/ var url = "jsps/common/import.jsp?whoami=Make!MakeSN"; var panelId = caller + "ma_id_" + id + "ma_idIS"+id; var panel = Ext.getCmp(panelId); var main = parent.Ext.getCmp("content-panel"); if(!main){ main = parent.parent.Ext.getCmp("content-panel"); } if(!panel){ var title = ""; panel = { title : '工单序列号导入', tag : 'iframe', tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'(ma_id"="' + id +')'}, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab1', html : '', closable : true, listeners : { close : function(){ if(!main){ main = parent.parent.Ext.getCmp("content-panel"); } main.setActiveTab(main.getActiveTab().id); } } }; this.openTab(panel, panelId); }else{ main.setActiveTab(panel); } } }, 'erpDecomSettingButton':{ afterrender: function(btn){ var ma_kind = Ext.getCmp("ma_kind"); if(ma_kind && ma_kind.value != '返工' ){ btn.hide(); } }, click: function(btn){ var ma_screcode = Ext.getCmp('ma_screcode').value; var grid = Ext.getCmp('grid'); var caller = 'DecomSetting!Make'; var id = Ext.getCmp('ma_id').value; var result = 0; if(ma_screcode != null && ma_screcode !=''){ Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: 'reworkdetail left join rework on re_id = rd_reid', field: 'count(rd_sncode)', condition: "re_code= '" + ma_screcode +"'" }, method : 'post', callback : function(opt, s, res){ var r = new Ext.decode(res.responseText); if(r.exceptionInfo){ showError(r.exceptionInfo);return; } else if(r.success){ result = r.data; } } }); }else{ showError("返工需求单号为空");return; } if(result > 0){ var dbwin = new Ext.window.Window({ id : 'dcswin', title: '拆解部件设定', height: "100%", width: "90%", maximizable : true, buttonAlign : 'center', layout : 'anchor', items: [], listeners:{ beforeclose: function(){ window.location.reload(); } } }); dbwin.add({ tag : 'iframe', frame : true, anchor : '100% 100%', layout : 'fit', html : '' }); dbwin.show(); }else{ showError("不存在序列号");return; } /*var items = grid.getStore().data.items;//获取store里面的数据 */ } }, 'erpMakeDownPutButton':{ afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'AUDITED' ){ btn.hide(); } }, click: function(btn){ //var istrue =me.checkFirstItem(); //if (!istrue) { // return false; //} warnMsg("确定要下放吗?", function(btn){ if(btn == 'yes'){ me.FormUtil.setLoading(true); Ext.Ajax.request({ url : basePath + 'pm/make/MakeDownPut.action', params: { id: Ext.getCmp('ma_id').value, caller : caller }, method : 'post', callback : function(options,success,response){ me.FormUtil.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert("提示","下放成功!",function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage('提示', str); window.location.reload(); } else if(str == 'OK'){ Ext.Msg.alert("提示","下放成功!"); } else { showError(str);return; } } } } }); } }); } }, 'erpVindicateMakeButton':{ click: function(btn){ var id = Ext.getCmp("ma_id").value; if(id != null && id != '' && id != 0 && id != '0'){ me.FormUtil.onAdd('MakeMaterial' + id, '用料表维护', 'jsps/pm/make/makeMaterial.jsp?formCondition=ma_id=' + id +"&gridCondition=mm_maid=" + id); } } }, 'erpResMakeDownPutButton':{ afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'STARTED' ){ btn.hide(); } }, click: function(btn){ var me = this; me.FormUtil.setLoading(true); Ext.Ajax.request({ url : basePath + 'pm/make/ResMakeDownPut.action', params: { id: Ext.getCmp('ma_id').value, caller : caller }, method : 'post', callback : function(options,success,response){ me.FormUtil.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert("提示","取消下放成功!",function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage('提示', str); window.location.reload(); } else if(str == 'OK'){ Ext.Msg.alert("提示","取消下放成功!"); } else { showError(str);return; } } } } }); } }, 'erpMakeStopButton':{ afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'STARTED' ){ btn.hide(); } }, click: function(btn){ warnMsg("确定要暂停吗?", function(btn){ if(btn == 'yes'){ Ext.Ajax.request({ url : basePath + 'pm/make/MakeStop.action', params: { id: Ext.getCmp('ma_id').value, caller : caller }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert("提示","暂停成功!",function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage('提示', str); window.location.reload(); } else if(str == 'OK'){ Ext.Msg.alert("提示","暂停成功!"); } else { showError(str);return; } } } } }); } }); } }, 'erpMakeResStopButton':{ afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'STOP' ){ btn.hide(); } }, click: function(btn){ Ext.Ajax.request({ url : basePath + 'pm/make/ResMakeStop.action', params: { id: Ext.getCmp('ma_id').value, caller : caller }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert("提示","取消暂停成功!",function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage('提示', str); window.location.reload(); } else if(str == 'OK'){ Ext.Msg.alert("提示","取消暂停成功!"); } else { showError(str);return; } } } } }); } }, 'erpSaveButton': { click: function(btn){ var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField); if(codeField.value == null || codeField.value == ''){ me.BaseUtil.getRandomNumber(caller);//自动添加编号 var res = me.getLeadCode(Ext.getCmp('ma_kind').value); if(res != null && res != ''){ codeField.setValue(res + codeField.getValue()); } } this.FormUtil.beforeSave(this); } }, 'erpCloseButton': { click: function(btn){ this.FormUtil.beforeClose(this); } }, /*'erpDeleteDetailButton': { afterrender: function(btn){ btn.ownerCt.add({ xtype: 'erpSubRelationButton' }); btn.ownerCt.add({ xtype: 'erpModifyMaterialButton' }); } },*/ 'erpUpdateButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'ENTERING' ){ btn.hide(); } }, click: function(btn){ if (Ext.getCmp('ma_firstitemcheck').value!=-1) { Ext.getCmp('ma_allowpronum').allowBlank=true; } this.FormUtil.onUpdate(this); /*var oldmaqty=0; if (Ext.getCmp('ma_id').value>0){ oldmaqty=me.getFdValue('make','ma_qty','ma_id='+Ext.getCmp('ma_id').value); } if (oldmaqty-Ext.getCmp('ma_qty').value!=0){ alert('工单需求数量已经被修改,请重新计算用料!'); }*/ } }, 'erpDeleteButton': { click: function(btn){ me.FormUtil.onDelete(Ext.getCmp('ma_id').value); } }, 'erpAddButton': { click: function(){ me.FormUtil.onAdd('addMakeBase', '新增单据', 'jsps/pm/make/makeBase.jsp?whoami=' + caller); } }, 'erpSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ //var istrue =me.checkFirstItem(); //if (!istrue) { // return false; //} /*var type = Ext.getCmp('ma_tasktype').getValue(); if(type != 'MAKE'){// 委外工单 考虑加工单价 var p = Ext.getCmp('ma_price'); if(p && (Ext.isEmpty(p.value) || p.value == 0)){ Ext.Msg.alert("提示","请先填写加工单价后再提交!"); return; } }*/ me.FormUtil.onSubmit(Ext.getCmp('ma_id').value); } }, 'erpResSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResSubmit(Ext.getCmp('ma_id').value); } }, 'erpAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onAudit(Ext.getCmp('ma_id').value); } }, 'erpResAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } var checkStatus = Ext.getCmp('ma_checkstatuscode'); if(checkStatus && checkStatus.value == 'COMMITED'){ btn.hide(); } }, click: function(btn){ if (!confirm('确定要反审核单据?')){ return; } me.FormUtil.onResAudit(Ext.getCmp('ma_id').value); } }, 'erpEnforceEndButton':{ afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value == 'FINISH'){ btn.hide(); } }, click: function(btn){ warnMsg("确定要强制结案吗?", function(btn){ if(btn == 'yes'){ Ext.Ajax.request({ url : basePath + 'pm/make/enforceEndMake.action', params: { id: Ext.getCmp('ma_id').value }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert("提示","操作成功!"); window.location.reload(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage('提示', str); window.location.reload(); } else if(str == 'OK'){ Ext.Msg.alert("提示","强制结案成功!"); } else { showError(str);return; } } } } }); } }); } }, 'erpChangeMaterialButton': { afterrender: function(btn){ btn.hide();//暂时不启用 var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } } }, 'dbfindtrigger[name=ma_saledetno]': { afterrender: function(t){ t.dbKey = "ma_salecode"; t.mappingKey = "sd_code"; t.dbMessage = "请先选择订单编号!"; } }, 'combo[name=ma_sourcekind]':{ change:function(field,newValue){ var codefield=Ext.getCmp('ma_salecode'); var detnofield=Ext.getCmp('ma_saledetno'); if(newValue=='Sale'){ //销售预测 codefield.dbCaller='Make!Base'; detnofield.dbCaller='Make!Base'; }else if(newValue=='SaleForeCast'){ codefield.dbCaller='Make!Base!ForeCast'; detnofield.dbCaller='Make!Base!ForeCast'; } } }, 'dbfindtrigger[name=mm_prodcode]': { /*focus: function(t){ var grid = Ext.getCmp('grid'); var c = null; Ext.each(grid.store.data.items, function(item){ if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != ''){ if(c == null){ c = "(pr_code<>'" + item.data['mm_prodcode'] + "'"; } else { c += " and pr_code<>'" + item.data['mm_prodcode'] + "'"; } } }); if(c != null){ t.dbBaseCondition = c + ")"; } }*/ }, 'textfield[name=ma_wccode]': { change: function(field){ if(field.value != null && field.value != ''){ var grid = Ext.getCmp('grid'); var d = field.value; if(grid){ Ext.Array.each(grid.getStore().data.items,function(item){ if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != '' ){ if(item.data['mm_wccode'] == null ||item.data['mm_wccode'] == '' ){ item.set('mm_wccode',d); } } }); } } } }, 'datefield[name=ma_planenddate]':{ change: function(f) { var c = Ext.getCmp('ma_planbegindate').getValue(); var value = f.value; if( c != null && c != '' && value !=null && value != ''){ if(c > value){ Ext.getCmp('ma_planbegindate').setValue(''); showError('计划完工日期不能早于计划开工日期'); } } } }, 'datefield[name=ma_planbegindate]':{ change: function(f) { var c = Ext.getCmp('ma_planenddate').getValue(); var value = f.value; if( value !=null && value != ''){ var formatV = new Date(Ext.util.Format.date(value, 'Y-m-d')); if(c != null && c != '' ){ if(value > c){ Ext.getCmp('ma_planenddate').setValue(''); showError('计划完工日期不能早于计划开工日期'); } } } } }, 'erpEndButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ Ext.MessageBox.show({ title:'结案', msg:'请输入结案原因:', width:300, buttons:Ext.MessageBox.OKCANCEL, multiline:true, fn:function(btn,text){ if(btn == 'ok'){ me.onEnd(Ext.getCmp('ma_id').value,text); } } }) } }, 'erpResEndButton': { afterrender: function(btn){ var status = Ext.getCmp('ma_statuscode'); if(status && status.value != 'FINISH'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResEnd(Ext.getCmp('ma_id').value); } }, 'erpSubRelationButton':{ click:function(btn){ var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"]; var formCondition="mm_id IS"+id; var gridCondition="mp_mmid IS"+id; var linkCaller='MakeBase!Sub'; var win = new Ext.window.Window( { id : 'win', height : '90%', width : '95%', maximizable : true, buttonAlign : 'center', layout : 'anchor', items : [ { tag : 'iframe', frame : true, anchor : '100% 100%', layout : 'fit', html : '' } ] }); win.show(); }, afterrender:function(btn){ btn.setDisabled(true); } }, 'erpModifyMaterialButton':{ click:function(btn){ var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"]; var formCondition="mm_id IS"+id; var linkCaller='MakeMaterial!Modify'; var win = new Ext.window.Window( { id : 'win', height : '90%', width : '95%', maximizable : true, buttonAlign : 'center', layout : 'anchor', items : [ { tag : 'iframe', frame : true, anchor : '100% 100%', layout : 'fit', html : '' } ], listeners:{ 'beforeclose':function(view ,opt){ var grid = Ext.getCmp('grid'); var value = Ext.getCmp('ma_id').value; var gridCondition = grid.mainField + '=' + value, gridParam = {caller: caller, condition: gridCondition}; me.GridUtil.loadNewStore(grid, gridParam); } } }); win.show(); }, afterrender:function(btn){ btn.setDisabled(true); } }, 'field[name=ma_prodcode]': { change: function(f){ if(f.value != null && f.value != ''){ me.FormUtil.getFieldValue('BOM', 'bo_id', "bo_mothercode='" + f.value + "'", 'ma_bomid'); } } }, /*'field[name=ma_qty]': { change: function(f){ if(f.value == null || f.value == ''){ f.value = 0; } if(Ext.getCmp('ma_total')){ Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_price').value); } var grid = Ext.getCmp('grid'); if(grid){ var items = grid.store.data.items; Ext.each(items, function(item){//制单需求=制单套数*单位用量 if(item.data['mm_oneuseqty'] != null && item.data['mm_oneuseqty'] != 0){ item.set('mm_qty', item.data['mm_oneuseqty']*f.value); } }); } } },*/ 'erpUpdateRemarkButton':{ click:function(){ var remark=Ext.getCmp('ma_remark'); me.updateRemark(remark.value,Ext.getCmp('ma_id').value); } }, 'erpUpdateTeamcodeButton':{ click:function(){ var linecode=Ext.getCmp('ma_linecode'); me.updateTeamcode(linecode.value,Ext.getCmp('ma_id').value); } }, 'field[name=ma_price]': { change: function(f){ if(f.value == null || f.value == ''){ f.value = 0; } if(Ext.getCmp('ma_total')){//字段存在赋值,不存在不赋值 Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_qty').value); } } }, 'field[name=mm_oneuseqty]': { change: function(f){//制单需求=制单套数*单位用量 if(f.value != null && f.value > 0 && Ext.getCmp('ma_qty') && Ext.getCmp('ma_qty').value > 0){ var record = Ext.getCmp('grid').selModel.getLastSelected(); if(record.data['mm_qty'] != f.value*Ext.getCmp('ma_qty').value){ record.set('mm_qty', f.value*Ext.getCmp('ma_qty').value); } } } }, 'dbfindtrigger[name=ma_craftcode]': { beforetrigger: function(field) { var t = field.up('form').down('field[name=ma_prodcode]'), value = t.getValue(); if(value) { field.findConfig = "cr_prodcode='" + value + "'"; } } }, 'dbfindtrigger[name=ma_bomversion]': { beforetrigger: function(field) { var value1 = Ext.getCmp('ma_prodcode').value; var value2 = Ext.getCmp('ma_craftcode').value; if(value1 && value2) { field.findConfig = "sb_prodcode='"+value1+"' and sb_craftcode = '"+value2+"'"; }else if(value1){ field.findConfig = "sb_prodcode='"+value1+"'"; }else if(value2){ field.findConfig = "sb_craftcode = '"+value2+"'"; } } }, 'erpUpdateMaCraftButton':{ afterrender:function(btn){ var status = Ext.getCmp("ma_statuscode"); if((status && (status.value == 'ENTERING' || status.value == 'FINISH'))){ btn.hide(); } }, click:function(){ var me=this; var cr_code = Ext.getCmp('ma_craftcode'), bg = 'background:#fffac0;color:#515151;'; var win = Ext.getCmp('cr_win'); if(win == null){ win = Ext.create('Ext.window.Window',{ width:400, height:200, id:'cr_win', title:'