Ext.QuickTips.init(); Ext.define('erp.controller.ma.logic.LogicSetup', { extend: 'Ext.app.Controller', requires: ['erp.util.FormUtil', 'erp.util.DrawUtil'], stores: ['TreeStore'],//声明该控制层要用到的store views: ['common.main.TreePanel','ma.logic.LogicSetup','core.button.Sync', 'common.main.Toolbar','core.trigger.SearchField', 'core.trigger.DbfindTrigger'],//声明该控制层要用到的view init: function(){ var me = this; me.FormUtil = Ext.create('erp.util.FormUtil'); me.DrawUtil = Ext.create('erp.util.DrawUtil'); this.flag = true;//防止双击时tree节点重复加载 this.control({ 'erpTreePanel': { itemmousedown: function(selModel, record){ if(!this.flag){ return; } this.flag = false; setTimeout(function(){ me.flag = true; me.loadTab(selModel, record); },20);//防止双击时tree节点重复加载 }, itemclick: function(selModel, record){ if(!this.flag){ return; } this.flag = false; setTimeout(function(){ me.flag = true; me.loadTab(selModel, record); },20); }, itemdbclick: function(selModel, record){ if(!this.flag){ return; } this.flag = false; setTimeout(function(){ me.flag = true; me.loadTab(selModel, record); },20); }, afterrender: function(){ } }, 'button[id=close]': { click: function(){ var p = parent.Ext.getCmp('content-panel'); if(p){ p.getActiveTab().close(); } else { window.close(); } } }, 'button[id=save]': { click: function(btn){ var add = me.getAdd(), update = me.getUpdated(), del = me.getDeleted(); if(add.length > 0 || update.length > 0 || del.length > 0) { me.save(add, update, del); } } } }); }, loadTab: function(selModel, record){ var me = this; me.showPath(record); if (record.get('leaf')) { var cal = record.get('caller'); if(!Ext.isEmpty(cal)) { if(cal != me.caller) { me.getLogicSet(cal); } } else { var p = Ext.getCmp('centerpanel'); p.removeAll(); me.data = new Array(); me.caller = null; } } else { if(record.isExpanded() && record.childNodes.length > 0){//是根节点,且已展开 record.collapse(true,true);//收拢 me.flag = true; } else {//未展开 //看是否加载了其children if(record.childNodes.length == 0){ //从后台加载 var tree = Ext.getCmp('tree-panel'), condition = tree.baseCondition; tree.setLoading(true, tree.body); Ext.Ajax.request({//拿到tree数据 url : basePath + 'common/lazyTree.action', params: { parentId: record.data['id'], condition: condition }, callback : function(options,success,response){ tree.setLoading(false); var res = new Ext.decode(response.responseText); if(res.tree){ record.appendChild(res.tree); record.expand(false, true);//展开 me.flag = true; } else if(res.exceptionInfo){ showError(res.exceptionInfo); me.flag = true; } } }); } else { record.expand(false,true);//展开 me.flag = true; } } } }, showPath: function(record){ var p = Ext.getCmp('centerpanel'); p.setTitle(record.getPath('text', '->').replace('root', '导航')); }, getLogicSet: function(cal){ var me = this; Ext.Ajax.request({ url : basePath + 'common/datalist.action', params: { caller: 'DocumentHandler', condition: 'ls_caller=\'' + cal + '\'', page: 1, pageSize: 1000 }, 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 = res.data; if(data && data.length > 2) { me.data = Ext.decode(data); me.caller = cal; me.drawLogicSet(); } else { showMessage('当前无逻辑配置.'); } } }); }, imageTag: basePath + 'resource/images/16/', drawLogicSet: function(){ var p = Ext.getCmp('centerpanel'), items = this.getItems(); p.removeAll(); p.add(this.DrawUtil.batchDraw(items)); }, methods: [{ name: 'save', value: '保存' }, { name: 'commit', value: '提交' }, { name: 'resCommit', value: '反提交' }, { name: 'audit', value: '审核' }, { name: 'resAudit', value: '反审核' }, { name: 'post', value: '过账' }, { name: 'resPost', value: '反过账' }, { name: 'print', value: '打印' }, { name: 'turnout', value: '抛转' }, { name: 'turn', value: '转单' }, { name: 'deletedetail', value: '删除明细' }, { name: 'delete', value: '删除' }], selData: function(method, turn){ var dt = new Array(); Ext.each(this.data, function(d){ if (d.ls_mtype == method && d.ls_turn == turn && 'delete' != d.status) { dt.push(d); } }); Ext.Array.sort(dt, function(a, b){ return a.dh_detno > b.dh_detno; }); return dt; }, getMethods: function(){ var da = this.data, methods = new Array(), arr = Ext.Array.unique(Ext.Array.pluck(da, 'ls_mtype')); Ext.each(this.methods, function(m){ if(Ext.Array.contains(arr, m.name)) { methods.push(m); } }); return methods; }, getItems: function(){ var me = this,x = 60,y = 0, methods = this.getMethods(); var cmp = new Array(), dt = new Array(), len = 50, ph = 0; y += 10; cmp.push({type: 'arrow', args: [0, 10, 60, 'r', 'gray', 'gray', '方法', 'center']}); cmp.push({type: 'arrow', args: [60, y, 300, 'r', 'gray', 'gray', '功能描述', 'center']}); cmp.push({type: 'arrow', args: [340, y, 300, 'r', 'gray', 'gray', '逻辑类.方法', 'center']}); cmp.push({type: 'arrow', args: [640, y, 200, 'r', 'gray', 'gray', '最近修改信息', 'center']}); cmp.push({type: 'arrow', args: [840, y, 50, 'r', 'gray', 'gray']}); cmp.push({type: 'arrow', args: [890, y, 150, 'r', 'gray', 'gray', '启用.添加.删除.编辑', 'center']}); Ext.each(methods, function(m){ ph = 0; dt = me.selData(m.name, 0); if(dt.length == 0) { var de = me.getDeletedByType(m.name, 0); if(de.length > 0) { me.addCmp(cmp, { ls_mtype: de[0].ls_mtype, ls_turn: de[0].ls_turn, ls_caller: de[0].ls_caller, ls_arg: de[0].ls_arg, dh_detno : 0, dh_isuse: 0, dh_id: de[0].dh_id }, x, y - 8 + len/2); } else { cmp.push({type: 'text', args: [60, y + len/2, '无法配置' + m.value + '前逻辑', 'red']}); } } else if(dt.length == 1 && dt[0].dh_id == null || dt[0].dh_id == '') { dt[0].dh_id = -new Date().getTime(); dt[0].dh_detno = 0; dt[0].status = 'ignore'; me.addCmp(cmp, dt[0], x, y - 8 + len/2); } else { Ext.each(dt, function(d){ if('delete' != d.status && 'ignore' != d.status) { ph += len; me.insertRow(cmp, d, x, y + ph); cmp.push({type: 'text', args: [0, y + ph, m.value + '前', 'gray']}); } }); } ph += len; cmp.push({type: 'arrow', args: [x, y, ph, 'b', 'gray', null]}); y += ph; cmp.push({type: 'dotted', args: [0, y + 15, 1040, 'gray', 'gray']}); cmp.push({type: 'rect', args: [x - 30, y, 60, 30, '#CDC1C5', m.value]}); if(dt.length > 0) { cmp.push({type: 'text', args: [x + 30, y , m.value + '前传递参数: ' + dt[0].ls_arg, 'gray']}); } y += 30; ph = 0; dt = me.selData(m.name, 1); if(dt.length > 0) { cmp.push({type: 'text', args: [x + 30, y, m.value + '后传递参数: ' + dt[0].ls_arg, 'gray']}); } if(dt.length == 0) { var de = me.getDeletedByType(m.name, 1); if(de.length > 0) { me.addCmp(cmp, { ls_mtype: de[0].ls_mtype, ls_turn: de[0].ls_turn, ls_caller: de[0].ls_caller, ls_arg: de[0].ls_arg, dh_detno : 0, dh_isuse: 0, dh_id: de[0].dh_id }, x, y - 8 + len/2); } else { cmp.push({type: 'text', args: [60, y + len/2, '无法配置' + m.value + '后逻辑', 'red']}); } } else if(dt.length == 1 && dt[0].dh_id == null || dt[0].dh_id == '') { dt[0].dh_id = -new Date().getTime(); dt[0].dh_detno = 0; dt[0].status = 'ignore'; me.addCmp(cmp, dt[0], x, y - 8 + len/2); } else { Ext.each(dt, function(d){ if('delete' != d.status && 'ignore' != d.status) { ph += len; me.insertRow(cmp, d, x, y + ph); cmp.push({type: 'text', args: [0, y + ph, m.value + '后', 'gray']}); } }); } ph += len; cmp.push({type: 'arrow', args: [x, y, ph, 'b', 'gray', null]}); y += ph; cmp.push({type: 'arrow', args: [0, y, 1040, 'r', 'gray', 'gray']}); }); return cmp; }, getDeleted: function(){ var me = this,da = me.data,arr = new Array(); Ext.each(da, function(d){ if('delete' == d.status) { arr.push(d); } }); return arr; }, getDeletedByType: function(type, turn){ var me = this,da = me.data,arr = new Array(); Ext.each(da, function(d){ if(d.ls_mtype == type && d.ls_turn == turn && 'delete' == d.status) { arr.push(d); } }); return arr; }, getAdd: function(){ var me = this,da = me.data,arr = new Array(); Ext.each(da, function(d){ if('add' == d.status) { arr.push(d); } }); return arr; }, getUpdated: function(){ var me = this,da = me.data,arr = new Array(); Ext.each(da, function(d){ if('update' == d.status) { arr.push(d); } }); return arr; }, insertRow: function(cmp, d, x, y){ var me = this,color = 'gray'; if(d.status == null) { color = 'black'; } cmp.push({type: 'arrow', args: [x, y, 300, 'r', color, null, d.dh_detno + '.' + d.dh_description]}); cmp.push({type: 'arrow', args: [x + 300, y, 300, 'r', color, null, d.dh_classname + '.' + d.dh_methodname]}); cmp.push({type: 'arrow', args: [x + 600, y, 200, 'r', color, null, d.dh_updater + ' ' + d.dh_updatedate]}); me.useCmp(cmp, d, x + 800, y); me.addCmp(cmp, d, x + 880, y); me.delCmp(cmp, d, x + 910, y); me.editCmp(cmp, d, x + 940, y); }, useCmp: function(cmp, d, x, y){ var me = this,color = 'gray', s = '已启用', src = me.imageTag + 'no.png'; if(d.dh_isuse == 1) { color = 'red', s = '未启用', src = me.imageTag + 'ok.png'; } cmp.push({type: 'arrow', args: [x, y, 50, 'r', color, null, s]}); cmp.push({type: 'image', args: [x + 50, y, 16, 16, src, d.dh_id, { click: function(img){ var d = me.indexOf(img.idx); d.dh_isuse = 1 - d.dh_isuse; if('add' != d.status) { d.status = 'update'; } me.refresh(); } }]}); }, addCmp: function(cmp, d, x, y){ var me = this, data = me.data; cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'add.png', d.dh_id, { click: function(img){ var d = me.indexOf(img.idx), rel = me.selData(d.ls_mtype, d.ls_turn); Ext.each(rel, function(r){ if(r.dh_detno > d.dh_detno) { r.dh_detno++; } }); var idx = -new Date().getTime(); data.push({ ls_id: d.ls_id, ls_mtype: d.ls_mtype, ls_turn: d.ls_turn, ls_caller: d.ls_caller, ls_arg: d.ls_arg, dh_detno : Number(d.dh_detno + 1), dh_isuse: 0, dh_lsid: d.ls_id, dh_id: idx, status: 'add' }); me.refresh(); d = me.indexOf(idx); me.showEditor(d); } }]}); }, delCmp: function(cmp, d, x, y){ var me = this; cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'del.png', d.dh_id, { click: function(img){ var d = me.indexOf(img.idx), rel = me.selData(d.ls_mtype, d.ls_turn); if('add' == d.status) { Ext.Array.remove(me.data, d); } else { d.status = 'delete'; } Ext.each(rel, function(r){ if(r.dh_detno > d.dh_detno) { r.dh_detno--; } }); me.refresh(); } }]}); }, editCmp: function(cmp, d, x, y){ var me = this; cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'edit.png', d.dh_id, { click: function(img){ var d = me.indexOf(img.idx); me.showEditor(d); } }]}); }, showEditor: function(d){ var me = this; Ext.create('Ext.Window', { width: '60%', height: '30%', autoShow: true, title: '编辑', modal: true, closeAction: 'destroy', layout: 'column', items: [{ xtype: 'textfield', fieldLabel: '类.方法', fieldStyle: 'background:#f1f1f1;', id: 'dh_classname', name: 'dh_classname', value: d.dh_classname, columnWidth: .6, readOnly: true },{ xtype: 'dbfindtrigger', id: 'dh_methodname', name: 'dh_methodname', columnWidth: .4, value: d.dh_methodname },{ xtype: 'textfield', fieldLabel: '描述', fieldStyle: 'background:#f1f1f1;', id: 'dh_description', name: 'dh_description', value: d.dh_description, columnWidth: 1, readOnly: true },{ xtype: 'hidden', id: 'dh_methodtype', name: 'dh_methodtype' }], buttonAlign: 'center', buttons: [{ text: $I18N.common.button.erpSaveButton, iconCls: 'x-button-icon-save', handler: function(btn){ var w = btn.ownerCt.ownerCt; d.dh_classname = w.down('#dh_classname').value; d.dh_methodname = w.down('#dh_methodname').value; d.dh_description = w.down('#dh_description').value; d.dh_updater = em_name; d.dh_updatecode = em_code; d.dh_updatedate = Ext.Date.format(new Date(), 'Y-m-d H:i:s'); if(w.down('#dh_methodtype').value != null) { d.dh_methodtype = w.down('#dh_methodtype').value; } if('add' != d.status) { d.status = 'update'; } me.refresh(); w.close(); } },{ text: $I18N.common.button.erpCloseButton, iconCls: 'x-button-icon-close', handler: function(btn){ btn.ownerCt.ownerCt.close(); } }] }); me.refresh(); }, indexOf: function(id){ var dd = null,da = this.data; Ext.each(da, function(d){ if (d.dh_id == id) { dd = d; } }); return dd; }, refresh: function(){ var me = this, p = Ext.getCmp('centerpanel'); p.removeAll(); me.drawLogicSet(); }, save: function(save, update, del){ var me = this; Ext.Ajax.request({ url: basePath + 'ma/logic/saveLogicSet.action', method: 'post', params: { save: unescape(Ext.JSON.encode(save).replace(/\\/g,"%")), update: unescape(Ext.JSON.encode(update).replace(/\\/g,"%")), del: unescape(Ext.JSON.encode(del).replace(/\\/g,"%")) }, callback: function(options, success, response){ var localJson = new Ext.decode(response.responseText); if(localJson.success){ alert('保存成功'); me.getLogicSet(me.caller); } } }); } });