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,{ dbColumns: [{ conditionCode: 'id', text: "客户ID", dataIndex: "id", hidden:true, xtype: "", }, { conditionCode: 'cu_code', text: "客户编号", dataIndex: "cu_code", width: 150, xtype: "", }, { conditionCode: 'cu_name', text: "客户名称", dataIndex: "cu_name", width: 200, xtype: "", }, { conditionCode: 'cu_type', text: "客户类型", dataIndex: "cu_type", width: 110, xtype: "", }, { text: "业务员编号", dataIndex: "cu_sellercode", width:110 }, { text: "业务员", dataIndex: "cu_sellername", width:110 }, { text: "税率", dataIndex: "cu_taxrate", xtype: 'numbercolumn', width:80, renderer: function (v) { return Ext.util.Format.number(v, '0'); } },{ text: "应收款余额", dataIndex: "cu_leftamount", width:110, xtype: 'numbercolumn', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } }, { text: "结算天数", dataIndex: "cu_promisedays", width:110, xtype: 'numbercolumn', renderer: function (v) { return Ext.util.Format.number(v, '0'); } }, { text: "额度", dataIndex: "cu_credit", width:110, xtype: 'numbercolumn', }, { text: "客户地址", dataIndex: "ca_address", width: 250 }], //赋值 dbfinds:[{ from: 'id', to: 'vc_custid',ignore:true }, { from:'cu_code', to:'vc_custcode' },{ from:'cu_name', to:'vc_custname' }], }) ; } }, // 转入客户 'dbfindtrigger[name=vc_turncustname]':{ beforerender:function(f){ Ext.apply(f,{ dbColumns: [{ conditionCode: 'id', text: "客户ID", dataIndex: "id", hidden:true, xtype: "", }, { conditionCode: 'cu_code', text: "客户编号", dataIndex: "cu_code", width: 150, xtype: "", }, { conditionCode: 'cu_name', text: "客户名称", dataIndex: "cu_name", width: 200, xtype: "", }, { conditionCode: 'cu_type', text: "客户类型", dataIndex: "cu_type", width: 110, xtype: "", }, { text: "业务员编号", dataIndex: "cu_sellercode", width:110 }, { text: "业务员", dataIndex: "cu_sellername", width:110 }, { text: "税率", dataIndex: "cu_taxrate", xtype: 'numbercolumn', width:80, renderer: function (v) { return Ext.util.Format.number(v, '0'); } },{ text: "应收款余额", dataIndex: "cu_leftamount", width:110, xtype: 'numbercolumn', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } }, { text: "结算天数", dataIndex: "cu_promisedays", width:110, xtype: 'numbercolumn', renderer: function (v) { return Ext.util.Format.number(v, '0'); } }, { text: "额度", dataIndex: "cu_credit", width:110, xtype: 'numbercolumn', }, { text: "客户地址", dataIndex: "ca_address", width: 250 }], //赋值 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, { dbColumns:[{ text: "供应商ID", hidden: true, dataIndex: "id", xtype: "numbercolumn" },{ text: "供应商编号", dataIndex: "ve_code", width: 150 }, { text: "供应商名称", dataIndex: "ve_name", width: 200 }, { text: "供应商类型", dataIndex: "ve_type", width: 110, }, { text: "税率", dataIndex: "ve_taxrate", width: 80, xtype: 'numbercolumn', align:'end', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } }, { text: "应付款余额", dataIndex: "ve_leftamount", width:110, xtype: 'numbercolumn', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } },{ text: "结算天数", dataIndex: "ve_promisedays", width: 110, xtype: 'numbercolumn', align: 'end', renderer : function(v) { return Ext.util.Format.number(v, '0'); } }, { text: "纳税人识别号", dataIndex: "ve_nsrzh", width: 150 }, { text: "开户银行", dataIndex: "ve_bankcode", width: 150 }, { text: "银行账户", dataIndex: "ve_bankaccount", width: 200 }], dbfinds: [{ from: 'id', to: 'vc_vendid', ignore: true }, { from: 've_code', to: 'vc_vendcode' }, { from: 've_name', to: 'vc_vendname' }], }); } }, // 转入供应商 'dbfindtrigger[name=vc_turnvendname]':{ beforerender: function (f) { Ext.apply(f, { dbColumns:[{ text: "供应商ID", hidden: true, dataIndex: "id", xtype: "numbercolumn" },{ text: "供应商编号", dataIndex: "ve_code", width: 150 }, { text: "供应商名称", dataIndex: "ve_name", width: 200 }, { text: "供应商类型", dataIndex: "ve_type", width: 110, }, { text: "税率", dataIndex: "ve_taxrate", width: 80, xtype: 'numbercolumn', align:'end', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } }, { text: "应付款余额", dataIndex: "ve_leftamount", width:110, xtype: 'numbercolumn', renderer : function(v) { if(!v) { return 0; } var arr = (v + '.').split('.'); var xr = (new Array(arr[1].length > 3 ? 3 : arr[1].length)).fill('0'); var format = '0.' + xr.join(); return Ext.util.Format.number(v, format); } },{ text: "结算天数", dataIndex: "ve_promisedays", width: 110, xtype: 'numbercolumn', align: 'end', renderer : function(v) { return Ext.util.Format.number(v, '0'); } }, { text: "纳税人识别号", dataIndex: "ve_nsrzh", width: 150 }, { text: "开户银行", dataIndex: "ve_bankcode", width: 150 }, { text: "银行账户", dataIndex: "ve_bankaccount", width: 200 }], dbfinds: [{ from: 'id', to: 'vc_turnvendid', 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); // 不写该方法合计列会错位,这里触发afterEdit事件用来刷新grid store.getAt(0) ? store.afterEdit(store.getAt(0), ['']) : null; }, 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(); }, save:function(){ var me = this, form = this.getView(), detailCount = form.detailCount, viewModel = me.getViewModel(), modelData = viewModel.getData(); //form里面数据 var formData = form.getDirtyData(); var params = { main:formData.main }; for(var i = 0; i < detailCount; i++) { params['items' + ( i + 1)] = formData['detail' + i]; } form.setLoading(true); saas.util.BaseUtil.request({ url: form._saveUrl, params: JSON.stringify(params), method: 'POST', }) .then(function(localJson) { form.setLoading(false); if(localJson.success){ var id = localJson.data.id; var code = localJson.data.code; form.initId = id; saas.util.FormUtil.loadData(form); saas.util.BaseUtil.showSuccessToast('保存成功'); var newId = form.xtype + '-' + id; var newTitle = form._title + '(' + code + ')'; saas.util.BaseUtil.refreshTabTitle(newId, newTitle); form.fireEvent('aftersave', true, form, localJson); } }) .catch(function(res) { form.setLoading(false); console.error(res); saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message); form.fireEvent('aftersave', false, form, res); }); }, audit: function() { var me = this, form = me.getView(), viewModel = me.getViewModel(), detailCount = form.detailCount, modelData = viewModel.getData(); //form里面数据 var formData = form.getFormData(); var params = { main: formData.main }; for(var i = 0; i < detailCount; i++) { params['items' + ( i + 1)] = formData['detail' + i]; } form.setLoading(true); saas.util.BaseUtil.request({ url: form._auditUrl, params: JSON.stringify(params), method: 'POST', }) .then(function(localJson) { form.setLoading(false); if(localJson.success){ // 未保存直接审核会返回id if(localJson.data) { var id = localJson.data.id; var code = localJson.data.code; form.initId = id; var newId = form.xtype + '-' + id; var newTitle = form._title + '(' + code + ')'; saas.util.BaseUtil.refreshTabTitle(newId, newTitle); } saas.util.FormUtil.loadData(form); form.setEditable(false); saas.util.BaseUtil.showSuccessToast('审核成功' + (localJson.message ? ': ' + localJson.message : '')); form.fireEvent('afteraudit', true, form, localJson); } }) .catch(function(res) { form.setLoading(false); console.error(res); if(res.data) { var id = localJson.data.id; var code = localJson.data.code; form.initId = id; var newId = form.xtype + '-' + id; var newTitle = form._title + '(' + code + ')'; saas.util.BaseUtil.refreshTabTitle(newId, newTitle); saas.util.FormUtil.loadData(form); } saas.util.BaseUtil.showErrorToast('审核失败: ' + res.message); form.fireEvent('afteraudit', false, form, res); }); }, myInitCopyData: function(formData) { var me = this, form = me.getView(); //录入人,录入日期,审核人,审核日期清空 formData.main['creatorId'] = saas.util.BaseUtil.getCurrentUser().id; formData.main['creatorName'] = saas.util.BaseUtil.getCurrentUser().realname; formData.main['createTime'] = Ext.Date.format(new Date(), 'Y-m-d H:i:s'); formData.main['updaterId'] = undefined; formData.main['updaterName'] = undefined; formData.main['updateTime'] = undefined; formData.main[form._auditmanField] = undefined; formData.main[form._auditdateField] = undefined; return formData; } });