Import.js 54 KB

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