MakeIMEI.js 52 KB

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