Template.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  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-MM-dd',
  1012. separator: ' ',
  1013. boxLabel: '年月日'
  1014. },{
  1015. xtype: 'checkbox',
  1016. inputValue: 'HH:mm:ss',
  1017. separator: '',
  1018. boxLabel: '时分秒'
  1019. }],
  1020. getValue: function(){
  1021. var rr = this.query('checkbox[checked=true]'), vv = '', len = rr.length;
  1022. Ext.each(rr, function(r, idx){
  1023. if(r.xtype == 'checkbox' && r.inputValue) {
  1024. vv += r.inputValue;
  1025. if(idx < len - 1) {
  1026. vv += r.separator;
  1027. }
  1028. }
  1029. });
  1030. if(vv == '') {
  1031. return '';
  1032. }
  1033. return 'date(' + vv + ')';
  1034. },
  1035. setValue: function(v){
  1036. this.down('radio').setValue(true);
  1037. v = v.substring(v.indexOf('(') + 1, v.indexOf(')'));
  1038. var y = v.split(' '),arr,me = this;
  1039. Ext.each(y, function(i){
  1040. if(i.indexOf('-') != -1) {
  1041. arr = i.split('-');
  1042. } else {
  1043. arr = i.split(':');
  1044. }
  1045. var ch;
  1046. Ext.each(arr, function(j){
  1047. ch = me.down('checkbox[inputValue=' + j + ']');
  1048. if(ch)
  1049. ch.setValue(true);
  1050. });
  1051. });
  1052. }
  1053. },{
  1054. xtype: 'fieldcontainer',
  1055. name: 'replace',
  1056. columnWidth: 1,
  1057. layout: 'hbox',
  1058. items: [{
  1059. xtype: 'radio',
  1060. name: 'default',
  1061. boxLabel: '替代值'
  1062. },{
  1063. xtype: 'fieldcontainer',
  1064. items: [{
  1065. xtype: 'textfield',
  1066. emptyText: '显示值'
  1067. },{
  1068. xtype: 'textfield',
  1069. emptyText: '实际值'
  1070. }],
  1071. getValue: function(){
  1072. var val = this.items.items[0],dis = this.items.items[1];
  1073. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1074. return val.value + ':' + dis.value;
  1075. }
  1076. return '';
  1077. },
  1078. setValue: function(v) {
  1079. if(!Ext.isEmpty(v)) {
  1080. this.items.items[0].setValue(v.split(':')[0]);
  1081. this.items.items[1].setValue(v.split(':')[1] || '');
  1082. }
  1083. }
  1084. },{
  1085. xtype: 'button',
  1086. iconCls: 'x-button-icon-add',
  1087. cls: 'x-btn-tb',
  1088. handler: function(b){
  1089. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1090. xtype: 'fieldcontainer',
  1091. items: [{
  1092. xtype: 'textfield',
  1093. emptyText: '显示值'
  1094. },{
  1095. xtype: 'textfield',
  1096. emptyText: '实际值'
  1097. }],
  1098. getValue: function(){
  1099. var val = this.items.items[0],dis = this.items.items[1];
  1100. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1101. return val.value + ':' + dis.value;
  1102. }
  1103. return '';
  1104. },
  1105. setValue: function(v) {
  1106. if(!Ext.isEmpty(v)) {
  1107. this.items.items[0].setValue(v.split(':')[0]);
  1108. this.items.items[1].setValue(v.split(':')[1] || '');
  1109. }
  1110. }
  1111. });
  1112. }
  1113. }],
  1114. getValue: function(){
  1115. var tx = this.query('fieldcontainer'),val = '';
  1116. Ext.each(tx, function(t){
  1117. if(!Ext.isEmpty(t.getValue())) {
  1118. if(val == '') {
  1119. val = t.getValue();
  1120. } else {
  1121. val += ',' + t.getValue();
  1122. }
  1123. }
  1124. });
  1125. if(val == '') {
  1126. return null;
  1127. }
  1128. return 'replace(' +val + ')';
  1129. },
  1130. setValue: function(v){
  1131. var m = this;
  1132. this.down('radio').setValue(true);
  1133. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1134. Ext.each(t, function(r, i){
  1135. if(i == 0) {
  1136. m.down('fieldcontainer').setValue(r);
  1137. } else {
  1138. var f = Ext.create('Ext.form.FieldContainer', {
  1139. items: [{
  1140. xtype: 'textfield',
  1141. emptyText: '显示值'
  1142. },{
  1143. xtype: 'textfield',
  1144. emptyText: '实际值'
  1145. }],
  1146. getValue: function(){
  1147. var val = this.items.items[0],dis = this.items.items[1];
  1148. if(!Ext.isEmpty(val.value) && !Ext.isEmpty(dis.value)) {
  1149. return val.value + ':' + dis.value;
  1150. }
  1151. return '';
  1152. },
  1153. setValue: function(v) {
  1154. if(!Ext.isEmpty(v)) {
  1155. this.items.items[0].setValue(v.split(':')[0]);
  1156. this.items.items[1].setValue(v.split(':')[1] || '');
  1157. }
  1158. }
  1159. });
  1160. m.insert(m.items.items.length - 1, f);
  1161. f.setValue(r);
  1162. }
  1163. });
  1164. }
  1165. },{
  1166. xtype: 'fieldcontainer',
  1167. name: 'copy',
  1168. columnWidth: 1,
  1169. layout: 'hbox',
  1170. items: [{
  1171. xtype: 'radio',
  1172. boxLabel: '等于字段',
  1173. name: 'default'
  1174. },{
  1175. xtype: 'combo',
  1176. displayField: 'display',
  1177. valueField: 'value',
  1178. queryMode: 'local',
  1179. editable: false,
  1180. store: Ext.create('Ext.data.Store', {
  1181. fields: ['display','value'],
  1182. data: ff
  1183. })
  1184. },{
  1185. xtype: 'radio',
  1186. name: 'condition',
  1187. inputValue: 'if',
  1188. boxLabel: '只在值为空时'
  1189. },{
  1190. xtype: 'radio',
  1191. name: 'condition',
  1192. inputValue: 'of',
  1193. boxLabel: '任何情况下',
  1194. checked: true
  1195. }],
  1196. getValue: function(){
  1197. var rr = this.query('radio[name=condition]'), vv = '';
  1198. Ext.each(rr, function(){
  1199. if(this.checked) {
  1200. vv = this.inputValue;
  1201. }
  1202. });
  1203. return 'copy' + vv + '(' + this.down('combo').value + ')';
  1204. },
  1205. setValue: function(v) {
  1206. this.down('radio').setValue(true);
  1207. this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
  1208. var ff = v.substring(4, v.indexOf('('));
  1209. this.down('radio[inputValue=' + ff + ']').setValue(true);
  1210. }
  1211. },{
  1212. xtype: 'fieldcontainer',
  1213. name: 'others',
  1214. columnWidth: 1,
  1215. layout: 'hbox',
  1216. items: [{
  1217. xtype: 'radio',
  1218. boxLabel: '其它',
  1219. name: 'default'
  1220. },{
  1221. xtype: 'textfield'
  1222. }],
  1223. getValue: function() {
  1224. return this.down('textfield').value;
  1225. },
  1226. setValue: function(v) {
  1227. this.down('radio').setValue(true);
  1228. this.down('textfield').setValue(v);
  1229. }
  1230. }],
  1231. buttonAlign: 'center',
  1232. buttons: [{
  1233. text: '确定',
  1234. handler: function(b){
  1235. var w = b.ownerCt.ownerCt;
  1236. var val = '',ch = w.query('radio[name="default"]'),cc = null;
  1237. Ext.each(ch, function(){
  1238. if(this.checked) {
  1239. cc = this;
  1240. }
  1241. });
  1242. if(cc) {
  1243. v = cc.ownerCt.getValue();
  1244. if(v != null) {
  1245. val = v;
  1246. }
  1247. }
  1248. f.setValue(val);
  1249. record.set('id_default', val);
  1250. w.close();
  1251. }
  1252. },{
  1253. text: '取消',
  1254. handler: function(b){
  1255. b.ownerCt.ownerCt.close();
  1256. }
  1257. }]
  1258. });
  1259. var fc = ww.query('fieldcontainer');
  1260. if(!Ext.isEmpty(f.value)) {
  1261. var vv = f.value,bool = false;
  1262. Ext.each(fc, function(r){
  1263. if(contains(vv, r.name, true)) {
  1264. bool = true;
  1265. r.setValue(vv);
  1266. }
  1267. });
  1268. if(!bool) {
  1269. ww.down('fieldcontainer[name=others]').setValue(vv);
  1270. }
  1271. }
  1272. },
  1273. logicTypes: function(f, record){
  1274. var g = Ext.getCmp('initdetails'), dd = g.store.data.items,ff = [];
  1275. Ext.each(dd, function(i){
  1276. if(i.data.id_field != record.data.id_field) {
  1277. ff.push({
  1278. display: i.data.id_caption,
  1279. value: i.data.id_field
  1280. });
  1281. }
  1282. });
  1283. var ww = Ext.create('Ext.Window', {
  1284. autoShow: true,
  1285. modal: true,
  1286. title: '逻辑表达式',
  1287. width: '60%',
  1288. height: '60%',
  1289. layout: 'column',
  1290. padding: 15,
  1291. items: [{
  1292. xtype: 'fieldcontainer',
  1293. name: 'unique',
  1294. columnWidth: 1,
  1295. items: [{
  1296. xtype: 'checkbox',
  1297. boxLabel: '唯一性'
  1298. }],
  1299. getValue: function(){
  1300. return 'unique(' + record.data.id_table + '|' + record.data.id_field + ')';
  1301. },
  1302. setValue: function(v){
  1303. this.down('checkbox').setValue(true);
  1304. }
  1305. },{
  1306. xtype: 'fieldcontainer',
  1307. name: 'trim',
  1308. columnWidth: 1,
  1309. layout: 'column',
  1310. items: [{
  1311. xtype: 'checkbox',
  1312. columnWidth: 0.1,
  1313. boxLabel: '禁用字符'
  1314. },{
  1315. xtype: 'textfield',
  1316. columnWidth: 0.1
  1317. },{
  1318. xtype: 'button',
  1319. iconCls: 'x-button-icon-add',
  1320. cls: 'x-btn-tb',
  1321. handler: function(b){
  1322. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1323. xtype: 'textfield',
  1324. columnWidth: 0.1
  1325. });
  1326. }
  1327. }],
  1328. getValue: function(){
  1329. var tx = this.query('textfield'),val = '';
  1330. Ext.each(tx, function(t){
  1331. if(!Ext.isEmpty(t.value)) {
  1332. if(val == '') {
  1333. val = t.value;
  1334. } else {
  1335. val += ',' + t.value;
  1336. }
  1337. }
  1338. });
  1339. if(val == '') {
  1340. return null;
  1341. }
  1342. return 'trim(' +val + ')';
  1343. },
  1344. setValue: function(v){
  1345. var m = this;
  1346. m.down('checkbox').setValue(true);
  1347. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1348. Ext.each(t, function(r, i){
  1349. if(i == 0) {
  1350. m.down('textfield').setValue(r);
  1351. } else {
  1352. m.insert(m.items.items.length - 1, {
  1353. xtype: 'textfield',
  1354. columnWidth: 0.1,
  1355. value: r
  1356. });
  1357. }
  1358. });
  1359. }
  1360. },{
  1361. xtype: 'fieldcontainer',
  1362. name: 'combo',
  1363. columnWidth: 1,
  1364. layout: 'column',
  1365. items: [{
  1366. xtype: 'checkbox',
  1367. columnWidth: 0.1,
  1368. boxLabel: '可选范围'
  1369. },{
  1370. xtype: 'textfield',
  1371. columnWidth: 0.1
  1372. },{
  1373. xtype: 'button',
  1374. iconCls: 'x-button-icon-add',
  1375. cls: 'x-btn-tb',
  1376. handler: function(b){
  1377. b.ownerCt.insert(b.ownerCt.items.items.length - 1, {
  1378. xtype: 'textfield',
  1379. columnWidth: 0.1
  1380. });
  1381. }
  1382. }],
  1383. getValue: function(){
  1384. var tx = this.query('textfield'),val = '';
  1385. Ext.each(tx, function(t){
  1386. if(!Ext.isEmpty(t.value)) {
  1387. if(val == '') {
  1388. val = t.value;
  1389. } else {
  1390. val += ',' + t.value;
  1391. }
  1392. }
  1393. });
  1394. if(val == '') {
  1395. return null;
  1396. }
  1397. return 'combo(' +val + ')';
  1398. },
  1399. setValue: function(v){
  1400. var m = this;
  1401. m.down('checkbox').setValue(true);
  1402. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split(',');
  1403. Ext.each(t, function(r, i){
  1404. if(i == 0) {
  1405. m.down('textfield').setValue(r);
  1406. } else {
  1407. m.insert(m.items.items.length - 1, {
  1408. xtype: 'textfield',
  1409. columnWidth: 0.1,
  1410. value: r
  1411. });
  1412. }
  1413. });
  1414. }
  1415. },{
  1416. xtype: 'fieldcontainer',
  1417. name: 'accord',
  1418. columnWidth: 1,
  1419. layout: 'column',
  1420. items: [{
  1421. xtype: 'checkbox',
  1422. columnWidth: 0.1,
  1423. boxLabel: '关联'
  1424. },{
  1425. columnWidth: 0.3,
  1426. emptyText: '表',
  1427. id: 'accord_table',
  1428. name: 'accord_table',
  1429. xtype: 'dbfindtrigger'
  1430. },{
  1431. columnWidth: 0.3,
  1432. emptyText: '字段',
  1433. id: 'accord_field',
  1434. name: 'accord_field',
  1435. dbKey: 'accord_table',
  1436. mappingKey: 'ddd_tablename',
  1437. dbMessage: '请选择表名',
  1438. xtype: 'dbfindtrigger'
  1439. }],
  1440. getValue: function(){
  1441. var at = this.down('dbfindtrigger[name=accord_table]'),
  1442. af = this.down('dbfindtrigger[name=accord_field]');
  1443. if(!Ext.isEmpty(at.value) && !Ext.isEmpty(af.value)) {
  1444. return 'accord(' + at.value + '|' + af.value + ')';
  1445. }
  1446. return null;
  1447. },
  1448. setValue: function(v){
  1449. this.down('checkbox').setValue(true);
  1450. var t = v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')).split('|');
  1451. this.down('dbfindtrigger[name=accord_table]').setValue(t[0]);
  1452. this.down('dbfindtrigger[name=accord_field]').setValue(t[1]);
  1453. }
  1454. },{
  1455. xtype: 'fieldcontainer',
  1456. name: 'diffence',
  1457. columnWidth: 1,
  1458. layout: 'column',
  1459. items: [{
  1460. xtype: 'checkbox',
  1461. columnWidth: 0.1,
  1462. boxLabel: '不同于'
  1463. },{
  1464. columnWidth: 0.3,
  1465. xtype: 'combo',
  1466. displayField: 'display',
  1467. valueField: 'value',
  1468. queryMode: 'local',
  1469. editable: false,
  1470. store: Ext.create('Ext.data.Store', {
  1471. fields: ['display','value'],
  1472. data: ff
  1473. })
  1474. }],
  1475. getValue: function(){
  1476. var c = this.down('combo');
  1477. if(!Ext.isEmpty(c.value)) {
  1478. return 'diffence(' + c.value + ')';
  1479. }
  1480. return null;
  1481. },
  1482. setValue: function(v){
  1483. this.down('checkbox').setValue(true);
  1484. this.down('combo').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
  1485. }
  1486. },{
  1487. xtype: 'fieldcontainer',
  1488. name: 'minValue',
  1489. columnWidth: 1,
  1490. layout: 'column',
  1491. items: [{
  1492. xtype: 'checkbox',
  1493. columnWidth: 0.1,
  1494. boxLabel: '最小值'
  1495. },{
  1496. columnWidth: 0.3,
  1497. xtype: 'numberfield'
  1498. }],
  1499. getValue: function(){
  1500. var c = this.down('numberfield');
  1501. if(!Ext.isEmpty(c.value)) {
  1502. return 'minValue(' + c.value + ')';
  1503. }
  1504. return null;
  1505. },
  1506. setValue: function(v){
  1507. this.down('checkbox').setValue(true);
  1508. this.down('minValue').setValue(v.substring(v.indexOf('(') + 1, v.lastIndexOf(')')));
  1509. }
  1510. }],
  1511. buttonAlign: 'center',
  1512. buttons: [{
  1513. text: '确定',
  1514. handler: function(b){
  1515. var w = b.ownerCt.ownerCt;
  1516. var val = '',ch = w.query('checkbox[checked=true]'),v;
  1517. Ext.each(ch, function(c){
  1518. v = c.ownerCt.getValue();
  1519. if(v != null) {
  1520. if(val != '') {
  1521. val += ';';
  1522. }
  1523. val += v;
  1524. }
  1525. });
  1526. f.setValue(val);
  1527. record.set('id_logic', val);
  1528. w.close();
  1529. }
  1530. },{
  1531. text: '取消',
  1532. handler: function(b){
  1533. b.ownerCt.ownerCt.close();
  1534. }
  1535. }]
  1536. });
  1537. var fc = ww.query('fieldcontainer');
  1538. if(!Ext.isEmpty(f.value)) {
  1539. var vv = f.value.split(';');
  1540. Ext.each(vv, function(s){
  1541. Ext.each(fc, function(r){
  1542. if(contains(s, r.name, true)) {
  1543. r.setValue(s);
  1544. }
  1545. });
  1546. });
  1547. }
  1548. },
  1549. dataTypes: function(f, record){
  1550. var v = f.value,a = v.substring(v.indexOf('(') + 1, v.indexOf(')')),x = 30,y = 0;
  1551. if(a) {
  1552. x = a.split(',')[0];
  1553. y = a.split(',')[1];
  1554. }
  1555. var isDate = contains(f.value, 'date', true), isStr = contains(f.value, 'varchar2', true);
  1556. Ext.create('Ext.Window', {
  1557. autoShow: true,
  1558. modal: true,
  1559. title: '数据类型',
  1560. width: '40%',
  1561. height: '30%',
  1562. items: [{
  1563. xtype: 'container',
  1564. padding: '10 5 5 10',
  1565. items: [{
  1566. xtype: 'radio',
  1567. boxLabel: '日期',
  1568. name: 'type',
  1569. checked: isDate,
  1570. inputValue: 'date()',
  1571. listeners: {
  1572. change : function(){
  1573. if(this.checked) {
  1574. this.ownerCt.down('numberfield[name=length_y]').hide();
  1575. this.ownerCt.down('numberfield[name=length_x]').hide();
  1576. } else {
  1577. this.ownerCt.down('numberfield[name=length_x]').show();
  1578. }
  1579. }
  1580. }
  1581. },{
  1582. xtype: 'radio',
  1583. boxLabel: '字符串',
  1584. name: 'type',
  1585. checked: isStr,
  1586. inputValue: 'varchar2'
  1587. },{
  1588. xtype: 'radio',
  1589. boxLabel: '数字',
  1590. name: 'type',
  1591. checked: !isDate && !isStr,
  1592. inputValue: 'number',
  1593. listeners: {
  1594. change : function(){
  1595. if(this.checked) {
  1596. this.ownerCt.down('numberfield[name=length_y]').show();
  1597. this.ownerCt.down('numberfield[name=length_x]').setMaxValue(38);
  1598. this.ownerCt.down('numberfield[name=length_x]').validate();
  1599. } else {
  1600. this.ownerCt.down('numberfield[name=length_y]').hide();
  1601. this.ownerCt.down('numberfield[name=length_x]').setMaxValue(2000);
  1602. }
  1603. }
  1604. }
  1605. },{
  1606. xtype: 'numberfield',
  1607. fieldLabel: '长度',
  1608. name: 'length_x',
  1609. format: '0',
  1610. value: x,
  1611. hidden: isDate,
  1612. maxText: '超过最大长度',
  1613. listeners: {
  1614. change: function(f){
  1615. var a = f.ownerCt.down('radio[checked=true]').inputValue;
  1616. if(a == 'number') {
  1617. f.setMaxValue(38);
  1618. } else {
  1619. f.setMaxValue(2000);
  1620. }
  1621. }
  1622. }
  1623. },{
  1624. xtype: 'numberfield',
  1625. fieldLabel: '小数位数',
  1626. name: 'length_y',
  1627. hidden: isDate || isStr,
  1628. format: '0',
  1629. maxValue: 57,
  1630. maxText: '超过最大数57',
  1631. value: y
  1632. }]
  1633. }],
  1634. buttonAlign: 'center',
  1635. buttons: [{
  1636. text: '确定',
  1637. handler: function(b){
  1638. var w = b.ownerCt.ownerCt;
  1639. v = w.down('radio[checked=true]').inputValue;
  1640. x = w.down('numberfield[name=length_x]').value || 0;
  1641. y = w.down('numberfield[name=length_y]').value || 0;
  1642. if(v == 'varchar2') {
  1643. v += '(' + x + ')';
  1644. } else if (v == 'number') {
  1645. v += '(' + x + ',' + y + ')';
  1646. }
  1647. f.setValue(v);
  1648. record.set(f.name, v);
  1649. w.close();
  1650. }
  1651. },{
  1652. text: '取消',
  1653. handler: function(b){
  1654. b.ownerCt.ownerCt.close();
  1655. }
  1656. }]
  1657. });
  1658. },
  1659. getRules: function(grid){
  1660. var datas = new Array();
  1661. if(grid.cfg && grid.cfg.length > 0) {
  1662. datas = grid.cfg;
  1663. var keys;
  1664. Ext.each(datas, function(d){
  1665. keys = Ext.Object.getKeys(d);
  1666. Ext.each(keys, function(k){
  1667. d[k] = d[k] == null ? '' : d[k];
  1668. });
  1669. d.id_visible = d.id_visible == 1;
  1670. d.id_need = d.id_need == 1;
  1671. });
  1672. } else {
  1673. datas = [{id_detno:1,id_width:100},{id_detno:2,id_width:100},{id_detno:3,id_width:100},
  1674. {id_detno:4,id_width:100},{id_detno:5,id_width:100},{id_detno:6,id_width:100},
  1675. {id_detno:7,id_width:100},{id_detno:8,id_width:100},{id_detno:9,id_width:100},
  1676. {id_detno:10,id_width:100}];
  1677. }
  1678. return datas;
  1679. },
  1680. /**
  1681. * 数据校验
  1682. */
  1683. checkdata: function(grid){
  1684. var me = this, count = grid.down('pagingtoolbar').dataCount, pageSize = 5000, page = 0, a, b,
  1685. len = Math.ceil(count/pageSize), index = 0;
  1686. var p = Ext.create('Ext.ProgressBar', {
  1687. width: '60%',
  1688. text: '准备校验中...',
  1689. floating: true,
  1690. renderTo: Ext.getBody()
  1691. }).show();
  1692. grid.setLoading(true);
  1693. // 先删除上次校验记录
  1694. Ext.Ajax.request({
  1695. url: basePath + 'system/beforeCheckLog.action',
  1696. params: {
  1697. id: grid.ilid
  1698. },
  1699. method: 'post',
  1700. callback: function(opt, s, r){
  1701. var res = Ext.decode(r.responseText);
  1702. if(res.success) {
  1703. while (page*pageSize < count) {
  1704. a = page * pageSize + 1;
  1705. b = (page + 1) * pageSize;
  1706. Ext.Ajax.request({
  1707. url: basePath + 'system/checkInitData.action',
  1708. timeout: 30000,
  1709. async: false,
  1710. method: 'post',
  1711. params: {
  1712. id: grid.ilid,
  1713. start: a,
  1714. end: b
  1715. },
  1716. callback: function(opt, s, r){
  1717. var rs = Ext.decode(r.responseText);
  1718. if(rs.exceptionInfo) {
  1719. grid.setLoading(false);
  1720. p.destroy();
  1721. Ext.Msg.alert('发现错误', rs.exceptionInfo);return;
  1722. }
  1723. index++;
  1724. p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
  1725. if(index == len) {
  1726. p.updateProgress(0.4, '准备完毕,正在校验...', true);
  1727. Ext.Ajax.request({
  1728. url: basePath + 'system/afterCheckLog.action',
  1729. timeout: (5000 + count*50),
  1730. params: {
  1731. id: grid.ilid
  1732. },
  1733. method: 'post',
  1734. callback: function(opt, s, r){
  1735. grid.setLoading(false);
  1736. var res = Ext.decode(r.responseText);
  1737. if(res.success) {
  1738. p.updateProgress(0.8, '校验完成,正在获取校验结果...', true);
  1739. // 刷新grid.renderer
  1740. me.getCheckResult(grid, p);
  1741. } else {
  1742. p.updateProgress(0.8, '校验过程中出现错误,请向管理员反馈...', true);
  1743. alert(res.exceptionInfo);
  1744. }
  1745. }
  1746. });
  1747. }
  1748. }
  1749. });
  1750. page++;
  1751. }
  1752. } else {
  1753. alert('系统错误,准备校验失败!');
  1754. }
  1755. }
  1756. });
  1757. },
  1758. /**
  1759. * 从数据库取校验结果
  1760. */
  1761. getCheckResult: function(grid, p){
  1762. grid.setLoading(true);
  1763. Ext.Ajax.request({
  1764. url: basePath + 'system/getCheckResult.action',
  1765. timeout: 15000,
  1766. params: {
  1767. id: grid.ilid
  1768. },
  1769. method: 'post',
  1770. callback: function(opt, s, r){
  1771. p.destroy();
  1772. grid.setLoading(false);
  1773. var rs = r.responseText;
  1774. if(rs != null && rs != '') {
  1775. grid.errorNodes = rs.replace(/\s/g, '').split(',').filter(function(a){
  1776. return a != '' && a != ' ';
  1777. });
  1778. } else {
  1779. grid.errorNodes = [];
  1780. alert('系统错误,未找到校验结果.');
  1781. }
  1782. grid.showErrors();
  1783. Ext.getCmp('errdownload').show();
  1784. Ext.getCmp('onlyerror').show();
  1785. Ext.getCmp('toformal').show();
  1786. Ext.getCmp('errdelete').show();
  1787. Ext.getCmp('saveupdates').show();
  1788. }
  1789. });
  1790. },
  1791. toformal: function(grid){
  1792. var count = grid.down('pagingtoolbar').dataCount, pageSize = 2000, page = 0, a, b,
  1793. len = Math.ceil(count/pageSize), index = 0;
  1794. if ('Purchase' == grid.caller || 'Sale' == grid.caller ||
  1795. 'PurchasePrice' == grid.caller || 'SalePrice' == grid.caller ||
  1796. 'ProdInOut' == grid.caller || 'Estimate' == grid.caller ||
  1797. 'Make' == grid.caller || 'SaleForecast' == grid.caller
  1798. || 'GoodsSend' == grid.caller|| 'ARBill'==grid.caller||'APBill'==grid.caller||
  1799. 'ProdInOut!ExchangeIn'==grid.caller||'ProdInOut!SaleBorrow'==grid.caller||
  1800. 'ProdInOut!OtherPurcIn'==grid.caller) {
  1801. pageSize = count;
  1802. len = 1;
  1803. }
  1804. var p = Ext.create('Ext.ProgressBar', {
  1805. width: '60%',
  1806. text: '准备中...',
  1807. floating: true,
  1808. renderTo: Ext.getBody()
  1809. }).show();
  1810. grid.setLoading(true);
  1811. Ext.Ajax.request({
  1812. url: basePath + 'system/beforeToFormal.action',
  1813. params: {
  1814. id: grid.ilid
  1815. },
  1816. callback: function(opt, s, r){
  1817. if (!s) {
  1818. grid.setLoading(false);
  1819. p.destroy();
  1820. showError('网络或系统错误!');return;
  1821. }
  1822. var res = Ext.decode(r.responseText);
  1823. if(res.success) {
  1824. while (page*pageSize < count) {
  1825. a = page * pageSize + 1;
  1826. b = (page + 1) * pageSize;
  1827. p.updateProgress(index/len, '开始导入' + index/len*100 + '%', true);
  1828. Ext.Ajax.request({
  1829. url: basePath + 'system/toFormalData.action',
  1830. timeout: 30000,
  1831. method: 'post',
  1832. async: false,
  1833. params: {
  1834. id: grid.ilid,
  1835. start: a,
  1836. end: b
  1837. },
  1838. callback: function(_opt, _s, _r){
  1839. var rs = Ext.decode(_r.responseText);
  1840. if(rs.exceptionInfo) {
  1841. grid.setLoading(false);
  1842. p.destroy();
  1843. showError(rs.exceptionInfo);return;
  1844. } else if(_s){
  1845. index++;
  1846. p.updateProgress(index/len, '完成' + index/len*100 + '%', true);
  1847. if(index == len) {
  1848. grid.setLoading(false);
  1849. p.destroy();
  1850. alert('转入成功!');
  1851. Ext.Ajax.request({
  1852. url: basePath + 'system/afterToFormal.action',
  1853. params: {
  1854. id: grid.ilid
  1855. },
  1856. callback: function(){
  1857. }
  1858. });
  1859. }
  1860. } else
  1861. return;
  1862. }
  1863. });
  1864. page++;
  1865. }
  1866. } else {
  1867. grid.setLoading(false);
  1868. p.destroy();
  1869. showError(res.exceptionInfo);
  1870. }
  1871. }
  1872. });
  1873. },
  1874. /**
  1875. * 保存已修改的数据
  1876. */
  1877. saveUpdates: function(grid){
  1878. var items = grid.store.data.items,arr = new Array();
  1879. Ext.each(items, function(item){
  1880. if(item.dirty) {
  1881. arr.push(item.data);
  1882. }
  1883. });
  1884. Ext.Ajax.request({
  1885. url: basePath + 'system/updateInitData.action',
  1886. method: 'post',
  1887. params: {
  1888. data: Ext.encode(arr)
  1889. },
  1890. callback: function(opt, s, r) {
  1891. var res = Ext.decode(r.responseText);
  1892. if(res.success) {
  1893. alert('保存成功!');
  1894. grid.getGridData(1);
  1895. }
  1896. }
  1897. });
  1898. },
  1899. /**
  1900. * 删除校验错误数据
  1901. */
  1902. deleteErrors: function(grid) {
  1903. Ext.Msg.alert('提示', '确定删除?', function(btn){
  1904. if(btn == 'ok' || btn == 'yes') {
  1905. Ext.Ajax.request({
  1906. url: basePath + 'system/init/errdelete.action',
  1907. params: {
  1908. id: grid.ilid
  1909. },
  1910. callback: function(opt, s, r) {
  1911. var rs = Ext.decode(r.responseText);
  1912. if(rs.success) {
  1913. alert('删除成功!');
  1914. grid.getGridData(1);
  1915. }
  1916. }
  1917. });
  1918. }
  1919. });
  1920. },
  1921. parseLogic: function(logic) {
  1922. if(logic != null) {
  1923. var gc = logic.split(';'), str = '';
  1924. for(var i in gc) {
  1925. var s = gc[i];
  1926. if(s != null) {
  1927. if(s.indexOf('unique') > -1) {
  1928. str += '唯一性;';
  1929. } else if(s.indexOf('trim') > -1) {
  1930. str += '不能包含' + s.replace('trim', '') + ';';
  1931. } else if(s.indexOf('combo') > -1) {
  1932. str += '只能是' + s.replace('combo', '') + '之一;';
  1933. } else if(s.indexOf('accord') > -1) {
  1934. str += '必须存在于' + s.replace('accord', '') + '中;';
  1935. } else if(s.indexOf('diffence') > -1) {
  1936. str += '必须与' + s.replace('diffence', '') + '不同;';
  1937. } else if(s.indexOf('minValue') > -1) {
  1938. str += '必须大于' + s.replace('minValue', '') + ';';
  1939. }
  1940. }
  1941. }
  1942. return str;
  1943. }
  1944. return null;
  1945. }
  1946. });