Template.js 63 KB

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