Showapply.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. Ext.define('erp.view.oa.meeting.Showapply',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.erpBatchDealGridPanel',
  4. id: 'batchDealGridPanel',
  5. columnLines : true,
  6. autoScroll : true,
  7. store: [],
  8. region: 'south',
  9. layout : 'fit',
  10. columns: new Array(),
  11. height:height,
  12. GridUtil: Ext.create('erp.util.GridUtil'),
  13. bodyStyle:'background-color:#f1f1f1;',
  14. selModel: Ext.create('Ext.selection.CheckboxModel',{
  15. headerWidth: 0
  16. }),
  17. /*enableLocking:true,*/
  18. /*lockable: true,*/
  19. GridUtil: Ext.create('erp.util.GridUtil'),
  20. BaseUtil: Ext.create('erp.util.BaseUtil'),
  21. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  22. clicksToEdit: 1,
  23. listeners:{
  24. 'edit':function(editor,e,Opts){
  25. var record=e.record,data=null,qty=0;
  26. if(record){
  27. data=record.data;
  28. for(var property in data){
  29. if(!/^[a-zA-Z]/.test(property)){
  30. qty+=data[property];
  31. }
  32. }
  33. }
  34. }
  35. }
  36. })],
  37. initComponent : function(){
  38. var condition = this.condition;
  39. if(!condition){
  40. var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
  41. urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
  42. gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  43. gridCondition = gridCondition + urlCondition;
  44. gridCondition = gridCondition.replace(/IS/g, "=");
  45. if(gridCondition.search(/!/) != -1){
  46. gridCondition = gridCondition.substring(0, gridCondition.length - 4);
  47. }
  48. condition = gridCondition;
  49. }
  50. var gridParam = {caller: this.caller || caller, condition: condition};
  51. this.getGridColumnsAndStore(this, 'oa/meeting/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
  52. this.callParent(arguments);
  53. },
  54. loadNewStore:function(grid, url, param, no){
  55. Ext.Ajax.request({//拿到grid的columns
  56. url : basePath + url,
  57. params: param,
  58. method : 'post',
  59. callback : function(options,success,response){
  60. var res = new Ext.decode(response.responseText);
  61. if(res.exceptionInfo){
  62. showError(res.exceptionInfo);return;
  63. }
  64. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  65. var data2 = Ext.decode(res.data2.replace(/,}/g, '}').replace(/,]/g, ']'));
  66. Ext.Array.each(data,function(item){
  67. Ext.Array.each(data2,function(item2){
  68. if(item.mr_code==item2.mamrcode){
  69. item[item2.name]=item2.result;
  70. }
  71. });
  72. });
  73. grid.store.loadData(data);
  74. }
  75. });
  76. },
  77. getGridColumnsAndStore: function(grid, url, param, no){
  78. var me = this;
  79. patchurl=basePath+url;
  80. grid.setLoading(true);
  81. Ext.Ajax.request({//拿到grid的columns
  82. url : basePath + url,
  83. params: param,
  84. async:false,
  85. method : 'post',
  86. callback : function(options,success,response){
  87. grid.setLoading(false);
  88. var res = new Ext.decode(response.responseText);
  89. if(res.exceptionInfo){
  90. showError(res.exceptionInfo);return;
  91. }
  92. if(res.columns){
  93. var limits = res.limits, limitArr = new Array();
  94. if(limits != null && limits.length > 0) {//权限外字段
  95. limitArr = Ext.Array.pluck(limits, 'lf_field');
  96. }
  97. var data = [];
  98. var gridfields=res.fields;
  99. var gridcolumns=res.columns;
  100. var hasadd=false,basecode=null;
  101. if(!res.data || res.data.length == 2){
  102. me.add10EmptyData(grid.detno, data);
  103. me.add10EmptyData(grid.detno, data);//添加20条空白数据
  104. } else {
  105. data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  106. var data2=Ext.decode(res.data2.replace(/,}/g, '}').replace(/,]/g, ']'));
  107. Ext.Array.each(data,function(item){
  108. Ext.Array.each(data2,function(item2){
  109. if(item.mr_code==item2.mamrcode){
  110. item[item2.name]=item2.result;
  111. }
  112. basecode=basecode==null?item2.mamrcode:basecode;
  113. if(item2.mamrcode==basecode&&hasadd==false){
  114. gridcolumns.push({
  115. readOnly:false,
  116. header:item2.name,
  117. cls: "x-grid-header-1",
  118. dataIndex:item2.name,
  119. width : 120,
  120. align:'right',
  121. format:'0',
  122. renderer:'oameeting'
  123. });
  124. gridfields.push({
  125. name:item2.name,
  126. type:'string'
  127. });
  128. }
  129. });
  130. hasadd=true;
  131. });
  132. Ext.each(res.columns, function(column, y){
  133. //power
  134. if(limitArr.length > 0 && Ext.Array.contains(limitArr, column.dataIndex)) {
  135. column.hidden = true;
  136. }
  137. //renderer
  138. me.setRenderer(grid, column);
  139. //logictype
  140. me.setLogicType(grid, column);
  141. });
  142. }
  143. //store
  144. //view
  145. if(grid.selModel.views == null){
  146. grid.selModel.views = [];
  147. }
  148. //dbfind
  149. if(res.dbfinds&&res.dbfinds.length > 0){
  150. grid.dbfinds = res.dbfinds;
  151. }
  152. //toolbar
  153. me.setToolbar(grid, res.columns, res.necessaryField, limitArr);
  154. var store = me.setStore(gridfields, data, grid.groupField, grid.necessaryField);
  155. grid.store=store;
  156. grid.columns=gridcolumns;
  157. var form = Ext.ComponentQuery.query('form')[0];
  158. if(form){
  159. if(form.readOnly){
  160. grid.readOnly = true;//grid不可编辑
  161. }
  162. }
  163. } else {
  164. grid.hide();
  165. var form = Ext.ComponentQuery.query('form')[0];
  166. me.updateFormPosition(form);//字段较少时,修改form布局
  167. }
  168. }
  169. });
  170. },
  171. setRenderer: function(grid, column){
  172. if(!column.haveRendered && column.renderer != null && column.renderer != ""){
  173. if(!grid.RenderUtil){
  174. grid.RenderUtil = Ext.create('erp.util.RenderUtil');
  175. }
  176. var renderName = column.renderer;
  177. if(contains(column.renderer, ':', true)){
  178. var args = new Array();
  179. Ext.each(column.renderer.split(':'), function(a, index){
  180. if(index == 0){
  181. renderName = a;
  182. } else {
  183. args.push(a);
  184. }
  185. });
  186. if(!grid.RenderUtil.args[renderName]){
  187. grid.RenderUtil.args[renderName] = new Object();
  188. }
  189. grid.RenderUtil.args[renderName][column.dataIndex] = args;
  190. }
  191. column.renderer = grid.RenderUtil[renderName];
  192. column.haveRendered = true;
  193. }
  194. },
  195. setLogicType: function(grid, column){
  196. var logic = column.logic;
  197. if(logic != null){
  198. if(logic == 'detno'){
  199. grid.detno = column.dataIndex;
  200. column.width = 40;
  201. column.renderer = function(val, meta) {
  202. meta.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
  203. return val;
  204. };
  205. } else if(logic == 'keyField'){
  206. grid.keyField = column.dataIndex;
  207. } else if(logic == 'mainField'){
  208. grid.mainField = column.dataIndex;
  209. } else if(logic == 'necessaryField'){
  210. grid.necessaryField = column.dataIndex;
  211. if(!grid.necessaryFields){
  212. grid.necessaryFields = new Array();
  213. }
  214. grid.necessaryFields.push(column.dataIndex);
  215. if(!column.haveRendered){
  216. column.renderer = function(val, meta, record, x, y, store, view){
  217. var c = this.columns[y];
  218. if(val != null && val.toString().trim() != ''){
  219. if(c.xtype == 'datecolumn'){
  220. val = Ext.Date.format(val, 'Y-m-d');
  221. }
  222. return val;
  223. } else {
  224. if(c.xtype == 'datecolumn'){
  225. val = '';
  226. }
  227. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  228. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  229. }
  230. };
  231. }
  232. } else if(logic == 'groupField'){
  233. grid.groupField = column.dataIndex;
  234. }
  235. }
  236. },
  237. setStore: function(fields, data, groupField, necessaryField){
  238. griddata=data;
  239. if(!Ext.isChrome){
  240. Ext.each(fields, function(f){
  241. if(f.type == 'date'){
  242. f.dateFormat = 'Y-m-d H:m:s';
  243. }
  244. });
  245. }
  246. return Ext.create('Ext.data.Store', {
  247. fields: fields,
  248. data: data,
  249. groupField: groupField,
  250. getSum: function(records, field) {
  251. if (arguments.length < 2) {
  252. return 0;
  253. }
  254. var total = 0,
  255. i = 0,
  256. len = records.length;
  257. if(necessaryField) {
  258. for (; i < len; ++i) {//重写getSum,grid在合计时,只合计填写了必要信息的行
  259. var necessary = records[i].get(necessaryField);
  260. if(necessary != null && necessary != ''){
  261. total += records[i].get(field);
  262. }
  263. }
  264. } else {
  265. for (; i < len; ++i) {
  266. total += records[i].get(field);
  267. }
  268. }
  269. return total;
  270. },
  271. getCount: function() {
  272. if(necessaryField) {
  273. var count = 0;
  274. Ext.each(this.data.items, function(item){//重写getCount,grid在合计时,只合计填写了必要信息的行
  275. if(item.data[necessaryField] != null && item.data[necessaryField] != ''){
  276. count++;
  277. }
  278. });
  279. return count;
  280. }
  281. return this.data.items.length;
  282. }
  283. });
  284. },
  285. setToolbar: function(grid, columns, necessaryField, limitArr){
  286. var items = [];
  287. var bool = true;
  288. if(!grid.dockedItems)
  289. return;
  290. Ext.each(grid.dockedItems.items, function(item){
  291. if(item.dock == 'bottom' && item.items){//bbar已存在
  292. bool = false;
  293. }
  294. });
  295. if(bool){
  296. Ext.each(columns, function(column){
  297. if(limitArr.length == 0 || !Ext.Array.contains(limitArr, column.dataIndex)) {
  298. if(column.summaryType == 'sum'){
  299. items.push('-',{
  300. id: column.dataIndex + '_sum',
  301. itemId: column.dataIndex,
  302. xtype: 'tbtext',
  303. text: column.header + '(sum):0'
  304. });
  305. } else if(column.summaryType == 'average') {
  306. items.push('-',{
  307. id: column.dataIndex + '_average',
  308. itemId: column.dataIndex,
  309. xtype: 'tbtext',
  310. text: column.header + '(average):0'
  311. });
  312. } else if(column.summaryType == 'count') {
  313. items.push('-',{
  314. id: column.dataIndex + '_count',
  315. itemId: column.dataIndex,
  316. xtype: 'tbtext',
  317. text: column.header + '(count):0'
  318. });
  319. }
  320. }
  321. if(column.dataIndex == necessaryField){
  322. column.renderer = function(val){
  323. if(val != null && val.toString().trim() != ''){
  324. return val;
  325. } else {
  326. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  327. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  328. }
  329. };
  330. }
  331. });
  332. grid.addDocked({
  333. xtype: 'toolbar',
  334. dock: 'bottom',
  335. items: items
  336. });
  337. } else {
  338. var bars = Ext.ComponentQuery.query('erpToolbar');
  339. if(bars.length > 0){
  340. Ext.each(columns, function(column){
  341. if(column.summaryType == 'sum'){
  342. bars[0].add('-');
  343. bars[0].add({
  344. id: column.dataIndex + '_sum',
  345. itemId: column.dataIndex,
  346. xtype: 'tbtext',
  347. text: column.header + '(sum):0'
  348. });
  349. } else if(column.summaryType == 'average') {
  350. bars[0].add('-');
  351. bars[0].add({
  352. id: column.dataIndex + '_average',
  353. itemId: column.dataIndex,
  354. xtype: 'tbtext',
  355. text: column.header + '(average):0'
  356. });
  357. } else if(column.summaryType == 'count') {
  358. bars[0].add('-');
  359. bars[0].add({
  360. id: column.dataIndex + '_count',
  361. itemId: column.dataIndex,
  362. xtype: 'tbtext',
  363. text: column.header + '(count):0'
  364. });
  365. }
  366. });
  367. }
  368. }
  369. },
  370. add10EmptyData: function(detno, data){
  371. if(detno){
  372. var index = data.length == 0 ? 0 : Number(data[data.length-1][detno]);
  373. for(var i=0;i<10;i++){
  374. var o = new Object();
  375. o[detno] = index + i + 1;
  376. data.push(o);
  377. }
  378. } else {
  379. for(var i=0;i<10;i++){
  380. var o = new Object();
  381. data.push(o);
  382. }
  383. }
  384. },
  385. checkGridDirty: function(grid){
  386. var s = grid.getStore().data.items;//获取store里面的数据
  387. var msg = '';
  388. for(var i=0;i<s.length;i++){
  389. if(s[i].dirty){//明细行被修改过哦
  390. msg = msg + '第' + (i+1) + '行:';
  391. var changed = Ext.Object.getKeys(s[i].modified);//拿到被修改了的字段
  392. for(var j = 0;j < changed.length;j++){
  393. Ext.each(grid.columns, function(c, index){
  394. if(index == 0){
  395. return;
  396. }
  397. if(c.dataIndex == changed[j] && c.logic != 'ignore'){//由字段dataindex匹配其text
  398. msg = msg + '<font color=blue>' + c.text + '</font>&nbsp;';
  399. }
  400. });
  401. }
  402. msg = msg + ";";
  403. }
  404. }
  405. if(msg != '' && msg != ';'){//明细行被修改过哦
  406. msg = "明细行<font color=green>" + msg.substring(0, msg.length-1) + "</font>已编辑过";
  407. }
  408. return msg;
  409. },
  410. getGridStore: function(grid){
  411. if(grid == null){
  412. grid = Ext.getCmp('grid');
  413. }
  414. var me = this,
  415. jsonGridData = new Array();
  416. var form = Ext.getCmp('form');
  417. var s = grid.getStore().data.items;//获取store里面的数据
  418. var dd;
  419. for(var i=0;i<s.length;i++){//将grid里面各行的数据获取并拼成jsonGridData
  420. var data = s[i].data;
  421. dd = new Object();
  422. if(s[i].dirty && !me.isBlank(grid, data)){
  423. Ext.each(gridcolumns, function(c){
  424. if(c.logic != 'ignore'){//只需显示,无需后台操作的字段,自动略去
  425. if(c.dataIndex=='wd_date'){
  426. Ext.Array.each(c.columns,function(column){
  427. dd[column.dataIndex]=data[column.dataIndex];
  428. });
  429. }else {
  430. if(c.xtype == 'datecolumn'){
  431. c.format = c.format || 'Y-m-d';
  432. if(Ext.isDate(data[c.dataIndex])){
  433. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], c.format);
  434. } else {
  435. if(c.editor){
  436. dd[c.dataIndex] = Ext.Date.format(new Date(), c.format);//如果用户没输入日期,或输入有误,就给个默认日期,
  437. }
  438. }
  439. } else if(c.xtype == 'datetimecolumn'){
  440. if(Ext.isDate(data[c.dataIndex])){
  441. dd[c.dataIndex] = Ext.Date.format(data[c.dataIndex], 'Y-m-d H:i:s');//在这里把GMT日期转化成Y-m-d H:i:s格式日期
  442. } else {
  443. if(c.editor){
  444. dd[c.dataIndex] = Ext.Date.format(new Date(), 'Y-m-d H:i:s');//默认日期,
  445. }
  446. }
  447. } else if(c.xtype == 'numbercolumn'){//赋个默认值0吧,不然不好保存
  448. if(data[c.dataIndex] == null || data[c.dataIndex] == ''){
  449. dd[c.dataIndex] = '0';//也可以从data里面去掉这些字段
  450. } else {
  451. dd[c.dataIndex] = s[i].data[c.dataIndex];
  452. }
  453. } else {
  454. dd[c.dataIndex] = s[i].data[c.dataIndex];
  455. }
  456. }
  457. }
  458. });
  459. if(grid.mainField && form && form.keyField){//例如,将pu_id的值赋给pd_puid
  460. dd[grid.mainField] = Ext.getCmp(form.keyField).value;
  461. }
  462. jsonGridData.push(Ext.JSON.encode(dd));
  463. }
  464. }
  465. return jsonGridData;
  466. },
  467. isBlank: function(grid, data) {
  468. var ff = grid.necessaryFields,bool = true;
  469. if(ff) {
  470. Ext.each(ff, function(f) {
  471. if(!Ext.isEmpty(data[f]) && data[f] != 0) {
  472. bool = false;
  473. }else {
  474. bool=true;
  475. return
  476. }
  477. });
  478. } else {
  479. if(!grid.necessaryField || !Ext.isEmpty(data[grid.necessaryField])) {
  480. bool = false;
  481. }
  482. }
  483. return bool;
  484. },
  485. });