Ext.define('saas.view.money.recBalance.FormPanelController', { extend: 'saas.view.core.form.FormPanelController', alias: 'controller.money-recbalance-formpanel', init: function (form) { var me = this; this.control({ 'dbfindtrigger[name=rb_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: 'rb_custid',ignore:true }, { from:'cu_code', to:'rb_custcode' },{ from:'cu_name', to:'rb_custname' },{ from:'cu_leftamount', to:'cu_leftamount' }], }) ; } }, 'dbfindtrigger[name=rd_bankname]':{ beforerender:function(f){ Ext.apply(f,{ //赋值 dbfinds:[{ from: 'id', to: 'rd_bankid',ignore:true }, { from:'bk_bankcode', to:'rd_bankcode' },{ from:'bk_bankname', to:'rd_bankname' }], }) ; } }, 'oriOrderMutiDbfindTrigger[name=rbd_slcode]': { beforerender: function (f) { Ext.apply(f, { dbfinds: [{ from: 'id', to: 'rbd_slid',ignore:true }, { from: 'sl_code', to: 'rbd_slcode' },{ from: 'sl_orderamount', to: 'rbd_amount' },{ from: 'sl_yamount', to: 'sl_yamount' },{ from: 'sl_namount', to: 'sl_namount' },{ from:'sl_date', to:'rbd_sldate' },{ from:'sl_kind', to:'rbd_slkind' },{ from: 'sl_namount', to: 'rbd_nowbalance' }], defaultCondition: "sl_custid<>0 and sl_kind in ('期初余额','出货单','销售退货单') and sl_namount<>0" }); } }, }); }, addCombo:function(){ var combo=this.ownerCmp; Ext.create('Ext.window.Window',{ layout:'vbox', bodyPadding: 15, width:500, items:[{ fieldLabel:'实际值', xtype:'textfield' },{ fieldLabel:'显示值', xtype:'textfield' }], buttons:[{ text:'确认', handler:function(b){ combo.setValue('ok'); b.up('window').close(); } }], renderTo:this.ownerCmp.ownerCt.getEl() }).show(); }, turnIn: function() { var me = this, form = me.getView(), id = form.getForm().findField(form._idField); saas.util.BaseUtil.request({ url: form._turnInUrl+id.value, method: 'GET', }) .then(function(localJson) { if(localJson.success){ saas.util.BaseUtil.showSuccessToast('转单成功'); } }) .catch(function(res) { console.error(res); saas.util.BaseUtil.showErrorToast('转单失败: ' + res.message); }); }, 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_rd_amount = store1.sum('rd_amount'); // 付款金额合计 var rb_discounts = viewModel.get('rb_discounts'); // 折扣金额 var sum_rbd_nowbalance = store2.sum('rbd_nowbalance'); // 本次核销金额合计 var flag = sum_rd_amount + rb_discounts - sum_rbd_nowbalance; viewModel.set("rb_preamount",flag); if(flag != 0) { var t = flag > 0 ? '大' : '小'; saas.util.BaseUtil.showConfirm('提示', '收款金额' + t + '于本次核销金额,是否仍要保存?') .then(function(y) { if(y == 'yes') { me.save(); } }); }else { me.save(); } }, custnamechange:function(dbfindtrigger){ var me = this, viewModel = me.getViewModel(); var c = viewModel.get('rb_custname_change'); if(c!=null&&c!=''){ c = ' and sl_custid='+c; }else{ c =''; } dbfindtrigger.defaultCondition = "sl_custid<>0 and sl_kind in ('期初余额','出货单','销售退货单') and sl_namount<>0" + c; }, myInitCopyData: function(formData) { var main = formData.main; main.rb_auditman = ''; main.rb_auditdate = null; return formData; } });