LogicSetup.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.logic.LogicSetup', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.DrawUtil'],
  5. stores: ['TreeStore'],//声明该控制层要用到的store
  6. views: ['common.main.TreePanel','ma.logic.LogicSetup','core.button.Sync',
  7. 'common.main.Toolbar','core.trigger.SearchField', 'core.trigger.DbfindTrigger'],//声明该控制层要用到的view
  8. init: function(){
  9. var me = this;
  10. me.FormUtil = Ext.create('erp.util.FormUtil');
  11. me.DrawUtil = Ext.create('erp.util.DrawUtil');
  12. this.flag = true;//防止双击时tree节点重复加载
  13. this.control({
  14. 'erpTreePanel': {
  15. itemmousedown: function(selModel, record){
  16. if(!this.flag){
  17. return;
  18. }
  19. this.flag = false;
  20. setTimeout(function(){
  21. me.flag = true;
  22. me.loadTab(selModel, record);
  23. },20);//防止双击时tree节点重复加载
  24. },
  25. itemclick: function(selModel, record){
  26. if(!this.flag){
  27. return;
  28. }
  29. this.flag = false;
  30. setTimeout(function(){
  31. me.flag = true;
  32. me.loadTab(selModel, record);
  33. },20);
  34. },
  35. itemdbclick: function(selModel, record){
  36. if(!this.flag){
  37. return;
  38. }
  39. this.flag = false;
  40. setTimeout(function(){
  41. me.flag = true;
  42. me.loadTab(selModel, record);
  43. },20);
  44. },
  45. afterrender: function(){
  46. }
  47. },
  48. 'button[id=close]': {
  49. click: function(){
  50. var p = parent.Ext.getCmp('content-panel');
  51. if(p){
  52. p.getActiveTab().close();
  53. } else {
  54. window.close();
  55. }
  56. }
  57. },
  58. 'button[id=save]': {
  59. click: function(btn){
  60. var add = me.getAdd(),
  61. update = me.getUpdated(),
  62. del = me.getDeleted();
  63. if(add.length > 0 || update.length > 0 || del.length > 0) {
  64. me.save(add, update, del);
  65. }
  66. }
  67. }
  68. });
  69. },
  70. loadTab: function(selModel, record){
  71. var me = this;
  72. me.showPath(record);
  73. if (record.get('leaf')) {
  74. var cal = record.get('caller');
  75. if(!Ext.isEmpty(cal)) {
  76. if(cal != me.caller) {
  77. me.getLogicSet(cal);
  78. }
  79. } else {
  80. var p = Ext.getCmp('centerpanel');
  81. p.removeAll();
  82. me.data = new Array();
  83. me.caller = null;
  84. }
  85. } else {
  86. if(record.isExpanded() && record.childNodes.length > 0){//是根节点,且已展开
  87. record.collapse(true,true);//收拢
  88. me.flag = true;
  89. } else {//未展开
  90. //看是否加载了其children
  91. if(record.childNodes.length == 0){
  92. //从后台加载
  93. var tree = Ext.getCmp('tree-panel'),
  94. condition = tree.baseCondition;
  95. tree.setLoading(true, tree.body);
  96. Ext.Ajax.request({//拿到tree数据
  97. url : basePath + 'common/lazyTree.action',
  98. params: {
  99. parentId: record.data['id'],
  100. condition: condition
  101. },
  102. callback : function(options,success,response){
  103. tree.setLoading(false);
  104. var res = new Ext.decode(response.responseText);
  105. if(res.tree){
  106. record.appendChild(res.tree);
  107. record.expand(false, true);//展开
  108. me.flag = true;
  109. } else if(res.exceptionInfo){
  110. showError(res.exceptionInfo);
  111. me.flag = true;
  112. }
  113. }
  114. });
  115. } else {
  116. record.expand(false,true);//展开
  117. me.flag = true;
  118. }
  119. }
  120. }
  121. },
  122. showPath: function(record){
  123. var p = Ext.getCmp('centerpanel');
  124. p.setTitle(record.getPath('text', '->').replace('root', '导航'));
  125. },
  126. getLogicSet: function(cal){
  127. var me = this;
  128. Ext.Ajax.request({
  129. url : basePath + 'common/datalist.action',
  130. params: {
  131. caller: 'DocumentHandler',
  132. condition: 'ls_caller=\'' + cal + '\'',
  133. page: 1,
  134. pageSize: 1000
  135. },
  136. method : 'post',
  137. callback : function(options, success, response){
  138. var res = new Ext.decode(response.responseText);
  139. if(res.exception || res.exceptionInfo){
  140. showError(res.exceptionInfo);
  141. return;
  142. }
  143. var data = res.data;
  144. if(data && data.length > 2) {
  145. me.data = Ext.decode(data);
  146. me.caller = cal;
  147. me.drawLogicSet();
  148. } else {
  149. showMessage('当前无逻辑配置.');
  150. }
  151. }
  152. });
  153. },
  154. imageTag: basePath + 'resource/images/16/',
  155. drawLogicSet: function(){
  156. var p = Ext.getCmp('centerpanel'),
  157. items = this.getItems();
  158. p.removeAll();
  159. p.add(this.DrawUtil.batchDraw(items));
  160. },
  161. methods: [{
  162. name: 'save', value: '保存'
  163. }, {
  164. name: 'commit', value: '提交'
  165. }, {
  166. name: 'resCommit', value: '反提交'
  167. }, {
  168. name: 'audit', value: '审核'
  169. }, {
  170. name: 'resAudit', value: '反审核'
  171. }, {
  172. name: 'post', value: '过账'
  173. }, {
  174. name: 'resPost', value: '反过账'
  175. }, {
  176. name: 'print', value: '打印'
  177. }, {
  178. name: 'turnout', value: '抛转'
  179. }, {
  180. name: 'turn', value: '转单'
  181. }, {
  182. name: 'deletedetail', value: '删除明细'
  183. }, {
  184. name: 'delete', value: '删除'
  185. }],
  186. selData: function(method, turn){
  187. var dt = new Array();
  188. Ext.each(this.data, function(d){
  189. if (d.ls_mtype == method && d.ls_turn == turn && 'delete' != d.status) {
  190. dt.push(d);
  191. }
  192. });
  193. Ext.Array.sort(dt, function(a, b){
  194. return a.dh_detno > b.dh_detno;
  195. });
  196. return dt;
  197. },
  198. getMethods: function(){
  199. var da = this.data,
  200. methods = new Array(),
  201. arr = Ext.Array.unique(Ext.Array.pluck(da, 'ls_mtype'));
  202. Ext.each(this.methods, function(m){
  203. if(Ext.Array.contains(arr, m.name)) {
  204. methods.push(m);
  205. }
  206. });
  207. return methods;
  208. },
  209. getItems: function(){
  210. var me = this,x = 60,y = 0,
  211. methods = this.getMethods();
  212. var cmp = new Array(), dt = new Array(), len = 50, ph = 0;
  213. y += 10;
  214. cmp.push({type: 'arrow', args: [0, 10, 60, 'r', 'gray', 'gray', '方法', 'center']});
  215. cmp.push({type: 'arrow', args: [60, y, 300, 'r', 'gray', 'gray', '功能描述', 'center']});
  216. cmp.push({type: 'arrow', args: [340, y, 300, 'r', 'gray', 'gray', '逻辑类.方法', 'center']});
  217. cmp.push({type: 'arrow', args: [640, y, 200, 'r', 'gray', 'gray', '最近修改信息', 'center']});
  218. cmp.push({type: 'arrow', args: [840, y, 50, 'r', 'gray', 'gray']});
  219. cmp.push({type: 'arrow', args: [890, y, 150, 'r', 'gray', 'gray', '启用.添加.删除.编辑', 'center']});
  220. Ext.each(methods, function(m){
  221. ph = 0;
  222. dt = me.selData(m.name, 0);
  223. if(dt.length == 0) {
  224. var de = me.getDeletedByType(m.name, 0);
  225. if(de.length > 0) {
  226. me.addCmp(cmp, {
  227. ls_mtype: de[0].ls_mtype,
  228. ls_turn: de[0].ls_turn,
  229. ls_caller: de[0].ls_caller,
  230. ls_arg: de[0].ls_arg,
  231. dh_detno : 0,
  232. dh_isuse: 0,
  233. dh_id: de[0].dh_id
  234. }, x, y - 8 + len/2);
  235. } else {
  236. cmp.push({type: 'text', args: [60, y + len/2, '无法配置' + m.value + '前逻辑', 'red']});
  237. }
  238. } else if(dt.length == 1 && dt[0].dh_id == null || dt[0].dh_id == '') {
  239. dt[0].dh_id = -new Date().getTime();
  240. dt[0].dh_detno = 0;
  241. dt[0].status = 'ignore';
  242. me.addCmp(cmp, dt[0], x, y - 8 + len/2);
  243. } else {
  244. Ext.each(dt, function(d){
  245. if('delete' != d.status && 'ignore' != d.status) {
  246. ph += len;
  247. me.insertRow(cmp, d, x, y + ph);
  248. cmp.push({type: 'text', args: [0, y + ph, m.value + '前', 'gray']});
  249. }
  250. });
  251. }
  252. ph += len;
  253. cmp.push({type: 'arrow', args: [x, y, ph, 'b', 'gray', null]});
  254. y += ph;
  255. cmp.push({type: 'dotted', args: [0, y + 15, 1040, 'gray', 'gray']});
  256. cmp.push({type: 'rect', args: [x - 30, y, 60, 30, '#CDC1C5', m.value]});
  257. if(dt.length > 0) {
  258. cmp.push({type: 'text', args: [x + 30, y , m.value + '前传递参数: ' + dt[0].ls_arg, 'gray']});
  259. }
  260. y += 30;
  261. ph = 0;
  262. dt = me.selData(m.name, 1);
  263. if(dt.length > 0) {
  264. cmp.push({type: 'text', args: [x + 30, y, m.value + '后传递参数: ' + dt[0].ls_arg, 'gray']});
  265. }
  266. if(dt.length == 0) {
  267. var de = me.getDeletedByType(m.name, 1);
  268. if(de.length > 0) {
  269. me.addCmp(cmp, {
  270. ls_mtype: de[0].ls_mtype,
  271. ls_turn: de[0].ls_turn,
  272. ls_caller: de[0].ls_caller,
  273. ls_arg: de[0].ls_arg,
  274. dh_detno : 0,
  275. dh_isuse: 0,
  276. dh_id: de[0].dh_id
  277. }, x, y - 8 + len/2);
  278. } else {
  279. cmp.push({type: 'text', args: [60, y + len/2, '无法配置' + m.value + '后逻辑', 'red']});
  280. }
  281. } else if(dt.length == 1 && dt[0].dh_id == null || dt[0].dh_id == '') {
  282. dt[0].dh_id = -new Date().getTime();
  283. dt[0].dh_detno = 0;
  284. dt[0].status = 'ignore';
  285. me.addCmp(cmp, dt[0], x, y - 8 + len/2);
  286. } else {
  287. Ext.each(dt, function(d){
  288. if('delete' != d.status && 'ignore' != d.status) {
  289. ph += len;
  290. me.insertRow(cmp, d, x, y + ph);
  291. cmp.push({type: 'text', args: [0, y + ph, m.value + '后', 'gray']});
  292. }
  293. });
  294. }
  295. ph += len;
  296. cmp.push({type: 'arrow', args: [x, y, ph, 'b', 'gray', null]});
  297. y += ph;
  298. cmp.push({type: 'arrow', args: [0, y, 1040, 'r', 'gray', 'gray']});
  299. });
  300. return cmp;
  301. },
  302. getDeleted: function(){
  303. var me = this,da = me.data,arr = new Array();
  304. Ext.each(da, function(d){
  305. if('delete' == d.status) {
  306. arr.push(d);
  307. }
  308. });
  309. return arr;
  310. },
  311. getDeletedByType: function(type, turn){
  312. var me = this,da = me.data,arr = new Array();
  313. Ext.each(da, function(d){
  314. if(d.ls_mtype == type && d.ls_turn == turn && 'delete' == d.status) {
  315. arr.push(d);
  316. }
  317. });
  318. return arr;
  319. },
  320. getAdd: function(){
  321. var me = this,da = me.data,arr = new Array();
  322. Ext.each(da, function(d){
  323. if('add' == d.status) {
  324. arr.push(d);
  325. }
  326. });
  327. return arr;
  328. },
  329. getUpdated: function(){
  330. var me = this,da = me.data,arr = new Array();
  331. Ext.each(da, function(d){
  332. if('update' == d.status) {
  333. arr.push(d);
  334. }
  335. });
  336. return arr;
  337. },
  338. insertRow: function(cmp, d, x, y){
  339. var me = this,color = 'gray';
  340. if(d.status == null) {
  341. color = 'black';
  342. }
  343. cmp.push({type: 'arrow', args: [x, y, 300, 'r', color, null, d.dh_detno + '.' + d.dh_description]});
  344. cmp.push({type: 'arrow', args: [x + 300, y, 300, 'r', color, null, d.dh_classname + '.' + d.dh_methodname]});
  345. cmp.push({type: 'arrow', args: [x + 600, y, 200, 'r', color, null, d.dh_updater + ' ' + d.dh_updatedate]});
  346. me.useCmp(cmp, d, x + 800, y);
  347. me.addCmp(cmp, d, x + 880, y);
  348. me.delCmp(cmp, d, x + 910, y);
  349. me.editCmp(cmp, d, x + 940, y);
  350. },
  351. useCmp: function(cmp, d, x, y){
  352. var me = this,color = 'gray', s = '已启用', src = me.imageTag + 'no.png';
  353. if(d.dh_isuse == 1) {
  354. color = 'red', s = '未启用', src = me.imageTag + 'ok.png';
  355. }
  356. cmp.push({type: 'arrow', args: [x, y, 50, 'r', color, null, s]});
  357. cmp.push({type: 'image', args: [x + 50, y, 16, 16, src, d.dh_id, {
  358. click: function(img){
  359. var d = me.indexOf(img.idx);
  360. d.dh_isuse = 1 - d.dh_isuse;
  361. if('add' != d.status) {
  362. d.status = 'update';
  363. }
  364. me.refresh();
  365. }
  366. }]});
  367. },
  368. addCmp: function(cmp, d, x, y){
  369. var me = this,
  370. data = me.data;
  371. cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'add.png', d.dh_id, {
  372. click: function(img){
  373. var d = me.indexOf(img.idx),
  374. rel = me.selData(d.ls_mtype, d.ls_turn);
  375. Ext.each(rel, function(r){
  376. if(r.dh_detno > d.dh_detno) {
  377. r.dh_detno++;
  378. }
  379. });
  380. var idx = -new Date().getTime();
  381. data.push({
  382. ls_id: d.ls_id,
  383. ls_mtype: d.ls_mtype,
  384. ls_turn: d.ls_turn,
  385. ls_caller: d.ls_caller,
  386. ls_arg: d.ls_arg,
  387. dh_detno : Number(d.dh_detno + 1),
  388. dh_isuse: 0,
  389. dh_lsid: d.ls_id,
  390. dh_id: idx,
  391. status: 'add'
  392. });
  393. me.refresh();
  394. d = me.indexOf(idx);
  395. me.showEditor(d);
  396. }
  397. }]});
  398. },
  399. delCmp: function(cmp, d, x, y){
  400. var me = this;
  401. cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'del.png', d.dh_id, {
  402. click: function(img){
  403. var d = me.indexOf(img.idx),
  404. rel = me.selData(d.ls_mtype, d.ls_turn);
  405. if('add' == d.status) {
  406. Ext.Array.remove(me.data, d);
  407. } else {
  408. d.status = 'delete';
  409. }
  410. Ext.each(rel, function(r){
  411. if(r.dh_detno > d.dh_detno) {
  412. r.dh_detno--;
  413. }
  414. });
  415. me.refresh();
  416. }
  417. }]});
  418. },
  419. editCmp: function(cmp, d, x, y){
  420. var me = this;
  421. cmp.push({type: 'image', args: [x, y, 16, 16, me.imageTag + 'edit.png', d.dh_id, {
  422. click: function(img){
  423. var d = me.indexOf(img.idx);
  424. me.showEditor(d);
  425. }
  426. }]});
  427. },
  428. showEditor: function(d){
  429. var me = this;
  430. Ext.create('Ext.Window', {
  431. width: '60%',
  432. height: '30%',
  433. autoShow: true,
  434. title: '编辑',
  435. modal: true,
  436. closeAction: 'destroy',
  437. layout: 'column',
  438. items: [{
  439. xtype: 'textfield',
  440. fieldLabel: '类.方法',
  441. fieldStyle: 'background:#f1f1f1;',
  442. id: 'dh_classname',
  443. name: 'dh_classname',
  444. value: d.dh_classname,
  445. columnWidth: .6,
  446. readOnly: true
  447. },{
  448. xtype: 'dbfindtrigger',
  449. id: 'dh_methodname',
  450. name: 'dh_methodname',
  451. columnWidth: .4,
  452. value: d.dh_methodname
  453. },{
  454. xtype: 'textfield',
  455. fieldLabel: '描述',
  456. fieldStyle: 'background:#f1f1f1;',
  457. id: 'dh_description',
  458. name: 'dh_description',
  459. value: d.dh_description,
  460. columnWidth: 1,
  461. readOnly: true
  462. },{
  463. xtype: 'hidden',
  464. id: 'dh_methodtype',
  465. name: 'dh_methodtype'
  466. }],
  467. buttonAlign: 'center',
  468. buttons: [{
  469. text: $I18N.common.button.erpSaveButton,
  470. iconCls: 'x-button-icon-save',
  471. handler: function(btn){
  472. var w = btn.ownerCt.ownerCt;
  473. d.dh_classname = w.down('#dh_classname').value;
  474. d.dh_methodname = w.down('#dh_methodname').value;
  475. d.dh_description = w.down('#dh_description').value;
  476. d.dh_updater = em_name;
  477. d.dh_updatecode = em_code;
  478. d.dh_updatedate = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
  479. if(w.down('#dh_methodtype').value != null) {
  480. d.dh_methodtype = w.down('#dh_methodtype').value;
  481. }
  482. if('add' != d.status) {
  483. d.status = 'update';
  484. }
  485. me.refresh();
  486. w.close();
  487. }
  488. },{
  489. text: $I18N.common.button.erpCloseButton,
  490. iconCls: 'x-button-icon-close',
  491. handler: function(btn){
  492. btn.ownerCt.ownerCt.close();
  493. }
  494. }]
  495. });
  496. me.refresh();
  497. },
  498. indexOf: function(id){
  499. var dd = null,da = this.data;
  500. Ext.each(da, function(d){
  501. if (d.dh_id == id) {
  502. dd = d;
  503. }
  504. });
  505. return dd;
  506. },
  507. refresh: function(){
  508. var me = this,
  509. p = Ext.getCmp('centerpanel');
  510. p.removeAll();
  511. me.drawLogicSet();
  512. },
  513. save: function(save, update, del){
  514. var me = this;
  515. Ext.Ajax.request({
  516. url: basePath + 'ma/logic/saveLogicSet.action',
  517. method: 'post',
  518. params: {
  519. save: unescape(Ext.JSON.encode(save).replace(/\\/g,"%")),
  520. update: unescape(Ext.JSON.encode(update).replace(/\\/g,"%")),
  521. del: unescape(Ext.JSON.encode(del).replace(/\\/g,"%"))
  522. },
  523. callback: function(options, success, response){
  524. var localJson = new Ext.decode(response.responseText);
  525. if(localJson.success){
  526. alert('保存成功');
  527. me.getLogicSet(me.caller);
  528. }
  529. }
  530. });
  531. }
  532. });