| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.fa.VoucherStyle', {
- extend: 'Ext.app.Controller',
- FormUtil: Ext.create('erp.util.FormUtil'),
- GridUtil: Ext.create('erp.util.GridUtil'),
- views: ['fa.VoucherStyle', 'core.form.Panel', 'core.grid.Panel2', 'core.grid.YnColumn', 'core.trigger.TextAreaTrigger',
- 'core.trigger.DbfindTrigger','core.button.Sync',
- 'core.button.Close', 'core.button.Save', 'core.button.Update'],
- init:function(){
- var me = this;
- this.control({
- 'erpGridPanel2': {
- itemclick: function(selModel, record) {
- me.GridUtil.onGridItemClick(selModel, record);
- var btn = Ext.getCmp('assdetail');
- var ass = record.data['ca_asstype'],
- check = record.data['vd_checkitem'];
- if(!Ext.isEmpty(ass) || check == -1){
- btn.setDisabled(false);
- } else {
- btn.setDisabled(true);
- }
- }
- },
- 'erpDeleteDetailButton': {
- afterrender: function(btn){
- //辅助核算
- btn.ownerCt.add({
- text: '辅助核算',
- width: 85,
- disabled: true,
- cls: 'x-btn-blue',
- id: 'assdetail'
- });
- }
- },
- 'erpSaveButton': {
- click: function(btn){
- me._beforeSave();
- me.beforeSave();
- }
- },
- 'erpUpdateButton': {
- click: function(btn){
- me._beforeSave();
- me.beforeUpdate();
- }
- },
- 'button[id=assdetail]': {
- click: function(btn){
- var grid = btn.ownerCt.ownerCt;
- var record = grid.selModel.lastSelected;
- if(record){
- var id = record.get('vd_id') || (-grid.store.indexOf(record));
- var win = Ext.getCmp('ass-' + id);
- if(win) {
- win.show();
- } else {
- var grid = Ext.create('Ext.grid.Panel', {
- anchor: '100% 100%',
- columns: [{
- text: 'ID',
- hidden: true,
- dataIndex: 'vsa_id'
- },{
- text: 'VD_ID',
- hidden: true,
- dataIndex: 'vsa_vdid'
- },{
- text: '核算项',
- dataIndex: 'vsa_assname',
- flex: 1,
- editor: {
- xtype: 'dbfindtrigger'
- },
- dbfind: 'AssKind|ak_name'
- },{
- text: '编号表达式',
- dataIndex: 'vsa_codefield',
- flex: 1,
- editor: {
- xtype: 'textfield'
- }
- },{
- text: '名称表达式',
- dataIndex: 'vsa_namefield',
- flex: 1,
- editor: {
- xtype: 'textfield'
- }
- }],
- store: new Ext.data.Store({
- fields: [{name: 'vsa_id', type: 'number'}, {name: 'vsa_vdid', type: 'number'},
- {name: 'vsa_assname', type: 'string'}, {name: 'vsa_codefield', type: 'string'},
- {name: 'vsa_namefield', type: 'string'}]
- }),
- columnLines: true,
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1
- })],
- dbfinds: [{
- field: 'vsa_assname',
- dbGridField: 'ak_name'
- }],
- listeners: {
- itemclick: function(selModel, record) {
- var grid = selModel.ownerCt,
- store = grid.store,
- idx = store.indexOf(record),
- len = store.getCount();
- if(idx == len - 1) {
- store.add({}, {}, {}, {}, {});
- }
- }
- }
- });
- win = Ext.create('Ext.Window', {
- width: 500,
- height: 360,
- layout: 'anchor',
- title: '辅助核算公式',
- items: [grid],
- buttonAlign: 'center',
- modal: true,
- buttons: [{
- text: $I18N.common.button.erpConfirmButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- var win = btn.ownerCt.ownerCt,
- grid = Ext.getCmp('grid'),
- record = grid.selModel.lastSelected,
- ass = win.down('gridpanel');
- var data = new Array();
- ass.store.each(function(item){
- data.push(item.data);
- });
- if(data.length > 0){
- me.cacheStore[record.data[grid.keyField] || (-record.index)] = data;
- }
- win.hide();
- }
- },{
- text: $I18N.common.button.erpOffButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- btn.ownerCt.ownerCt.hide();
- }
- }]
- }).show();
- }
- me.getAss(win.down('gridpanel'), id, record.get('ca_assname'));
- }
- }
- },
- 'field[name=vd_catecode]': {
- aftertrigger: function(f, d) {
- var record = f.record,
- ass = d.get('ca_asstype');
- if(!Ext.isEmpty(ass)) {
- record.set('vd_checkitem', -1);
- } else {
- record.set('vd_checkitem', 0);
- }
- }
- }
- });
- },
- _beforeSave: function() {
- var grid = Ext.getCmp('grid'),
- code = Ext.getCmp('vs_code').value;
-
- // Ext.each(grid.store.data.items,function(item,index){
- //
- // if(item.data['vd_class']==''){
- // item.data['vd_code']=code;
- // }
- //
- // });
-
- grid.store.each(function(d){
- if(!Ext.isEmpty(d.get('vd_class'))) {
- d.set('vd_code', code);
- }
- });
- },
- cacheStore: new Array(),
- getAss: function(grid, id, assname) {
- var me = this;
- if(!me.cacheStore[id]){
- if(id == null || id <= 0){
- var data = new Array(),r = assname.join('#');
- for(var i=0;i<r.length;i++){
- var o = new Object();
- o.vsa_vdid = id;
- o.vsa_assname = r[i];
- data.push(o);
- }
- grid.store.loadData(data);
- } else {
- var condition = "vsa_vdid=" + id;
- Ext.Ajax.request({
- url : basePath + 'common/getFieldsDatas.action',
- params: {
- caller: "VoucherStyleAss",
- fields: 'vsa_id,vsa_vdid,vsa_assname,vsa_codefield,vsa_namefield',
- condition: condition
- },
- method : 'post',
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- if(res.exception || res.exceptionInfo){
- showError(res.exceptionInfo);
- return;
- }
- var data = Ext.decode(res.data);
- var dd = new Array(),r = assname.split('#');
- Ext.Array.each(data, function(d){
- var o = new Object();
- o.vsa_id = d.VSA_ID;
- o.vsa_vdid = d.VSA_VDID;
- o.vsa_assname = d.VSA_ASSNAME;
- o.vsa_codefield = d.VSA_CODEFIELD;
- o.vsa_namefield = d.VSA_NAMEFIELD;
- dd.push(o);
- });
- for(var i = 0; i < r.length; i++){
- if(!Ext.isEmpty(r[i])) {
- var bool = false;
- Ext.Array.each(data, function(d){
- if(d.VSA_ASSNAME == r[i]) {
- bool = true;
- }
- });
- if(!bool) {
- var o = new Object();
- o.vsa_vdid = id;
- o.vsa_assname = r[i];
- dd.push(o);
- }
- }
- }
- if(dd.length == 0) {
- dd = [{}, {}, {}, {}, {}];
- }
- grid.store.loadData(dd);
- }
- });
- }
- } else {
- grid.store.loadData(me.cacheStore[id]);
- }
- },
- beforeSave: function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
- me.FormUtil.getSeqId(form);
- }
- var detail = Ext.getCmp('grid');
- var param2 = new Array();
- Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
- Ext.each(me.cacheStore[key], function(d){
- d['vsa_vdid'] = key;
- param2.push(d);
- });
- });
- Ext.each(detail.store.data.items, function(item){
- if(item.data.vd_id == null || item.data.vd_id == 0){
- item.data.vd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- if(detail.necessaryField.length > 0 && (param1.length == 0)){
- showError($I18N.common.grid.emptyDetail);
- return;
- }
- me.onSave(form, param1, param2);
- },
- onSave: function(form, param1, param2) {
- var me = this;
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- // param3 = param3 == null ? [] : param3.toString().replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- me.FormUtil.save(form.getValues(), param1, param2);
- }else{
- me.FormUtil.checkForm();
- }
- },
- beforeUpdate: function(){
- var me = this;
- var form = Ext.getCmp('form');
- if(! me.FormUtil.checkForm()){
- return;
- }
- var detail = Ext.getCmp('grid');
- Ext.each(detail.store.data.items, function(item){
- if(item.data.vd_id == null || item.data.vd_id == 0){
- item.data.vd_id = -item.index;
- }
- });
- var param1 = me.GridUtil.getGridStore(detail);
- var param2 = new Array();
- Ext.each(Ext.Object.getKeys(me.cacheStore), function(key){
- Ext.each(me.cacheStore[key], function(d){
- d['vsa_vdid'] = key;
- param2.push(d);
- });
- });
- if(me.FormUtil.checkFormDirty(form) == '' && detail.necessaryField.length > 0 && (param1.length == 0)
- && param2.length == 0){
- showError($I18N.common.grid.emptyDetail);
- return;
- } else {
- param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
- param2 = param2 == null ? [] : Ext.encode(param2).replace(/\\/g,"%");
- if(form.getForm().isValid()){
- Ext.each(form.items.items, function(item){
- if(item.xtype == 'numberfield'){
- if(item.value == null || item.value == ''){
- item.setValue(0);
- }
- }
- });
- me.FormUtil.update(form.getValues(), param1, param2);
- }else{
- me.FormUtil.checkForm();
- }
- }
- }
- });
|