Ext.QuickTips.init(); Ext.define('erp.controller.scm.sale.Evaluation', { extend: 'Ext.app.Controller', FormUtil: Ext.create('erp.util.FormUtil'), GridUtil: Ext.create('erp.util.GridUtil'), BaseUtil: Ext.create('erp.util.BaseUtil'), views:[ 'core.form.Panel','scm.sale.Evaluation','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField', 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.Upload','core.button.ResAudit', 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit', 'core.button.Banned','core.button.ResBanned','core.grid.YnColumn','core.button.BOMCost','core.button.BOMInsert','core.button.BOMVastCost', 'core.button.TurnOffPrice', 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.form.YnField','core.form.FileField' ], init:function(){ var me = this; this.control({ 'erpGridPanel2': { itemclick: this.onGridItemClick }, 'field[name=ev_currency]': { beforetrigger: function(field) { var t = field.up('form').down('field[name=ev_date]'), value = t.getValue(); if(value) { field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym'); } } }, 'erpSaveButton': { click: function(btn){ var form = me.getForm(btn); if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){ me.BaseUtil.getRandomNumber();//自动添加编号 } var ev_materialcost=Ext.getCmp('ev_materialcost').value, ev_makecost=Ext.getCmp('ev_makecost').value, ev_mancost=Ext.getCmp('ev_mancost').value, ev_othercost=Ext.getCmp('ev_othercost').value, statdate = Ext.getCmp('ev_fromdate').value, enddate = Ext.getCmp('ev_validdate').value; if(!Ext.isEmpty(enddate)){ if(Ext.Date.format(statdate,'Y-m-d') > Ext.Date.format(enddate,'Y-m-d')){ bool=false; showError('失效日期不能小于生效日期!');return; } if(Ext.Date.format(enddate,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('失效日期不能小于当前日期!');return; } } Ext.getCmp('ev_cost').setValue(Number(ev_materialcost)+Number(ev_makecost)+Number(ev_mancost)+Number(ev_othercost)); this.FormUtil.beforeSave(this); } } , 'erpDeleteButton' : { click: function(btn){ me.FormUtil.onDelete(Ext.getCmp('ev_id').value); } }, 'erpUpdateButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ var ev_materialcost=Ext.getCmp('ev_materialcost').value, ev_makecost=Ext.getCmp('ev_makecost').value, ev_mancost=Ext.getCmp('ev_mancost').value, ev_othercost=Ext.getCmp('ev_othercost').value, statdate = Ext.getCmp('ev_fromdate').value, enddate = Ext.getCmp('ev_validdate').value; if(!Ext.isEmpty(enddate)){ if(Ext.Date.format(statdate,'Y-m-d') > Ext.Date.format(enddate,'Y-m-d')){ bool=false; showError('失效日期不能小于生效日期!');return; } if(Ext.Date.format(enddate,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('失效日期不能小于当前日期!');return; } } Ext.getCmp('ev_cost').setValue(Number(ev_materialcost)+Number(ev_makecost)+Number(ev_mancost)+Number(ev_othercost)); this.FormUtil.onUpdate(this); } }, 'erpAddButton': { click: function(){ me.FormUtil.onAdd('addEvaluation', '新增估价单', 'jsps/scm/sale/evaluation.jsp'); } }, 'erpCloseButton': { click: function(btn){ me.FormUtil.beforeClose(me); } }, 'erpSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn){ var statdate = Ext.getCmp('ev_fromdate').value, enddate = Ext.getCmp('ev_validdate').value; if(!Ext.isEmpty(enddate)){ if(Ext.Date.format(statdate,'Y-m-d') > Ext.Date.format(enddate,'Y-m-d')){ bool=false; showError('失效日期不能小于生效日期!');return; } if(Ext.Date.format(enddate,'Y-m-d') < Ext.Date.format(new Date(),'Y-m-d')){ bool=false; showError('失效日期不能小于当前日期!');return; } } me.FormUtil.onSubmit(Ext.getCmp('ev_id').value); } }, 'erpResSubmitButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResSubmit(Ext.getCmp('ev_id').value); } }, 'erpAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'COMMITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onAudit(Ext.getCmp('ev_id').value); } }, 'erpResAuditButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(btn){ me.FormUtil.onResAudit(Ext.getCmp('ev_id').value); } }, 'erpPrintButton': { click:function(btn){ var reportName="sale_gj"; var condition='{evaluation.ev_id}='+Ext.getCmp('ev_id').value+''; var id=Ext.getCmp('ev_id').value; me.FormUtil.onwindowsPrint(id,reportName,condition); } }, 'erpBannedButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value == 'BANNED'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onBanned(Ext.getCmp('ev_id').value); } }, 'erpResBannedButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'BANNED'){ btn.hide(); } }, click: function(btn){ this.FormUtil.onResBanned(Ext.getCmp('ev_id').value); } }, 'erpBOMCostButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn) { var form = btn.ownerCt.ownerCt, ev_id = Ext.getCmp('ev_id').value, bo_id = Ext.getCmp('ev_bomid').value, pr_code = Ext.getCmp('ev_prcode').value; if(bo_id==""){bo_id=0;} form.setLoading(true); Ext.Ajax.request({ url: basePath + 'scm/sale/bomcost.action', params: { ev_id: ev_id, bo_id: bo_id, pr_code: pr_code }, timeout: 600000, callback: function(opt, s, r) { form.setLoading(false); var rs = Ext.decode(r.responseText); if(rs.success) { alert('计算完成!'); me.FormUtil.loadNewStore(form, {caller: caller, condition: 'ev_id=' + ev_id}); me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: 'evd_evid=' + ev_id}); } else if(r.exceptionInfo) { showError(r.exceptionInfo); } } }); } }, 'erpBOMInsertButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'ENTERING'){ btn.hide(); } }, click: function(btn) { var form = btn.ownerCt.ownerCt, ev_id = Ext.getCmp('ev_id').value; form.setLoading(true); Ext.Ajax.request({ url: basePath + 'scm/sale/bominsert.action', params: { ev_id: ev_id }, timeout: 600000, callback: function(opt, s, r) { form.setLoading(false); var rs = Ext.decode(r.responseText); if(rs.success) { alert('导入成功!'); me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: 'evd_evid=' + ev_id}); } else if(r.exceptionInfo) { showError(r.exceptionInfo); } } }); } }, 'erpBOMVastCostButton': { click: function(btn) { var form = btn.ownerCt.ownerCt, ev_id = Ext.getCmp('ev_id').value; form.setLoading(true); Ext.Ajax.request({ url: basePath + 'scm/sale/bomvastcost.action', params: { ev_id: ev_id }, timeout: 600000, callback: function(opt, s, r) { form.setLoading(false); var rs = Ext.decode(r.responseText); if(rs.success) { alert('计算完成!'); me.FormUtil.loadNewStore(form, {caller: caller, condition: 'ev_id=' + ev_id}); me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: 'evd_evid=' + ev_id}); } } }); } }, 'textfield[name=ev_rate]':{ change: function(f){ var v = Ext.isEmpty(f.value) ? 1 : f.value, grid = f.up('form').ownerCt.down('grid'); grid.store.each(function(){ this.set('evd_price', Ext.Number.toFixed(this.get('evd_doubleprice')/v, 6)); this.set('evd_amount', Ext.Number.toFixed(this.get('evd_price')*this.get('evd_qty'), 2)); }); } }, 'erpTurnOffPriceButton': { afterrender: function(btn){ var status = Ext.getCmp('ev_checkstatuscode'); if(status && status.value != 'AUDITED'){ btn.hide(); } }, click: function(b){ warnMsg("确定要转入核价单吗?", function(btn){ if(btn == 'yes'){ me.turnQuotation(b.ownerCt.ownerCt); } }); } } }); }, onGridItemClick: function(selModel, record){//grid行选择 this.GridUtil.onGridItemClick(selModel, record); }, getForm: function(btn){ return btn.ownerCt.ownerCt; }, turnQuotation: function(form) { var me = this; form.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + 'scm/evaluation/turnQuotation.action', params: { id: form.down('#ev_id').value }, method : 'post', callback : function(options,success,response){ form.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ turnSuccess(function(){ var id = localJson.id; var url = "jsps/scm/sale/quotation.jsp?formCondition=qu_idIS"+ id + "&gridCondition=qd_quidIS"+ id; me.FormUtil.onAdd('Quotation' + id, '物料核价单' + id, url); }); } } }); } });