MrpReplaceGrid.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Ext.define('erp.view.pm.mps.MrpReplaceGrid',{
  2. extend: 'Ext.grid.Panel',
  3. alias: 'widget.MrpReplaceGrid',
  4. region: 'south',
  5. layout : 'fit',
  6. id: 'grid',
  7. emptyText : $I18N.common.grid.emptyText,
  8. columnLines : true,
  9. autoScroll : true,
  10. store: [],
  11. columns: [],
  12. bodyStyle: 'background-color:#f1f1f1;',
  13. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  14. clicksToEdit: 1
  15. })],
  16. GridUtil: Ext.create('erp.util.GridUtil'),
  17. BaseUtil: Ext.create('erp.util.BaseUtil'),
  18. necessaryFields: new Array(),
  19. necessaryField:'',
  20. detno: '',//编号字段
  21. keyField: '',//主键字段
  22. mainField: '',//对应主表主键的字段
  23. dbfinds: [],
  24. caller: null,
  25. condition: null,
  26. initComponent : function(){
  27. var condition = this.condition;
  28. if(!condition){
  29. var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
  30. urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
  31. gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
  32. gridCondition = gridCondition + urlCondition;
  33. gridCondition = gridCondition.replace(/IS/g, "=");
  34. /*if(gridCondition.search(/!/) != -1){
  35. gridCondition = gridCondition.substring(0, gridCondition.length - 4);
  36. }*/
  37. condition = gridCondition;
  38. }
  39. var gridParam = {caller: this.caller || caller, condition: condition};
  40. this.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
  41. this.callParent(arguments);
  42. },
  43. getGridColumnsAndStore:function(grid,url,param){
  44. var me = this;
  45. grid.setLoading(true);
  46. Ext.Ajax.request({//拿到grid的columns
  47. url : basePath + url,
  48. params: param,
  49. method : 'post',
  50. callback : function(options,success,response){
  51. grid.setLoading(false);
  52. var res = new Ext.decode(response.responseText);
  53. if(res.exceptionInfo){
  54. showError(res.exceptionInfo);return;
  55. }
  56. if(res.columns){
  57. var data = [];
  58. if(!res.data || res.data.length == 2){
  59. /* var o=new Object();
  60. o.mr_prodcode='无数据';
  61. o.mr_repcode='无数据';
  62. data.push(o);*/
  63. } else {
  64. data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  65. }
  66. //store
  67. var store =Ext.create('Ext.data.Store', {
  68. fields: res.fields,
  69. data: data
  70. });
  71. //view
  72. if(grid.selModel.views == null){
  73. grid.selModel.views = [];
  74. }
  75. if(res.dbfinds&&res.dbfinds.length > 0){
  76. grid.dbfinds = res.dbfinds;
  77. }
  78. Ext.each(res.columns, function(column, y){
  79. me.setLogicType(grid, column);
  80. });
  81. grid.reconfigure(store, res.columns);
  82. } else {
  83. grid.hide();
  84. var form = Ext.ComponentQuery.query('form')[0];
  85. me.updateFormPosition(form);//字段较少时,修改form布局
  86. }
  87. }
  88. });
  89. },
  90. setLogicType: function(grid, column){
  91. var logic = column.logic;
  92. if(logic != null){
  93. if(logic == 'detno'){
  94. grid.detno = column.dataIndex;
  95. column.width = 40;
  96. column.renderer = function(val, meta) {
  97. meta.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
  98. return val;
  99. };
  100. } else if(logic == 'keyField'){
  101. grid.keyField = column.dataIndex;
  102. } else if(logic == 'mainField'){
  103. grid.mainField = column.dataIndex;
  104. }else if(logic == 'orNecessField'){
  105. if(!grid.orNecessField){
  106. grid.orNecessField = new Array();
  107. }
  108. grid.orNecessField.push(column.dataIndex);
  109. }else if(logic == 'necessaryField'){
  110. grid.necessaryField = column.dataIndex;
  111. if(!grid.necessaryFields){
  112. grid.necessaryFields = new Array();
  113. }
  114. grid.necessaryFields.push(column.dataIndex);
  115. if(!column.haveRendered){
  116. column.renderer = function(val, meta, record, x, y, store, view){
  117. var c = this.columns[y];
  118. if(val != null && val.toString().trim() != ''){
  119. if(c.xtype == 'datecolumn'){
  120. val = Ext.Date.format(val, 'Y-m-d');
  121. }
  122. return val;
  123. } else {
  124. if(c.xtype == 'datecolumn'){
  125. val = '';
  126. }
  127. return '<img src="' + basePath + 'resource/images/icon/need.png" title="必填字段">' +
  128. '<span style="color:blue;padding-left:2px;" title="必填字段">' + val + '</span>';
  129. }
  130. };
  131. }
  132. } else if(logic == 'groupField'){
  133. grid.groupField = column.dataIndex;
  134. }
  135. }
  136. },
  137. setReadOnly: function(bool){
  138. this.readOnly = bool;
  139. },
  140. reconfigure: function(store, columns){
  141. var d = this.headerCt;
  142. if (this.columns.length <= 1 && columns) {
  143. d.suspendLayout = true;
  144. d.removeAll();
  145. d.add(columns);
  146. }
  147. if (store) {
  148. try{
  149. this.bindStore(store);
  150. } catch (e){
  151. }
  152. } else {
  153. this.getView().refresh();
  154. }
  155. if (columns) {
  156. d.suspendLayout = false;
  157. this.forceComponentLayout();
  158. }
  159. this.fireEvent("reconfigure", this);
  160. },
  161. listeners: {
  162. afterrender: function(grid){
  163. var me = this;
  164. if(Ext.isIE){
  165. document.body.attachEvent('onkeydown', function(){
  166. if(window.event.ctrlKey && window.event.keyCode == 67){//Ctrl + C
  167. var e = window.event;
  168. if(e.srcElement) {
  169. window.clipboardData.setData('text', e.srcElement.innerHTML);
  170. }
  171. }
  172. });
  173. } else {
  174. document.body.addEventListener("mouseover", function(e){
  175. if(Ext.isFF5){
  176. e = e || window.event;
  177. }
  178. window.mouseoverData = e.target.value;
  179. });
  180. document.body.addEventListener("keydown", function(e){
  181. if(Ext.isFF5){
  182. e = e || window.event;
  183. }
  184. if(e.ctrlKey && e.keyCode == 67){
  185. me.copyToClipboard(window.mouseoverData);
  186. }
  187. if(e.ctrlKey && e.keyCode == 67){
  188. me.copyToClipboard(window.mouseoverData);
  189. }
  190. });
  191. }
  192. }
  193. }
  194. });