Ext.define('saas.view.money.verification.FormPanelController', { extend: 'saas.view.core.form.FormPanelController', alias: 'controller.money-verification-formpanel', init: function (form) { var me = this; this.control({ // 客户 'dbfindtrigger[name=vc_custname]':{ beforerender:function(f){ Ext.apply(f,{ //赋值 dbfinds:[{ from: 'id', to: 'vc_custid',ignore:true }, { from:'cu_code', to:'vc_custcode' },{ from:'cu_name', to:'vc_custname' }], }) ; } }, // 转出客户 'dbfindtrigger[name=vc_outcustname]':{ beforerender:function(f){ Ext.apply(f,{ //赋值 dbfinds:[{ from: 'id', to: 'vc_outcustid',ignore:true }, { from:'cu_code', to:'vc_outcustcode' },{ from:'cu_name', to:'vc_outcustname' }], }) ; } }, // 转入客户 'dbfindtrigger[name=vc_turncustname]':{ beforerender:function(f){ Ext.apply(f,{ //赋值 dbfinds:[{ from: 'id', to: 'vc_turncustid',ignore:true }, { from:'cu_code', to:'vc_turncustcode' },{ from:'cu_name', to:'vc_turncustname' }], }) ; } }, // 供应商 'dbfindtrigger[name=vc_vendname]':{ beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'vc_vendid', ignore: true }, { from: 've_code', to: 'vc_vendcode' }, { from: 've_name', to: 'vc_vendname' }], }); } }, // 转出供应商 'dbfindtrigger[name=vc_outvendname]':{ beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'vc_outvendid', ignore: true }, { from: 've_code', to: 'vc_outvendcode' }, { from: 've_name', to: 'vc_outvendname' }], }); } }, // 转入供应商 'dbfindtrigger[name=vc_turnvendname]':{ beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'vc_turncustid', ignore: true }, { from: 've_code', to: 'vc_turnvendcode' }, { from: 've_name', to: 'vc_turnvendname' }], }); } }, // 来源单号1 'oriOrderMutiDbfindTrigger[name=vd_slcode]': { beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'vd_slid',ignore:true }, { from: 'sl_code', to: 'vd_slcode' },{ from: 'sl_orderamount', to: 'vd_amount' },{ from: 'sl_yamount', to: 'sl_yamount' },{ from: 'sl_namount', to: 'sl_namount' },{ from:'sl_date', to:'vd_sldate' },{ from:'sl_kind', to:'vd_slkind' },{ from: 'sl_namount', to: 'vd_nowbalance' }], }); }, beforequery: function(f) { var defaultCondition = this.getDefaultCondition(0); if(!defaultCondition) { return false; } Ext.apply(f, { defaultCondition: defaultCondition }); }, beforetriggerclick: function(f) { var defaultCondition = this.getDefaultCondition(0); if(!defaultCondition) { return false; } Ext.apply(f, { defaultCondition: defaultCondition }); } }, // 来源单号2 'oriOrderMutiDbfindTrigger[name=vcd_slcode]': { beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'vcd_slid',ignore:true }, { from: 'sl_code', to: 'vcd_slcode' },{ from: 'sl_orderamount', to: 'vcd_amount' },{ from: 'sl_yamount', to: 'sl_yamount' },{ from: 'sl_namount', to: 'sl_namount' },{ from:'sl_date', to:'vcd_sldate' },{ from:'sl_kind', to:'vcd_slkind' },{ from: 'sl_namount', to: 'vcd_nowbalance' }], }); }, beforequery: function(f) { var defaultCondition = this.getDefaultCondition(1); if(!defaultCondition) { return false; } Ext.apply(f, { defaultCondition: defaultCondition }); }, beforetriggerclick: function(f) { var defaultCondition = this.getDefaultCondition(1); if(!defaultCondition) { return false; } Ext.apply(f, { defaultCondition: defaultCondition }); } }, }); }, getDefaultCondition: function(idx) { var me = this, form = me.getView(), formItems = form.formItems, viewModel = me.getViewModel(), acitveType = form.acitveType, etc = form.etc, defaultConditions = etc.defaultConditions, defaultConditionMode = defaultConditions[acitveType][idx]; var reg = /(.*){(.*)}(.*)/g; var fieldName = defaultConditionMode.match(/(.*){(.*)}(.*)/)[2]; var fieldLabel = Ext.Array.findBy(formItems, function(f) { return f.name == fieldName; }).fieldLabel; var fieldValue = viewModel.get(fieldName); if(!fieldValue) { saas.util.BaseUtil.showErrorToast('请先录入主表字段【' + '' + fieldLabel + '】'); return null; } var defaultCondition = defaultConditionMode.replace(reg, '$1' + fieldValue + '$3'); return defaultCondition; }, /** * 清空所有从表数据 */ clearDetails: function() { var me = this; me.clearDetail0(); me.clearDetail1(); }, /** * 清空第一个从表数据 */ clearDetail0: function(f, n, o) { var me = this, form = me.getView(), grid = form.query('detailGridField')[0]; me.clearDetail(grid); }, /** * 清空第二个从表数据 */ clearDetail1: function() { var me = this, form = me.getView(), grid = form.query('detailGridField')[1]; me.clearDetail(grid); }, /** * 清空一个从表数据 */ clearDetail: function(grid) { var datas = [], emptyRows = grid.emptyRows, detnoColumn = grid.detnoColumn, detno = 0, store = grid.getStore(); Ext.Array.each(new Array(emptyRows), function() { detno += 1; var data = {}; data[detnoColumn] = detno; datas.push(data); }) store.removeAll(); store.add(datas); }, onSave: function() { var me = this, form = me.getView(), viewModel = me.getViewModel(), store1 = viewModel.get('detail0').detailStore, store2 = viewModel.get('detail1').detailStore; var valid = form.isValid(); if(!valid) { saas.util.BaseUtil.showErrorToast(form.invalidText); return false; } var sum_detail1 = store1.sum('vd_nowbalance'); // 从表1核销合计 var sum_detail2 = store2.sum('vcd_nowbalance'); // 从表2核销合计 viewModel.set("vc_amount1",sum_detail1); viewModel.set("vc_amount2",sum_detail2); me.save(); }, });