Ext.define('make.view.make.makeBase.FormPanelController', { extend: 'saas.view.core.form.FormPanelController', alias: 'controller.make-makebase-formpanel', init: function (form) { var me = this; this.control({ 'dbfindtrigger[name=ma_prodcode]':{ beforerender:function(f){ Ext.apply(f,{ //放大镜赋值设置 dbfinds:[{ from:'id',to:'ma_prodid',ignore:true },{ from:'pr_code',to:'ma_prodcode' },{ from:'pr_detail',to:'pr_detail' },{ from:'pr_spec',to:'pr_spec' },{ from: 'pr_brand', to: 'pr_brand' },{ from: 'pr_orispeccode', to: 'pr_orispeccode' },{ from: 'pr_unit', to: 'pr_unit' }], }); } }, 'saledetailDbfindTrigger[name=ma_salecode]':{ beforerender:function(f){ Ext.apply(f,{ //放大镜赋值设置 dbfinds:[{ from:'sa_id',to:'ma_saleid',ignore:true },{ from:'sa_code',to:'ma_salecode' },{ from:'sa_custname',to:'ma_custname' },{ from:'sa_custid',to:'ma_custid' },{ from: 'sa_custcode', to: 'ma_custcode' },{ from: 'sd_delivery', to: 'ma_delivery' },{ from: 'sd_prodcode', to: 'ma_prodcode' },{ from: 'pr_detail', to: 'pr_detail' },{ from: 'pr_spec', to: 'pr_spec' },{ from: 'pr_orispeccode', to: 'pr_orispeccode' },{ from:'sd_prodid',to:'ma_prodid' },{ from: 'pr_brand', to: 'pr_brand' },], }); } }, //从表多选放大镜赋值关系 以及 tpl模板 'multidbfindtrigger[name=mm_prodcode]':{ beforerender:function(f){ Ext.apply(f,{ //放大镜赋值设置 dbfinds:[{ from:'id',to:'mm_prodid',ignore:true },{ from:'pr_code',to:'mm_prodcode' },{ from:'pr_detail',to:'pr_detail' },{ from:'pr_spec',to:'pr_spec' },{ from: 'pr_brand', to: 'pr_brand' },{ from: 'pr_orispeccode', to: 'pr_orispeccode' },{ from: 'pr_unit', to: 'pr_unit' },{ from: 'pu_decimal', to: 'pu_decimal' }], }); } }, 'multidbfindtrigger[name=pr_detail]': { beforerender: function (f) { Ext.apply(f, { dbfinds:[{ from:'id',to:'mm_prodid',ignore:true },{ from:'pr_code',to:'mm_prodcode' },{ from:'pr_detail',to:'pr_detail' },{ from:'pr_spec',to:'pr_spec' },{ from: 'pr_brand', to: 'pr_brand' },{ from: 'pr_orispeccode', to: 'pr_orispeccode' },{ from: 'pr_unit', to: 'pr_unit' },{ from: 'pu_decimal', to: 'pu_decimal' }], }); } } }); }, /** * 单位用量改变改变,级联事件 * @param {*} field */ onOneUseChange: function (field) { if (field.value) { var me = this, view = me.getView(), vm = view.getViewModel(), oneuseqty = field.value || 0, ma_qty = vm.get('ma_qty') || 0, record = view.down('detailGridField').selModel.getLastSelected(), decimal = record.get('pu_decimal')||(record.get('productDTO')?record.get('productDTO')['pu_decimal']:0); if(ma_qty>0){ qty = Number(Math.ceil(oneuseqty * ma_qty*Math.pow(10,decimal))/Math.pow(10,decimal)); if(record.data['mm_qty'] != qty){ record.set('mm_qty', qty); } } } }, /** * 用料表计算 */ calMaterial: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._calMaterial + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { saas.util.BaseUtil.showSuccessToast('用料计算成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('用料计算失败: ' + e.message); }); }, /** * 生成领料单 */ turnPick: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._turnPick + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { var intValue = localJson.data.id, codeValue = localJson.data.code, name = '生产领料'; saas.util.BaseUtil.openTab('make-makepick-formpanel', name + "(" + codeValue + ")", codeValue + intValue, { initId: intValue }); saas.util.BaseUtil.showSuccessToast('转单成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message); }); }, /** * 生成退料单 */ turnBack: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._turnBack + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { var intValue = localJson.data.id, codeValue = localJson.data.code, name = '生产退料'; saas.util.BaseUtil.openTab('make-makereturn-formpanel', name + "(" + codeValue + ")", codeValue + intValue, { initId: intValue }); saas.util.BaseUtil.showSuccessToast('转单成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message); }); }, /** * 生成报废单 */ turnScrap: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._turnScrap + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { var intValue = localJson.data.id, codeValue = localJson.data.code, name = '生产报废'; saas.util.BaseUtil.openTab('make-makescrap-formpanel', name + "(" + codeValue + ")", codeValue + intValue, { initId: intValue }); saas.util.BaseUtil.showSuccessToast('转单成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message); }); }, /** * 生成完工入库单 */ turnIn: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._turnIn + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { var intValue = localJson.data.id, codeValue = localJson.data.code, name ='完工入库'; saas.util.BaseUtil.openTab('make-makein-formpanel', name + "(" + codeValue + ")", codeValue + intValue, { initId: intValue }); saas.util.BaseUtil.showSuccessToast('转单成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('转单失败: ' + e.message); }); }, /** * 结案 */ end: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._end + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { if(localJson.data){ //弹出结案检测的结果,弹出window me.showEndCheckDataWin(localJson.data); }else{ saas.util.BaseUtil.showSuccessToast('结案成功'); saas.util.FormUtil.loadData(form); } } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('结案失败: ' + e.message); }); }, /** * 反结案 */ resEnd: function(){ var me = this, form = me.getView(), id = form.getForm().findField(form._idField); form.setLoading(true); saas.util.BaseUtil.request({ url: form._resEnd + '/' + id.value, method: 'POST', }) .then(function (localJson) { form.setLoading(false); if (localJson.success) { saas.util.BaseUtil.showSuccessToast('反结案成功'); saas.util.FormUtil.loadData(form); } }) .catch(function (e) { form.setLoading(false); saas.util.BaseUtil.showErrorToast('反结案失败: ' + e.message); }); }, /** * 修改用料 */ modifyMaterial: function(button){ //需要先选中行 var me = this, form = me.getView(), grid = form.down('detailGridField'), record = grid.selModel.getLastSelected(), vm = form.getViewModel(); if(null == record || record.get('mm_id')){ saas.util.BaseUtil.showErrorToast('请先选择明细行'); }else{ me.materialDialog = form.add({ xtype: 'make-makebase-modifymaterialwin', _parent:form, }); me.materialDialog.getViewModel().set('form',{ id:record.get('id'), mm_detno:record.get('mm_detno'), mm_prodid:record.get('mm_prodid'), mm_prodcode:record.get('mm_prodcode'), mm_oneuseqty:record.get('mm_oneuseqty'), mm_qty:record.get('mm_qty'), mm_remark:record.get('mm_remark'), pr_detail:record.get('pr_detail'), pr_spec:record.get('pr_spec'), pr_brand:record.get('pr_brand'), pr_orispeccode:record.get('pr_orispeccode'), pu_decimal: record.get('pu_decimal')||record.get('productDTO')['pu_decimal']}); me.materialDialog.getViewModel().set('ma_qty',vm.get('ma_qty')); me.materialDialog.getViewModel().set('ma_id',vm.get('id')); me.materialDialog.show(); } }, /** * 工单变更 */ modifyMake: function(){ var me = this, base = me.getView(), vm = base.getViewModel(); var win = base.add(Ext.create('Ext.window.Window', { cls: 'x-window-dbfind', modal: true, minHeight: 150, width: 800, title: '工单变更', bodyPadding: 10, constrain: true, closable: true, layout: 'anchor', renderTo: base.getEl(), viewModel: { data: { make:{ id:vm.get('id'), ma_code:vm.get('ma_code'), ma_prodcode:vm.get('ma_prodcode'), ma_qty:0, ma_turnmadeqty:vm.get('ma_turnmadeqty') }, oldmake:{ ma_oldqty:vm.get('ma_qty'), } } }, items: [{ xtype: 'form', layout: 'column', autoScroll: true, buttonAlign : 'center', _saveUrl:'/api/make/make/modifyMake', defaults:{ columnWidth:0.33 , margin: '0 0 10 0', labelAlign: 'right', labelWidth: 90, }, bodyPadding: '8 12 8 12', items:[{ xtype: 'hidden', fieldLabel: 'ID', allowBlank: false, bind:'{make.id}', },{ xtype: 'textfield', name: 'ma_code', fieldLabel: '制造单号', allowBlank: false, readOnly: true, bind:'{make.ma_code}', },{ xtype: 'textfield', name: 'ma_prodcode', fieldLabel: '产品编号', allowBlank: false, readOnly: true, bind:'{make.ma_prodcode}', },{ xtype: 'textfield', name: 'ma_oldqty', fieldLabel: '原数量', readOnly: true, bind:'{oldmake.ma_oldqty}', },{ xtype: 'numberfield', name: 'ma_qty', fieldLabel: '新数量', allowBlank: false, bind:'{make.ma_qty}', decimalPrecision: 6, },{ xtype: 'numberfield', name: 'ma_turnmadeqty', fieldLabel: '已转完工数', readOnly: true, bind:'{make.ma_turnmadeqty}', }], buttons: [{ text:'保存', disabled: true, formBind: true, handler:'onWinMSave' },{ text: '关闭', handler:'onWinMClose' }] }], })); win.show(); }, //工单变更修改 onWinMSave:function(btn){ var me = this; view = btn.ownerCt.ownerCt.ownerCt, vm = view.getViewModel(), form = view.down('form'), params = Ext.clone(vm.get('make')), oldmake = Ext.clone(vm.get('oldmake')); if(Ext.isEmpty(params.ma_qty)){ saas.util.BaseUtil.showErrorToast('新数量不能为空!'); return false; } if(params.ma_qty<=0){ saas.util.BaseUtil.showErrorToast('新数量不能小于等于0,如需关闭工单,请使用结案功能!'); return false; } if(params.ma_qty == oldmake.ma_oldqty){ saas.util.BaseUtil.showErrorToast('新数量等于旧数量无须变更!'); return false; } view.setLoading(true); saas.util.BaseUtil.request({ url: form._saveUrl, params: JSON.stringify(params), method: 'POST', }) .then(function(localJson) { view.setLoading(false); if(localJson.success){ saas.util.BaseUtil.showSuccessToast('修改成功'); me.onWinMClose(btn); //刷新工单页面 saas.util.FormUtil.loadData(me.getView()); } }) .catch(function(e) { view.setLoading(false); saas.util.BaseUtil.showErrorToast('修改失败: ' + e.message); }); }, onWinMClose:function(btn){ btn.ownerCt.ownerCt.ownerCt.close(); }, /** * 显示结案检测结果弹框 */ showEndCheckDataWin: function(data){ var me = this, base = me.getView(), vm = base.getViewModel(); tab = saas.util.BaseUtil.getCurrentTab(), win = tab.add({ xtype: 'make-makebase-endcheck-window', modal: true, onConfirm: function () { win.close(); } }); win.show(); win.loadData(data); }, });