Template.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Template', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil','erp.util.GridUtil'],
  5. views: ['common.init.Template', 'core.button.UpExcel', 'core.trigger.DbfindTrigger', 'core.trigger.MultiDbfindTrigger',
  6. 'core.toolbar.Toolbar'],
  7. init: function(){
  8. var me = this;
  9. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  10. me.GridUtil = Ext.create('erp.util.GridUtil');
  11. this.control({
  12. 'panel[id="tree"]': {
  13. afterrender: function(p){
  14. me.getParentNodes(p);
  15. }
  16. },
  17. 'form[id=upexcel]': {
  18. afterrender: function(btn){
  19. btn.upexcel = function(field){
  20. if(btn.grid){
  21. btn.getForm().submit({
  22. url: basePath + 'system/initImport.action?caller=' + btn.grid.caller,
  23. waitMsg: "正在解析Excel",
  24. success: function(fp, o){
  25. field.reset();
  26. btn.grid.ilid = o.result.ilid;
  27. btn.grid.down('pagingtoolbar').dataCount = o.result.count;
  28. btn.grid.down('pagingtoolbar').onLoad();
  29. btn.grid.getGridData(1);
  30. Ext.getCmp('check').show();
  31. },
  32. failure: function(fp, o){
  33. if(o.result.size){
  34. showError(o.result.error + " " + Ext.util.Format.fileSize(o.result.size));
  35. field.reset();
  36. } else {
  37. showError(o.result.error);
  38. field.reset();
  39. }
  40. }
  41. });
  42. }
  43. };
  44. }
  45. },
  46. 'button[id=export]': {
  47. click: function(btn){
  48. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  49. if(grid){
  50. window.location = basePath + 'system/initTemplate.xls?caller=' + grid.caller +
  51. '&title=' + (grid.ownerCt.title.replace(/»/g, '/'));
  52. }
  53. }
  54. },
  55. 'button[id=rule]': {
  56. click: function(btn){
  57. me.showRule(btn.ownerCt.ownerCt.down('gridpanel'));
  58. }
  59. },
  60. 'button[id=check]': {
  61. click: function(btn){
  62. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  63. if(grid){
  64. me.checkdata(grid);
  65. }
  66. }
  67. },
  68. 'button[id=history]': {
  69. click: function(btn){
  70. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  71. if(grid){
  72. me.showHistory(grid.caller);
  73. }
  74. }
  75. },
  76. 'checkbox[id=onlyerror]': {
  77. change: function(f){
  78. var grid = f.ownerCt.ownerCt.down('gridpanel');
  79. if(grid) {
  80. if(f.checked) {
  81. grid.store.filterBy(function(item) {
  82. return !Ext.isEmpty(item.get('log'));
  83. });
  84. } else {
  85. grid.store.filterBy(function(item) {
  86. return true;
  87. });
  88. }
  89. }
  90. }
  91. },
  92. 'button[id=toformal]': {
  93. click: function(btn){
  94. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  95. if(grid && grid.ilid > 0) {
  96. if(grid.errorNodes && grid.errorNodes.length > 0) {
  97. showMessage('提示', '测试未通过,无法转入正式');
  98. } else {
  99. me.toformal(grid);
  100. }
  101. }
  102. }
  103. },
  104. 'button[id=errdelete]': {
  105. click: function(btn){
  106. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  107. if(grid && grid.ilid > 0) {
  108. me.deleteErrors(grid);
  109. }
  110. }
  111. },
  112. 'button[id=saveupdates]': {
  113. click: function(btn){
  114. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  115. if(grid && grid.ilid > 0) {
  116. me.saveUpdates(grid);
  117. }
  118. }
  119. },
  120. 'button[id=errdownload]': {
  121. click: function(btn){
  122. var grid = btn.ownerCt.ownerCt.down('gridpanel');
  123. if(grid && grid.ilid > 0) {
  124. window.location = basePath + 'system/initError.xls?caller=' + grid.caller +
  125. '&title=ERR_' + (grid.ownerCt.title.replace(/»/g, '/') + '&id=' + grid.ilid);
  126. }
  127. }
  128. }
  129. });
  130. },
  131. getParentNodes: function(p){
  132. var me = this;
  133. Ext.Ajax.request({// 拿到tree数据
  134. url : basePath + 'system/initTree.action',
  135. params: {
  136. pid: 0
  137. },
  138. callback : function(options,success,response){
  139. var res = new Ext.decode(response.responseText);
  140. if(res.tree){
  141. Ext.each(res.tree, function(t){
  142. p.add({
  143. title: t.in_desc,
  144. autoScroll: true,
  145. caller: t.in_caller,
  146. id: t.in_id,
  147. listeners: {
  148. expand: function(n){
  149. if(n.items.items.length == 0){
  150. me.getTreeNode(n);
  151. }
  152. }
  153. }
  154. });
  155. });
  156. var n = p.items.items[0];
  157. if(n && n.items.items.length == 0) {
  158. me.getTreeNode(n);
  159. }
  160. } else if(res.exceptionInfo){
  161. showError(res.exceptionInfo);
  162. }
  163. }
  164. });
  165. },
  166. getTreeNode: function(node){
  167. var me = this;
  168. Ext.Ajax.request({// 拿到tree数据
  169. url : basePath + 'system/initTree.action',
  170. params: {
  171. pid: node.id
  172. },
  173. callback : function(options,success,response){
  174. var res = new Ext.decode(response.responseText);
  175. if(res.tree){
  176. var tree = me.parseTree(res.tree);
  177. node.add({
  178. xtype: 'treepanel',
  179. height: '100%',
  180. rootVisible: false,
  181. containerScroll : true,
  182. autoScroll: false,
  183. store: Ext.create('Ext.data.TreeStore', {
  184. root: {
  185. text: 'root',
  186. id: 'root',
  187. expanded: true,
  188. children: tree
  189. }
  190. }),
  191. listeners: {
  192. itemmousedown: function(selModel, record){
  193. Ext.getCmp('template').setTitle(me.getPathString(selModel.ownerCt, record));
  194. me.getNode(record);
  195. }
  196. }
  197. });
  198. } else if(res.exceptionInfo){
  199. showError(res.exceptionInfo);
  200. }
  201. }
  202. });
  203. },
  204. parseTree: function(arr){
  205. var tree = new Array(),t;
  206. Ext.each(arr, function(r){
  207. t = new Object();
  208. t.id = r.in_id;
  209. t.text = r.in_desc;
  210. t.caller = r.in_caller;
  211. t.img = r.in_img;
  212. t.parentId = r.in_pid;
  213. t.leaf = r.in_leaf == 1;
  214. tree.push(t);
  215. });
  216. return tree;
  217. },
  218. getNode: function(record){
  219. var me = this,
  220. p = Ext.getCmp('template');
  221. me.getDetails(p, record.raw.caller, false);
  222. },
  223. getDetails: function(p, caller, isReload){
  224. if(caller != p.caller || isReload){
  225. p.caller = caller;
  226. var me = this;
  227. Ext.Ajax.request({
  228. url: basePath + 'system/initDetails.action',
  229. params: {
  230. caller: caller
  231. },
  232. method: 'post',
  233. callback: function(options, success, response){
  234. var res = new Ext.decode(response.responseText);
  235. if(res.exceptionInfo != null){
  236. Ext.getCmp('upexcel').hide();
  237. showError(res.exceptionInfo);return;
  238. } else {
  239. p.removeAll();
  240. var store = me.emptyData(res.data);
  241. p.add({
  242. xtype: 'grid',
  243. id: 'template-data',
  244. anchor: "100% 100%",
  245. cls: 'custom',
  246. caller: caller,
  247. ilid: -1,
  248. cfg: res.data,// 当前导入项的配置信息
  249. columnLines: true,
  250. columns: me.parseInitDetails(res.data),
  251. store: store,
  252. dockedItems: [me.getDockedItems(store)],
  253. getGridData: function(page){
  254. me.loadInitData(this, page);
  255. },
  256. loadData: function(ilid, count, page){
  257. this.ilid = ilid;
  258. this.down('pagingtoolbar').dataCount = count;
  259. this.down('pagingtoolbar').onLoad();
  260. this.getGridData(page);
  261. Ext.getCmp('errdownload').show();
  262. Ext.getCmp('onlyerror').show();
  263. Ext.getCmp('toformal').show();
  264. Ext.getCmp('errdelete').show();
  265. Ext.getCmp('saveupdates').show();
  266. Ext.getCmp('check').show();
  267. },
  268. deleteData: function(ilid){
  269. me.ondelete(ilid);
  270. },
  271. reset: function(){
  272. this.ilid = -1;
  273. this.down('pagingtoolbar').dataCount = 25;
  274. this.down('pagingtoolbar').onLoad();
  275. this.store.removeAll(true);
  276. this.store.loadData([{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]);
  277. },
  278. showErrors: function(){
  279. var grid = this,items = grid.store.data.items,
  280. columns = grid.columns,d,nodes = grid.errorNodes,log = '';
  281. if(nodes && nodes.length > 0) {
  282. Ext.each(items, function(item, index){
  283. d = item.data;
  284. log = '';
  285. Ext.each(columns, function(c, idx){
  286. if(idx > 0 && c.logic && c.renderer){
  287. if(Ext.Array.contains(nodes, d.id_id + ':' + c.dataIndex)) {
  288. if(log == '') {
  289. log = '<table border="1" class="custom-log">';
  290. log += '<tr class="custom-tr"><td>字段</td><td>值</td>' +
  291. '<td>规则</td><td>数据类型</td>' +
  292. '<td>是否必填</td>' +
  293. '<td>逻辑</td>' +
  294. '</tr>';
  295. }
  296. log += '<tr><td>' + c.text + '</td><td><font color=red>'
  297. + d[c.dataIndex] + '</td><td><font color=blue>'
  298. + (c.rule || '') + '</font></td><td><font color=blue>'
  299. + c.dataType + '</font></td><td><font color=blue>'
  300. + c.isNeed + '</font></td><td><font color=red>'
  301. + c.logicdesc +'</font></td></tr>';
  302. }
  303. }
  304. });
  305. if(log != '') {
  306. log += '</table>';
  307. }
  308. item.set('log', log);
  309. });
  310. }
  311. },
  312. plugins: [{
  313. ptype: 'rowexpander',
  314. rowBodyTpl : [
  315. '<p><b>校验状态:</b> {log}</p><br>'
  316. ]
  317. }, Ext.create('Ext.grid.plugin.CellEditing', {
  318. clicksToEdit: 1
  319. })]
  320. });
  321. Ext.getCmp('upexcel').show();
  322. Ext.getCmp('upexcel').grid = p.down('gridpanel');
  323. }
  324. }
  325. });
  326. }
  327. },
  328. parseInitDetails: function(arr){
  329. var me = this, d = new Array(),o;
  330. d.push({xtype: 'rownumberer', width: 35});
  331. d.push({
  332. text: '导入日志',
  333. dataIndex: 'log',
  334. hidden: true,
  335. renderer: function(val, meta){
  336. meta.style = 'height:0px;';
  337. }
  338. });
  339. d.push({
  340. text: 'ID',
  341. dataIndex: 'id_id',
  342. hidden: true
  343. });
  344. Ext.each(arr, function(a){
  345. o = new Object();
  346. o.text = a.id_caption;
  347. o.dataIndex = a.id_field;
  348. o.hidden = a.id_visible == 0;
  349. o.width = a.id_width;
  350. o.rule = a.id_rule;
  351. o.dataType = a.id_type;
  352. o.isNeed = a.id_need == 1 ? '是' : '否';
  353. o.logic = a.id_logic;
  354. o.logicdesc = me.parseLogic(o.logic);
  355. o.editor = {
  356. xtype: 'textfield'
  357. };
  358. if(/combo(.)/.test(o.logic)){
  359. var s = o.logic.substring(6, o.logic.lastIndexOf(')')).split(','),
  360. da = new Array();
  361. Ext.each(s, function(t){
  362. da.push({
  363. display: t,
  364. value: t
  365. });
  366. });
  367. o.editor = {
  368. xtype: 'combobox',
  369. displayField: 'display',
  370. valueField: 'value',
  371. queryMode: 'local',
  372. editable: false,
  373. store: Ext.create('Ext.data.Store', {
  374. fields: ['display', 'value'],
  375. data : da
  376. })
  377. };
  378. }
  379. o.renderer = function(val, meta, record, x, y, store, view){
  380. if(view) {
  381. var grid = view.ownerCt,errNodes = grid.errorNodes,cm = grid.columns[y];
  382. if(errNodes && y > 0 && Ext.Array.contains(errNodes, record.data['id_id'] + ':' + cm.dataIndex)){
  383. meta.tdCls = 'x-td-warn';
  384. meta.tdAttr = 'data-qtip="' + cm.rule + '"';
  385. }
  386. }
  387. return val;
  388. };
  389. d.push(o);
  390. });
  391. return d;
  392. },
  393. emptyData: function(arr){
  394. var fields = new Array();
  395. Ext.each(arr, function(a){
  396. fields.push(a.id_field);
  397. });
  398. return new Ext.data.Store({
  399. fields: fields,
  400. data: [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
  401. });
  402. },
  403. getDockedItems: function(store){
  404. return {
  405. xtype: 'pagingtoolbar',
  406. store: store,
  407. pageSize: 100,
  408. dataCount: store.data.items.length,
  409. page: 1,
  410. dock: 'bottom',
  411. displayInfo: true,
  412. updateInfo : function(){
  413. var page = this.child('#inputItem').getValue() || 1;
  414. var me = this,
  415. pageSize = me.pageSize || 100,
  416. dataCount = me.dataCount || 20;
  417. var displayItem = me.child('#displayItem'),
  418. pageData = me.getPageData();
  419. pageData.fromRecord = (page-1)*pageSize+1;
  420. pageData.toRecord = page*pageSize > dataCount ? dataCount : page*pageSize;
  421. pageData.total = dataCount;
  422. var msg;
  423. if (displayItem) {
  424. if (me.dataCount === 0) {
  425. msg = me.emptyMsg;
  426. } else {
  427. msg = Ext.String.format(
  428. me.displayMsg,
  429. pageData.fromRecord,
  430. pageData.toRecord,
  431. pageData.total
  432. );
  433. }
  434. displayItem.setText(msg);
  435. me.doComponentLayout();
  436. }
  437. },
  438. getPageData : function(){
  439. var me = this,
  440. totalCount = me.dataCount;
  441. return {
  442. total : totalCount,
  443. currentPage : me.page,
  444. pageCount: Math.ceil(me.dataCount / me.pageSize),
  445. fromRecord: ((me.page - 1) * me.pageSize) + 1,
  446. toRecord: Math.min(me.page * me.pageSize, totalCount)
  447. };
  448. },
  449. doRefresh:function(){
  450. this.moveFirst();
  451. },
  452. onPagingKeyDown : function(field, e){
  453. var me = this,
  454. k = e.getKey(),
  455. pageData = me.getPageData(),
  456. increment = e.shiftKey ? 10 : 1,
  457. pageNum = 0;
  458. if (k == e.RETURN) {
  459. e.stopEvent();
  460. pageNum = me.readPageFromInput(pageData);
  461. if (pageNum !== false) {
  462. pageNum = Math.min(Math.max(1, pageNum), pageData.pageCount);
  463. me.child('#inputItem').setValue(pageNum);
  464. if(me.fireEvent('beforechange', me, pageNum) !== false){
  465. me.page = pageNum;
  466. me.ownerCt.getGridData(me.page);
  467. }
  468. }
  469. } else if (k == e.HOME || k == e.END) {
  470. e.stopEvent();
  471. pageNum = k == e.HOME ? 1 : pageData.pageCount;
  472. field.setValue(pageNum);
  473. } else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN) {
  474. e.stopEvent();
  475. pageNum = me.readPageFromInput(pageData);
  476. if (pageNum) {
  477. if (k == e.DOWN || k == e.PAGEDOWN) {
  478. increment *= -1;
  479. }
  480. pageNum += increment;
  481. if (pageNum >= 1 && pageNum <= pageData.pages) {
  482. field.setValue(pageNum);
  483. }
  484. }
  485. }
  486. me.updateInfo();
  487. me.resetTool(value);
  488. },
  489. moveFirst : function(){
  490. var me = this;
  491. me.child('#inputItem').setValue(1);
  492. value = 1;
  493. me.page = value;
  494. me.ownerCt.getGridData(value);
  495. me.updateInfo();
  496. me.resetTool(value);
  497. },
  498. movePrevious : function(){
  499. var me = this;
  500. me.child('#inputItem').setValue(me.child('#inputItem').getValue() - 1);
  501. value = me.child('#inputItem').getValue();
  502. me.page = value;
  503. me.ownerCt.getGridData(value);
  504. me.updateInfo();
  505. me.resetTool(value);
  506. },
  507. moveNext : function(){
  508. var me = this,
  509. last = me.getPageData().pageCount;
  510. total = last;
  511. me.child('#inputItem').setValue(me.child('#inputItem').getValue() + 1);
  512. value = me.child('#inputItem').getValue();
  513. me.page = value;
  514. me.ownerCt.getGridData(value);
  515. me.updateInfo();
  516. me.resetTool(value);
  517. },
  518. moveLast : function(){
  519. var me = this,
  520. last = me.getPageData().pageCount;
  521. total = last;
  522. me.child('#inputItem').setValue(last);
  523. value = me.child('#inputItem').getValue();
  524. me.page = value;
  525. me.ownerCt.getGridData(value);
  526. me.updateInfo();
  527. me.resetTool(value);
  528. },
  529. onLoad : function() {
  530. var e = this, d, b, c, a;
  531. if (!e.rendered) {
  532. return
  533. }
  534. d = e.getPageData();
  535. b = d.currentPage;
  536. c = Math.ceil(e.dataCount / e.pageSize);
  537. a = Ext.String.format(e.afterPageText, isNaN(c) ? 1 : c);
  538. e.child("#afterTextItem").setText(a);
  539. e.child("#inputItem").setValue(b);
  540. e.child("#first").setDisabled(b === 1);
  541. e.child("#prev").setDisabled(b === 1);
  542. e.child("#next").setDisabled(b === c || c===1);//
  543. e.child("#last").setDisabled(b === c || c===1);
  544. e.child("#refresh").enable();
  545. e.updateInfo();
  546. e.fireEvent("change", e, d);
  547. },
  548. resetTool: function(value){
  549. var pageCount = this.getPageData().pageCount;
  550. this.child('#last').setDisabled(value == pageCount || pageCount == 1);
  551. this.child('#next').setDisabled(value == pageCount || pageCount == 1);
  552. this.child('#first').setDisabled(value <= 1);
  553. this.child('#prev').setDisabled(value <= 1);
  554. }
  555. };
  556. },
  557. getPathString: function(tree, record){// path:/root/5/12
  558. var str = tree.ownerCt.title;
  559. return record.getPath('text', '&raquo;').replace('root', str);
  560. },
  561. showHistory: function(caller){
  562. var w = Ext.create('Ext.Window', {
  563. width: '60%',
  564. height: '80%',
  565. id: 'history-win',
  566. title: '导入数据历史记录',
  567. autoShow: true,
  568. layout: 'anchor',
  569. items: [{
  570. xtype: 'gridpanel',
  571. anchor: '100% 100%',
  572. columnLines: true,
  573. columns: [{dataIndex: 'il_id', hidden: true},{dataIndex: 'il_caller', hidden: true},{dataIndex: 'il_date', text: '日期', flex: 2},
  574. {dataIndex: 'il_sequence', text: '次数', flex: 1},{dataIndex: 'il_count', text: '数据量(条)', flex: 1},
  575. {dataIndex: 'il_checked', text: '是否已校验', flex: 1, renderer: function(val, m){
  576. if(val == '否') {
  577. m.style = 'float:right';
  578. }
  579. return val;
  580. }},{dataIndex: 'il_success',text:'是否校验通过', flex: 1, renderer: function(val, m){
  581. if(val == '否') {
  582. m.style = 'float:right';
  583. }
  584. return val;
  585. }},
  586. {dataIndex: 'il_toformal', text: '是否转正式', flex: 1, renderer: function(val, m){
  587. if(val == '否') {
  588. m.style = 'float:right';
  589. }
  590. return val;
  591. }}, {text: '', flex: 1, renderer: function(val, m, r){
  592. return '<a href="javascript:Ext.getCmp(\'template-data\').loadData(' + r.get('il_id') + ','
  593. + r.get('il_count') + ',1);Ext.getCmp(\'history-win\').close();">载入</a>&nbsp;&nbsp;<a href="javascript:Ext.getCmp(\'template-data\').deleteData(' +
  594. r.get('il_id') + ');Ext.getCmp(\'history-win\').close();">删除</a>';
  595. }}],
  596. store: Ext.create('Ext.data.Store', {
  597. fields: ['il_id', 'il_caller', 'il_date', 'il_sequence', 'il_count', 'il_checked', 'il_success', 'il_toformal'],
  598. data: [{},{},{},{},{},{},{},{},{},{}]
  599. })
  600. }]
  601. });
  602. this.getInitLog(w.down('gridpanel'), caller);
  603. },
  604. getInitLog: function(g, c){
  605. Ext.Ajax.request({
  606. url: basePath + 'system/initHistory.action',
  607. params: {
  608. caller: c
  609. },
  610. method: 'post',
  611. callback: function(opt, s, r){
  612. var res = new Ext.decode(r.responseText);
  613. var dd = res.data;
  614. Ext.each(dd, function(d){
  615. d.il_date = Ext.Date.format(new Date(d.il_date), 'Y-m-d H:i:s');
  616. d.il_checked = d.il_checked == 1 ? '是' : '否';
  617. d.il_success = d.il_success == 1 ? '是' : '否';
  618. d.il_toformal = d.il_toformal == 1 ? '是' : '否';
  619. });
  620. g.store.loadData(dd);
  621. }
  622. });
  623. },
  624. loadInitData: function(grid, page){
  625. var f = (page-1) * 100 + 1,
  626. t = page*100;
  627. grid.setLoading(true);
  628. Ext.Ajax.request({
  629. url: basePath + 'system/getInitData.action',
  630. timeout: 10000,
  631. params: {
  632. condition: "id_ilid=" + grid.ilid +
  633. " AND id_detno between " + f + " AND " + t
  634. },
  635. method: 'post',
  636. callback: function(options, success, response){
  637. grid.setLoading(false);
  638. if(!success) {
  639. alert('系统繁忙,请稍后再试!');
  640. return;
  641. }
  642. var res = new Ext.decode(response.responseText);
  643. if(res.exceptionInfo != null){
  644. showError(res.exceptionInfo);return;
  645. } else {
  646. var datas = new Array(), o;
  647. Ext.each(res.data, function(d){
  648. o = Ext.decode(d.id_data);
  649. o.id_id = d.id_id;
  650. datas.push(o);
  651. });
  652. grid.store.loadData(datas);
  653. grid.showErrors();
  654. var f = Ext.getCmp('onlyerror');
  655. if(f.checked) {
  656. grid.store.filterBy(function(item) {
  657. return !Ext.isEmpty(item.get('log'));
  658. });
  659. }
  660. }
  661. }
  662. });
  663. },
  664. ondelete: function(id){
  665. var grid = Ext.getCmp('template-data');
  666. grid.setLoading(true);
  667. Ext.Ajax.request({
  668. url: basePath + 'system/deleteInitData.action',
  669. params: {
  670. id: id
  671. },
  672. method: 'post',
  673. timeout: 20000,
  674. callback: function(options, success, response){
  675. grid.setLoading(false);
  676. if(!success) {
  677. alert('系统繁忙,请稍后再试!');
  678. return;
  679. }
  680. var res = new Ext.decode(response.responseText);
  681. if(res.exceptionInfo != null){
  682. showError(res.exceptionInfo);return;
  683. } else {
  684. if(id == grid.ilid) {// 如果删除的是当前显示的数据,要清除当前grid的数据
  685. grid.reset();
  686. }
  687. }
  688. }
  689. });
  690. },
  691. showRule: function(grid){
  692. if(grid){
  693. var me = this,data = me.getRules(grid);
  694. Ext.create('Ext.window.Window', {
  695. width: '100%',
  696. height: '100%',
  697. autoShow: 'true',
  698. closeAction: 'destroy',
  699. title: '导入配置',
  700. layout: 'anchor',
  701. tbar: ['->',{
  702. text: '保存',
  703. width: 80,
  704. cls: 'x-btn-bar-s',
  705. handler: function(b){
  706. me.saveInitDetails(b.ownerCt.ownerCt.down('gridpanel'), grid.caller);
  707. }
  708. },{
  709. text: '取消',
  710. width: 80,
  711. cls: 'x-btn-bar-s',
  712. handler: function(b) {
  713. b.ownerCt.ownerCt.close();
  714. }
  715. },'->'],
  716. items: [{
  717. xtype: 'gridpanel',
  718. id: 'initdetails',
  719. anchor: '100% 100%',
  720. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  721. clicksToEdit: 1
  722. }),
  723. columnLines: true,
  724. keyField: 'id_id',
  725. detno: 'id_detno',
  726. bbar: {xtype: 'erpToolbar'},
  727. dbfinds: [{
  728. field: 'id_table',
  729. dbGridField: 'dd_tablename;ddd_tablename'
  730. },{
  731. field: 'id_field',
  732. dbGridField: 'ddd_fieldname'
  733. },{
  734. field: 'id_caption',
  735. dbGridField: 'ddd_description'
  736. },{
  737. field: 'id_type',
  738. dbGridField: 'ddd_fieldtype'
  739. }],
  740. columns: [{
  741. dataIndex: 'id_id',
  742. hidden: true
  743. },{
  744. dataIndex: 'id_caller',
  745. hidden: true,
  746. renderer: function(v, m, r, x, y, s, w){
  747. var grid = w.ownerCt;
  748. if(Ext.isEmpty(v) && !Ext.isEmpty(grid.caller)) {
  749. v = grid.caller;
  750. r.set('id_caller', v);
  751. }
  752. return v;
  753. }
  754. },{
  755. dataIndex: 'id_detno',
  756. text: '序号',
  757. width: 40,
  758. renderer: function(val, meta) {
  759. meta.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
  760. return val;
  761. }
  762. },{
  763. text: '导入表',
  764. dataIndex: 'id_table',
  765. width: 90,
  766. editor: {
  767. xtype: 'dbfindtrigger'
  768. },
  769. dbfind: 'DataDictionary|dd_tablename'
  770. },{
  771. text: '导入项',
  772. dataIndex: 'id_field',
  773. width: 100,
  774. editor: {
  775. xtype: 'multidbfindtrigger'
  776. },
  777. dbfind: 'DataDictionaryDetail|ddd_fieldname'
  778. },{
  779. text: '描述',
  780. dataIndex: 'id_caption',
  781. width: 105,
  782. renderer: function(v){
  783. if(Ext.isEmpty(v)) {
  784. return '<font color=gray>无</font>';
  785. }
  786. return v;
  787. },
  788. editor: {
  789. xtype: 'textfield'
  790. }
  791. },{
  792. text: '逻辑表达式',
  793. dataIndex: 'id_logic',
  794. width: 250,
  795. renderer: function(v){
  796. if(Ext.isEmpty(v)) {
  797. return '<font color=gray>无</font>';
  798. }
  799. return v;
  800. },
  801. editor: {
  802. xtype: 'trigger',
  803. editable: false,
  804. triggerCls: 'x-form-search-trigger',
  805. onTriggerClick: function(){
  806. me.logicTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
  807. }
  808. }
  809. },{
  810. text: '逻辑描述',
  811. dataIndex: 'id_rule',
  812. width: 500,
  813. renderer: function(v){
  814. if(Ext.isEmpty(v)) {
  815. return '<font color=gray>无</font>';
  816. }
  817. return v;
  818. },
  819. editor: {
  820. xtype: 'textfield'
  821. }
  822. },{
  823. text: '类型',
  824. dataIndex: 'id_type',
  825. width: 105,
  826. renderer: function(v, meta, record){
  827. if(Ext.isEmpty(v)) {
  828. return '<font color=gray>无</font>';
  829. } else {
  830. v = v.toLowerCase();
  831. if(contains(v, 'varchar2')) {
  832. v = v.replace(/byte/g, '').trim();
  833. }
  834. if(record.data['id_type'] != v) {
  835. record.set('id_type', v);
  836. }
  837. }
  838. return v;
  839. },
  840. editor: {
  841. xtype: 'trigger',
  842. editable: false,
  843. triggerCls: 'x-form-search-trigger',
  844. onTriggerClick: function(){
  845. me.dataTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
  846. }
  847. }
  848. },{
  849. text: '默认值',
  850. dataIndex: 'id_default',
  851. wdith: 80,
  852. renderer: function(v){
  853. if(Ext.isEmpty(v)) {
  854. return '<font color=gray>无</font>';
  855. }
  856. return v;
  857. },
  858. editor: {
  859. xtype: 'trigger',
  860. editable: false,
  861. triggerCls: 'x-form-search-trigger',
  862. onTriggerClick: function(){
  863. me.fieldTypes(this, Ext.getCmp('initdetails').selModel.lastSelected);
  864. }
  865. }
  866. },{
  867. text: '是否显示',
  868. dataIndex: 'id_visible',
  869. xtype: 'checkcolumn',
  870. width: 75,
  871. editor: {
  872. xtype: 'checkbox'
  873. }
  874. },{
  875. text: '是否必填',
  876. dataIndex: 'id_need',
  877. xtype: 'checkcolumn',
  878. width: 75,
  879. editor: {
  880. xtype: 'checkbox'
  881. }
  882. },{
  883. text: '列宽度',
  884. dataIndex: 'id_width',
  885. xtype: 'numbercolumn',
  886. format: '0',
  887. width: 75,
  888. editor: {
  889. xtype: 'numberfield',
  890. hideTrigger: true,
  891. format: '0'
  892. }
  893. }],
  894. store: Ext.create('Ext.data.Store', {
  895. fields: ['id_id', 'id_caller', 'id_detno', 'id_table', 'id_field', 'id_caption', 'id_logic', 'id_rule',
  896. 'id_type', {name: 'id_visible', type: 'bool'}, {name: 'id_need', type: 'bool'}, 'id_default',
  897. 'id_width'],
  898. data: data
  899. }),
  900. listeners: {
  901. itemclick: function(selModel, record){
  902. me.GridUtil.onGridItemClick(selModel, record);
  903. }
  904. }
  905. }]
  906. });
  907. me.control('field[name=id_field]', {
  908. focus: function(t){
  909. var record = Ext.getCmp('initdetails').selModel.lastSelected;
  910. var dd = record.data['id_table'];
  911. if(!Ext.isEmpty(dd)) {
  912. t.dbBaseCondition = 'ddd_tablename=\'' + dd + '\'';
  913. } else {
  914. t.dbBaseCondition = '';
  915. }
  916. }
  917. });
  918. }
  919. },
  920. saveInitDetails: function(grid, caller){
  921. var me = this,datas = [],items = grid.store.data.items,d;
  922. Ext.each(items, function(i){
  923. if(i.dirty) {
  924. d = i.data;
  925. if(!Ext.isEmpty(d.id_field) && !Ext.isEmpty(d.id_table)) {
  926. d.id_need = d.id_need ? 1 : 0;
  927. d.id_visible = d.id_visible ? 1 : 0;
  928. d.id_caller = caller;
  929. d.id_width = Ext.isEmpty(d.id_width) ? 0 : d.id_width;
  930. datas.push(d);
  931. }
  932. }
  933. });
  934. Ext.Ajax.request({
  935. url: basePath + 'system/saveInitDetail.action',
  936. method: 'post',
  937. params: {
  938. data: unescape(Ext.encode(datas).replace(/\\/g,"%"))
  939. },
  940. callback: function(opt, s, r) {
  941. if(r.exceptionInfo) {
  942. showError(r.exceptionInfo);
  943. } else {
  944. alert('保存成功!');
  945. grid.ownerCt.destroy();
  946. me.getDetails(Ext.getCmp('template'), caller, true);
  947. }
  948. }
  949. });
  950. },
  951. fieldTypes: function(f, record){
  952. var g = Ext.getCmp('initdetails'), dd = g.store.data.items,ff = [];
  953. Ext.each(dd, function(i){
  954. if(i.data.id_field != record.data.id_field) {
  955. ff.push({
  956. display: i.data.id_caption,
  957. value: i.data.id_field
  958. });
  959. }
  960. });
  961. var ww = Ext.create('Ext.Window', {
  962. autoShow: true,
  963. modal: true,
  964. title: '默认值',
  965. width: '55%',
  966. height: '50%',
  967. layout: 'column',
  968. items: [{
  969. xtype: 'fieldcontainer',
  970. name: 'keyField',
  971. columnWidth: 1,
  972. items: [{
  973. xtype: 'radio',
  974. columnWidth: 1,
  975. boxLabel: '自动取ID',
  976. name: 'default'
  977. }],
  978. getValue: function(){
  979. return 'keyField';
  980. },
  981. setValue: function(){
  982. this.down('radio').setValue(true);
  983. }
  984. },{
  985. xtype: 'fieldcontainer',
  986. name: 'codeField',
  987. columnWidth: 1,
  988. items: [{
  989. xtype: 'radio',
  990. columnWidth: 1,
  991. boxLabel: '自动取编号',
  992. name: 'default'
  993. }],
  994. getValue: function(){
  995. return 'codeField';
  996. },
  997. setValue: function(){
  998. this.down('radio').setValue(true);
  999. }
  1000. },{
  1001. xtype: 'fieldcontainer',
  1002. name: 'date',
  1003. columnWidth: 1,
  1004. layout: 'hbox',
  1005. items: [{
  1006. xtype: 'radio',
  1007. boxLabel: '当前时间',
  1008. name: 'default'
  1009. },{
  1010. xtype: 'checkbox',
  1011. inputValue: 'yy',
  1012. separator: '-',
  1013. boxLabel: '年'
  1014. },{
  1015. xtype: 'checkbox',
  1016. inputValue: 'MM',
  1017. separator: '-',
  1018. boxLabel: '月'
  1019. },{
  1020. xtype: 'checkbox',
  1021. inputValue: 'dd',
  1022. separator: ' ',
  1023. boxLabel: '日'
  1024. },{
  1025. xtype: 'checkbox',
  1026. inputValue: 'HH',
  1027. separator: ':',
  1028. boxLabel: '时'
  1029. },{
  1030. xtype: 'checkbox',
  1031. inputValue: 'mm',
  1032. separator: ':',
  1033. boxLabel: '分'
  1034. },{
  1035. xtype: 'checkbox',
  1036. inputValue: 'ss',
  1037. separator: '',
  1038. boxLabel: '秒'
  1039. }],
  1040. getValue: function(){
  1041. var rr = this.query('checkbox[checked=true]'), vv = '', len = rr.length;
  1042. Ext.each(rr, function(r, idx){
  1043. if(r.xtype == 'checkbox' && r.inputValue) {
  1044. vv += r.inputValue;
  1045. if(idx < len - 1) {
  1046. vv += r.separator;
  1047. }
  1048. }
  1049. });
  1050. if(vv == '') {
  1051. return '';
  1052. }
  1053. return 'date(' + vv + ')';
  1054. },
  1055. setValue: function(v){
  1056. this.down('radio').setValue(true);
  1057. v = v.substring(v.indexOf('(') + 1, v.indexOf(')'));
  1058. var y = v.split(' '),arr,me = this;
  1059. Ext.each(y, function(i){
  1060. if(i.indexOf('-') != -1) {
  1061. arr = i.split('-');
  1062. } else {
  1063. arr = i.split(':');
  1064. }
  1065. var ch;
  1066. Ext.each(arr, function(j){
  1067. ch = me.down('checkbox[inputValue=' + j + ']');
  1068. if(ch)
  1069. ch.setValue(true);
  1070. });
  1071. });
  1072. }
  1073. },{
  1074. xtype: 'fieldcontainer',
  1075. name: 'replace',
  1076. columnWidth: 1,
  1077. layout: 'hbox',
  1078. items: [{
  1079. xtype: 'radio',
  1080. name: 'default',
  1081. boxLabel: '替代值'
  1082. },{
  1083. xtype: 'fieldcontainer',
  1084. items: [{
  1085. xtype: 'textfield',
  1086. emptyText: '显示值'
  1087. },{
  1088. xtype: 'textfield',
  1089. emptyText: '实际值'
  1090. }],
  1091. getValue: function(){
  1092. var val = this.items.items[0],dis = this.items.items[1];
  1093. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1094. return val.value + ':' + dis.value;
  1095. }
  1096. return '';
  1097. },
  1098. setValue: function(v) {
  1099. if(!Ext.isEmpty(v)) {
  1100. this.items.items[0].setValue(v.split(':')[0]);
  1101. this.items.items[1].setValue(v.split(':')[1] || '');
  1102. }
  1103. }
  1104. },{
  1105. xtype: 'button',
  1106. iconCls: 'x-button-icon-add',
  1107. cls: 'x-btn-tb',
  1108. handler: function(b){
  1109. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1110. xtype: 'fieldcontainer',
  1111. items: [{
  1112. xtype: 'textfield',
  1113. emptyText: '显示值'
  1114. },{
  1115. xtype: 'textfield',
  1116. emptyText: '实际值'
  1117. }],
  1118. getValue: function(){
  1119. var val = this.items.items[0],dis = this.items.items[1];
  1120. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1121. return val.value + ':' + dis.value;
  1122. }
  1123. return '';
  1124. },
  1125. setValue: function(v) {
  1126. if(!Ext.isEmpty(v)) {
  1127. this.items.items[0].setValue(v.split(':')[0]);
  1128. this.items.items[1].setValue(v.split(':')[1] || '');
  1129. }
  1130. }
  1131. });
  1132. }
  1133. }],
  1134. getValue: function(){
  1135. var tx = this.query('fieldcontainer'),val = '';
  1136. Ext.each(tx, function(t){
  1137. if(!Ext.isEmpty(t.getValue())) {
  1138. if(val == '') {
  1139. val = t.getValue();
  1140. } else {
  1141. val += ',' + t.getValue();
  1142. }
  1143. }
  1144. });
  1145. if(val == '') {
  1146. return null;
  1147. }
  1148. return 'replace(' +val + ')';
  1149. },
  1150. setValue: function(v){
  1151. var m = this;
  1152. this.down('radio').setValue(true);
  1153. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1154. Ext.each(t, function(r, i){
  1155. if(i == 0) {
  1156. m.down('fieldcontainer').setValue(r);
  1157. } else {
  1158. var f = Ext.create('Ext.form.FieldContainer', {
  1159. items: [{
  1160. xtype: 'textfield',
  1161. emptyText: '显示值'
  1162. },{
  1163. xtype: 'textfield',
  1164. emptyText: '实际值'
  1165. }],
  1166. getValue: function(){
  1167. var val = this.items.items[0],dis = this.items.items[1];
  1168. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1169. return val.value + ':' + dis.value;
  1170. }
  1171. return '';
  1172. },
  1173. setValue: function(v) {
  1174. if(!Ext.isEmpty(v)) {
  1175. this.items.items[0].setValue(v.split(':')[0]);
  1176. this.items.items[1].setValue(v.split(':')[1] || '');
  1177. }
  1178. }
  1179. });
  1180. m.insert(m.items.items.length - 1, f);
  1181. f.setValue(r);
  1182. }
  1183. });
  1184. }
  1185. },{
  1186. xtype: 'fieldcontainer',
  1187. name: 'copy',
  1188. columnWidth: 1,
  1189. layout: 'hbox',
  1190. items: [{
  1191. xtype: 'radio',
  1192. boxLabel: '等于字段',
  1193. name: 'default'
  1194. },{
  1195. xtype: 'combo',
  1196. displayField: 'display',
  1197. valueField: 'value',
  1198. queryMode: 'local',
  1199. editable: false,
  1200. store: Ext.create('Ext.data.Store', {
  1201. fields: ['display','value'],
  1202. data: ff
  1203. })
  1204. },{
  1205. xtype: 'radio',
  1206. name: 'condition',
  1207. inputValue: 'if',
  1208. boxLabel: '只在值为空时'
  1209. },{
  1210. xtype: 'radio',
  1211. name: 'condition',
  1212. inputValue: 'of',
  1213. boxLabel: '任何情况下',
  1214. checked: true
  1215. }],
  1216. getValue: function(){
  1217. var rr = this.query('radio[name=condition]'), vv = '';
  1218. Ext.each(rr, function(){
  1219. if(this.checked) {
  1220. vv = this.inputValue;
  1221. }
  1222. });
  1223. return 'copy' + vv + '(' + this.down('combo').value + ')';
  1224. },
  1225. setValue: function(v) {
  1226. this.down('radio').setValue(true);
  1227. this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
  1228. var ff = v.substring(4, v.indexOf('('));
  1229. this.down('radio[inputValue=' + ff + ']').setValue(true);
  1230. }
  1231. },{
  1232. xtype: 'fieldcontainer',
  1233. name: 'others',
  1234. columnWidth: 1,
  1235. layout: 'hbox',
  1236. items: [{
  1237. xtype: 'radio',
  1238. boxLabel: '其它',
  1239. name: 'default'
  1240. },{
  1241. xtype: 'textfield'
  1242. }],
  1243. getValue: function() {
  1244. return this.down('textfield').value;
  1245. },
  1246. setValue: function(v) {
  1247. this.down('radio').setValue(true);
  1248. this.down('textfield').setValue(v);
  1249. }
  1250. }],
  1251. buttonAlign: 'center',
  1252. buttons: [{
  1253. text: '确定',
  1254. handler: function(b){
  1255. var w = b.ownerCt.ownerCt;
  1256. var val = '',ch = w.query('radio[name="default"]'),cc = null;
  1257. Ext.each(ch, function(){
  1258. if(this.checked) {
  1259. cc = this;
  1260. }
  1261. });
  1262. if(cc) {
  1263. v = cc.ownerCt.getValue();
  1264. if(v != null) {
  1265. val = v;
  1266. }
  1267. }
  1268. f.setValue(val);
  1269. record.set('id_default', val);
  1270. w.close();
  1271. }
  1272. },{
  1273. text: '取消',
  1274. handler: function(b){
  1275. b.ownerCt.ownerCt.close();
  1276. }
  1277. }]
  1278. });
  1279. var fc = ww.query('fieldcontainer');
  1280. if(!Ext.isEmpty(f.value)) {
  1281. var vv = f.value,bool = false;
  1282. Ext.each(fc, function(r){
  1283. if(contains(vv, r.name, true)) {
  1284. bool = true;
  1285. r.setValue(vv);
  1286. }
  1287. });
  1288. if(!bool) {
  1289. ww.down('fieldcontainer[name=others]').setValue(vv);
  1290. }
  1291. }
  1292. },
  1293. logicTypes: function(f, record){
  1294. var g = Ext.getCmp('initdetails'), dd = g.store.data.items,ff = [];
  1295. Ext.each(dd, function(i){
  1296. if(i.data.id_field != record.data.id_field) {
  1297. ff.push({
  1298. display: i.data.id_caption,
  1299. value: i.data.id_field
  1300. });
  1301. }
  1302. });
  1303. var ww = Ext.create('Ext.Window', {
  1304. autoShow: true,
  1305. modal: true,
  1306. title: '逻辑表达式',
  1307. width: '60%',
  1308. height: '60%',
  1309. layout: 'column',
  1310. items: [{
  1311. xtype: 'fieldcontainer',
  1312. name: 'unique',
  1313. columnWidth: 1,
  1314. items: [{
  1315. xtype: 'checkbox',
  1316. boxLabel: '唯一性'
  1317. }],
  1318. getValue: function(){
  1319. return 'unique(' + record.data.id_table + '|' + record.data.id_field + ')';
  1320. },
  1321. setValue: function(v){
  1322. this.down('checkbox').setValue(true);
  1323. }
  1324. },{
  1325. xtype: 'fieldcontainer',
  1326. name: 'trim',
  1327. columnWidth: 1,
  1328. layout: 'column',
  1329. items: [{
  1330. xtype: 'checkbox',
  1331. columnWidth: 0.1,
  1332. boxLabel: '禁用字符'
  1333. },{
  1334. xtype: 'textfield',
  1335. columnWidth: 0.1
  1336. },{
  1337. xtype: 'button',
  1338. iconCls: 'x-button-icon-add',
  1339. cls: 'x-btn-tb',
  1340. handler: function(b){
  1341. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1342. xtype: 'textfield',
  1343. columnWidth: 0.1
  1344. });
  1345. }
  1346. }],
  1347. getValue: function(){
  1348. var tx = this.query('textfield'),val = '';
  1349. Ext.each(tx, function(t){
  1350. if(!Ext.isEmpty(t.value)) {
  1351. if(val == '') {
  1352. val = t.value;
  1353. } else {
  1354. val += ',' + t.value;
  1355. }
  1356. }
  1357. });
  1358. if(val == '') {
  1359. return null;
  1360. }
  1361. return 'trim(' +val + ')';
  1362. },
  1363. setValue: function(v){
  1364. var m = this;
  1365. m.down('checkbox').setValue(true);
  1366. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1367. Ext.each(t, function(r, i){
  1368. if(i == 0) {
  1369. m.down('textfield').setValue(r);
  1370. } else {
  1371. m.insert(m.items.items.length - 1, {
  1372. xtype: 'textfield',
  1373. columnWidth: 0.1,
  1374. value: r
  1375. });
  1376. }
  1377. });
  1378. }
  1379. },{
  1380. xtype: 'fieldcontainer',
  1381. name: 'combo',
  1382. columnWidth: 1,
  1383. layout: 'column',
  1384. items: [{
  1385. xtype: 'checkbox',
  1386. columnWidth: 0.1,
  1387. boxLabel: '可选范围'
  1388. },{
  1389. xtype: 'textfield',
  1390. columnWidth: 0.1
  1391. },{
  1392. xtype: 'button',
  1393. iconCls: 'x-button-icon-add',
  1394. cls: 'x-btn-tb',
  1395. handler: function(b){
  1396. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1397. xtype: 'textfield',
  1398. columnWidth: 0.1
  1399. });
  1400. }
  1401. }],
  1402. getValue: function(){
  1403. var tx = this.query('textfield'),val = '';
  1404. Ext.each(tx, function(t){
  1405. if(!Ext.isEmpty(t.value)) {
  1406. if(val == '') {
  1407. val = t.value;
  1408. } else {
  1409. val += ',' + t.value;
  1410. }
  1411. }
  1412. });
  1413. if(val == '') {
  1414. return null;
  1415. }
  1416. return 'combo(' +val + ')';
  1417. },
  1418. setValue: function(v){
  1419. var m = this;
  1420. m.down('checkbox').setValue(true);
  1421. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1422. Ext.each(t, function(r, i){
  1423. if(i == 0) {
  1424. m.down('textfield').setValue(r);
  1425. } else {
  1426. m.insert(m.items.items.length - 1, {
  1427. xtype: 'textfield',
  1428. columnWidth: 0.1,
  1429. value: r
  1430. });
  1431. }
  1432. });
  1433. }
  1434. },{
  1435. xtype: 'fieldcontainer',
  1436. name: 'accord',
  1437. columnWidth: 1,
  1438. layout: 'column',
  1439. items: [{
  1440. xtype: 'checkbox',
  1441. columnWidth: 0.1,
  1442. boxLabel: '关联'
  1443. },{
  1444. columnWidth: 0.3,
  1445. emptyText: '表',
  1446. id: 'accord_table',
  1447. name: 'accord_table',
  1448. xtype: 'dbfindtrigger'
  1449. },{
  1450. columnWidth: 0.3,
  1451. emptyText: '字段',
  1452. id: 'accord_field',
  1453. name: 'accord_field',
  1454. dbKey: 'accord_table',
  1455. mappingKey: 'ddd_tablename',
  1456. dbMessage: '请选择表名',
  1457. xtype: 'dbfindtrigger'
  1458. }],
  1459. getValue: function(){
  1460. var at = this.down('dbfindtrigger[name=accord_table]'),
  1461. af = this.down('dbfindtrigger[name=accord_field]');
  1462. if(!Ext.isEmpty(at.value) && !Ext.isEmpty(af.value)) {
  1463. return 'accord(' + at.value + '|' + af.value + ')';
  1464. }
  1465. return null;
  1466. },
  1467. setValue: function(v){
  1468. this.down('checkbox').setValue(true);
  1469. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split('|');
  1470. this.down('dbfindtrigger[name=accord_table]').setValue(t[0]);
  1471. this.down('dbfindtrigger[name=accord_field]').setValue(t[1]);
  1472. }
  1473. },{
  1474. xtype: 'fieldcontainer',
  1475. name: 'diffence',
  1476. columnWidth: 1,
  1477. layout: 'column',
  1478. items: [{
  1479. xtype: 'checkbox',
  1480. columnWidth: 0.1,
  1481. boxLabel: '不同于'
  1482. },{
  1483. columnWidth: 0.3,
  1484. xtype: 'combo',
  1485. displayField: 'display',
  1486. valueField: 'value',
  1487. queryMode: 'local',
  1488. editable: false,
  1489. store: Ext.create('Ext.data.Store', {
  1490. fields: ['display','value'],
  1491. data: ff
  1492. })
  1493. }],
  1494. getValue: function(){
  1495. var c = this.down('combo');
  1496. if(!Ext.isEmpty(c.value)) {
  1497. return 'diffence(' + c.value + ')';
  1498. }
  1499. return null;
  1500. },
  1501. setValue: function(v){
  1502. this.down('checkbox').setValue(true);
  1503. this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
  1504. }
  1505. }],
  1506. buttonAlign: 'center',
  1507. buttons: [{
  1508. text: '确定',
  1509. handler: function(b){
  1510. var w = b.ownerCt.ownerCt;
  1511. var val = '',ch = w.query('checkbox[checked=true]'),v;
  1512. Ext.each(ch, function(c){
  1513. v = c.ownerCt.getValue();
  1514. if(v != null) {
  1515. if(val != '') {
  1516. val += ';';
  1517. }
  1518. val += v;
  1519. }
  1520. });
  1521. f.setValue(val);
  1522. record.set('id_logic', val);
  1523. w.close();
  1524. }
  1525. },{
  1526. text: '取消',
  1527. handler: function(b){
  1528. b.ownerCt.ownerCt.close();
  1529. }
  1530. }]
  1531. });
  1532. var fc = ww.query('fieldcontainer');
  1533. if(!Ext.isEmpty(f.value)) {
  1534. var vv = f.value.split(';');
  1535. Ext.each(vv, function(s){
  1536. Ext.each(fc, function(r){
  1537. if(contains(s, r.name, true)) {
  1538. r.setValue(s);
  1539. }
  1540. });
  1541. });
  1542. }
  1543. },
  1544. dataTypes: function(f, record){
  1545. var v = f.value,a = v.substring(v.indexOf('(') + 1, v.indexOf(')')),x = 30,y = 0;
  1546. if(a) {
  1547. x = a.split(',')[0];
  1548. y = a.split(',')[1];
  1549. }
  1550. var isDate = contains(f.value, 'date', true), isStr = contains(f.value, 'varchar2', true);
  1551. Ext.create('Ext.Window', {
  1552. autoShow: true,
  1553. modal: true,
  1554. title: '数据类型',
  1555. width: '40%',
  1556. height: '30%',
  1557. items: [{
  1558. xtype: 'container',
  1559. padding: '10 5 5 10',
  1560. items: [{
  1561. xtype: 'radio',
  1562. boxLabel: '日期',
  1563. name: 'type',
  1564. checked: isDate,
  1565. inputValue: 'date()',
  1566. listeners: {
  1567. change : function(){
  1568. if(this.checked) {
  1569. this.ownerCt.down('numberfield[name=length_y]').hide();
  1570. this.ownerCt.down('numberfield[name=length_x]').hide();
  1571. } else {
  1572. this.ownerCt.down('numberfield[name=length_x]').show();
  1573. }
  1574. }
  1575. }
  1576. },{
  1577. xtype: 'radio',
  1578. boxLabel: '字符串',
  1579. name: 'type',
  1580. checked: isStr,
  1581. inputValue: 'varchar2'
  1582. },{
  1583. xtype: 'radio',
  1584. boxLabel: '数字',
  1585. name: 'type',
  1586. checked: !isDate && !isStr,
  1587. inputValue: 'number',
  1588. listeners: {
  1589. change : function(){
  1590. if(this.checked) {
  1591. this.ownerCt.down('numberfield[name=length_y]').show();
  1592. this.ownerCt.down('numberfield[name=length_x]').setMaxValue(38);
  1593. this.ownerCt.down('numberfield[name=length_x]').validate();
  1594. } else {
  1595. this.ownerCt.down('numberfield[name=length_y]').hide();
  1596. this.ownerCt.down('numberfield[name=length_x]').setMaxValue(2000);
  1597. }
  1598. }
  1599. }
  1600. },{
  1601. xtype: 'numberfield',
  1602. fieldLabel: '长度',
  1603. name: 'length_x',
  1604. format: '0',
  1605. value: x,
  1606. hidden: isDate,
  1607. maxText: '超过最大长度',
  1608. listeners: {
  1609. change: function(f){
  1610. var a = f.ownerCt.down('radio[checked=true]').inputValue;
  1611. if(a == 'number') {
  1612. f.setMaxValue(38);
  1613. } else {
  1614. f.setMaxValue(2000);
  1615. }
  1616. }
  1617. }
  1618. },{
  1619. xtype: 'numberfield',
  1620. fieldLabel: '小数位数',
  1621. name: 'length_y',
  1622. hidden: isDate || isStr,
  1623. format: '0',
  1624. maxValue: 57,
  1625. maxText: '超过最大数57',
  1626. value: y
  1627. }]
  1628. }],
  1629. buttonAlign: 'center',
  1630. buttons: [{
  1631. text: '确定',
  1632. handler: function(b){
  1633. var w = b.ownerCt.ownerCt;
  1634. v = w.down('radio[checked=true]').inputValue;
  1635. x = w.down('numberfield[name=length_x]').value || 0;
  1636. y = w.down('numberfield[name=length_y]').value || 0;
  1637. if(v == 'varchar2') {
  1638. v += '(' + x + ')';
  1639. } else if (v == 'number') {
  1640. v += '(' + x + ',' + y + ')';
  1641. }
  1642. f.setValue(v);
  1643. record.set(f.name, v);
  1644. w.close();
  1645. }
  1646. },{
  1647. text: '取消',
  1648. handler: function(b){
  1649. b.ownerCt.ownerCt.close();
  1650. }
  1651. }]
  1652. });
  1653. },
  1654. getRules: function(grid){
  1655. var datas = new Array();
  1656. if(grid.cfg && grid.cfg.length > 0) {
  1657. datas = grid.cfg;
  1658. var keys;
  1659. Ext.each(datas, function(d){
  1660. keys = Ext.Object.getKeys(d);
  1661. Ext.each(keys, function(k){
  1662. d[k] = d[k] == null ? '' : d[k];
  1663. });
  1664. d.id_visible = d.id_visible == 1;
  1665. d.id_need = d.id_need == 1;
  1666. });
  1667. } else {
  1668. datas = [{id_detno:1,id_width:100},{id_detno:2,id_width:100},{id_detno:3,id_width:100},
  1669. {id_detno:4,id_width:100},{id_detno:5,id_width:100},{id_detno:6,id_width:100},
  1670. {id_detno:7,id_width:100},{id_detno:8,id_width:100},{id_detno:9,id_width:100},
  1671. {id_detno:10,id_width:100}];
  1672. }
  1673. return datas;
  1674. },
  1675. /**
  1676. * 数据校验
  1677. */
  1678. checkdata: function(grid){
  1679. var me = this, count = grid.down('pagingtoolbar').dataCount, pageSize = 5000, page = 0, a, b,
  1680. len = Math.ceil(count/pageSize), index = 0;
  1681. var p = Ext.create('Ext.ProgressBar', {
  1682. width: '60%',
  1683. text: '准备校验中...',
  1684. floating: true,
  1685. renderTo: Ext.getBody()
  1686. }).show();
  1687. grid.setLoading(true);
  1688. // 先删除上次校验记录
  1689. Ext.Ajax.request({
  1690. url: basePath + 'system/beforeCheckLog.action',
  1691. params: {
  1692. id: grid.ilid
  1693. },
  1694. method: 'post',
  1695. callback: function(opt, s, r){
  1696. var res = Ext.decode(r.responseText);
  1697. if(res.success) {
  1698. while (page*pageSize < count) {
  1699. a = page * pageSize + 1;
  1700. b = (page + 1) * pageSize;
  1701. Ext.Ajax.request({
  1702. url: basePath + 'system/checkInitData.action',
  1703. timeout: 30000,
  1704. async: false,
  1705. method: 'post',
  1706. params: {
  1707. id: grid.ilid,
  1708. start: a,
  1709. end: b
  1710. },
  1711. callback: function(opt, s, r){
  1712. var rs = Ext.decode(r.responseText);
  1713. if(rs.exceptionInfo) {
  1714. grid.setLoading(false);
  1715. p.destroy();
  1716. Ext.Msg.alert('发现错误', rs.exceptionInfo);return;
  1717. }
  1718. index++;
  1719. p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
  1720. if(index == len) {
  1721. p.updateProgress(0.4, '准备完毕,正在校验...', true);
  1722. Ext.Ajax.request({
  1723. url: basePath + 'system/afterCheckLog.action',
  1724. timeout: (5000 + count*50),
  1725. params: {
  1726. id: grid.ilid
  1727. },
  1728. method: 'post',
  1729. callback: function(opt, s, r){
  1730. grid.setLoading(false);
  1731. var res = Ext.decode(r.responseText);
  1732. if(res.success) {
  1733. p.updateProgress(0.8, '校验完成,正在获取校验结果...', true);
  1734. // 刷新grid.renderer
  1735. me.getCheckResult(grid, p);
  1736. } else {
  1737. p.updateProgress(0.8, '校验过程中出现错误,请向管理员反馈...', true);
  1738. alert(res.exceptionInfo);
  1739. }
  1740. }
  1741. });
  1742. }
  1743. }
  1744. });
  1745. page++;
  1746. }
  1747. } else {
  1748. alert('系统错误,准备校验失败!');
  1749. }
  1750. }
  1751. });
  1752. },
  1753. /**
  1754. * 从数据库取校验结果
  1755. */
  1756. getCheckResult: function(grid, p){
  1757. grid.setLoading(true);
  1758. Ext.Ajax.request({
  1759. url: basePath + 'system/getCheckResult.action',
  1760. timeout: 15000,
  1761. params: {
  1762. id: grid.ilid
  1763. },
  1764. method: 'post',
  1765. callback: function(opt, s, r){
  1766. p.destroy();
  1767. grid.setLoading(false);
  1768. var rs = r.responseText;
  1769. if(rs != null && rs != '') {
  1770. grid.errorNodes = rs.replace(/\s/g, '').split(',').filter(function(a){
  1771. return a != '' && a != ' ';
  1772. });
  1773. } else {
  1774. grid.errorNodes = [];
  1775. alert('系统错误,未找到校验结果.');
  1776. }
  1777. grid.showErrors();
  1778. Ext.getCmp('errdownload').show();
  1779. Ext.getCmp('onlyerror').show();
  1780. Ext.getCmp('toformal').show();
  1781. Ext.getCmp('errdelete').show();
  1782. Ext.getCmp('saveupdates').show();
  1783. }
  1784. });
  1785. },
  1786. toformal: function(grid){
  1787. var count = grid.down('pagingtoolbar').dataCount, pageSize = 2000, page = 0, a, b,
  1788. len = Math.ceil(count/pageSize), index = 0;
  1789. if ('Purchase' == grid.caller || 'Sale' == grid.caller ||
  1790. 'PurchasePrice' == grid.caller || 'SalePrice' == grid.caller ||
  1791. 'ProdInOut' == grid.caller || 'Estimate' == grid.caller ||
  1792. 'Make' == grid.caller || 'SaleForecast' == grid.caller
  1793. || 'GoodsSend' == grid.caller) {
  1794. pageSize = count;
  1795. len = 1;
  1796. }
  1797. var p = Ext.create('Ext.ProgressBar', {
  1798. width: '60%',
  1799. text: '准备中...',
  1800. floating: true,
  1801. renderTo: Ext.getBody()
  1802. }).show();
  1803. grid.setLoading(true);
  1804. Ext.Ajax.request({
  1805. url: basePath + 'system/beforeToFormal.action',
  1806. params: {
  1807. id: grid.ilid
  1808. },
  1809. callback: function(opt, s, r){
  1810. if (!s) {
  1811. grid.setLoading(false);
  1812. p.destroy();
  1813. showError('网络或系统错误!');return;
  1814. }
  1815. var res = Ext.decode(r.responseText);
  1816. if(res.success) {
  1817. while (page*pageSize < count) {
  1818. a = page * pageSize + 1;
  1819. b = (page + 1) * pageSize;
  1820. p.updateProgress(index/len, '开始导入' + index/len*100 + '%', true);
  1821. Ext.Ajax.request({
  1822. url: basePath + 'system/toFormalData.action',
  1823. timeout: 30000,
  1824. method: 'post',
  1825. async: false,
  1826. params: {
  1827. id: grid.ilid,
  1828. start: a,
  1829. end: b
  1830. },
  1831. callback: function(_opt, _s, _r){
  1832. if(!_s) return;
  1833. var rs = Ext.decode(_r.responseText);
  1834. if(rs.exceptionInfo) {
  1835. grid.setLoading(false);
  1836. p.destroy();
  1837. showError(rs.exceptionInfo);return;
  1838. } else {
  1839. index++;
  1840. p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
  1841. if(index == len) {
  1842. grid.setLoading(false);
  1843. p.destroy();
  1844. alert('转入成功!');
  1845. Ext.Ajax.request({
  1846. url: basePath + 'system/afterToFormal.action',
  1847. params: {
  1848. id: grid.ilid
  1849. },
  1850. callback: function(){
  1851. }
  1852. });
  1853. }
  1854. }
  1855. }
  1856. });
  1857. page++;
  1858. }
  1859. } else {
  1860. grid.setLoading(false);
  1861. p.destroy();
  1862. showError(res.exceptionInfo);
  1863. }
  1864. }
  1865. });
  1866. },
  1867. /**
  1868. * 保存已修改的数据
  1869. */
  1870. saveUpdates: function(grid){
  1871. var items = grid.store.data.items,arr = new Array();
  1872. Ext.each(items, function(item){
  1873. if(item.dirty) {
  1874. arr.push(item.data);
  1875. }
  1876. });
  1877. Ext.Ajax.request({
  1878. url: basePath + 'system/updateInitData.action',
  1879. method: 'post',
  1880. params: {
  1881. data: Ext.encode(arr)
  1882. },
  1883. callback: function(opt, s, r) {
  1884. var res = Ext.decode(r.responseText);
  1885. if(res.success) {
  1886. alert('保存成功!');
  1887. grid.getGridData(1);
  1888. }
  1889. }
  1890. });
  1891. },
  1892. /**
  1893. * 删除校验错误数据
  1894. */
  1895. deleteErrors: function(grid) {
  1896. Ext.Msg.alert('提示', '确定删除?', function(btn){
  1897. if(btn == 'ok' || btn == 'yes') {
  1898. Ext.Ajax.request({
  1899. url: basePath + 'system/init/errdelete.action',
  1900. params: {
  1901. id: grid.ilid
  1902. },
  1903. callback: function(opt, s, r) {
  1904. var rs = Ext.decode(r.responseText);
  1905. if(rs.success) {
  1906. alert('删除成功!');
  1907. grid.getGridData(1);
  1908. }
  1909. }
  1910. });
  1911. }
  1912. });
  1913. },
  1914. parseLogic: function(logic) {
  1915. if(logic != null) {
  1916. var gc = logic.split(';'), str = '';
  1917. for(var i in gc) {
  1918. var s = gc[i];
  1919. if(s != null) {
  1920. if(s.indexOf('unique') > -1) {
  1921. str += '唯一性;';
  1922. } else if(s.indexOf('trim') > -1) {
  1923. str += '不能包含' + s.replace('trim', '') + ';';
  1924. } else if(s.indexOf('combo') > -1) {
  1925. str += '只能是' + s.replace('combo', '') + '之一;';
  1926. } else if(s.indexOf('accord') > -1) {
  1927. str += '必须存在于' + s.replace('accord', '') + '中;';
  1928. } else if(s.indexOf('diffence') > -1) {
  1929. str += '必须与' + s.replace('diffence', '') + '不同;';
  1930. }
  1931. }
  1932. }
  1933. return str;
  1934. }
  1935. return null;
  1936. }
  1937. });