SysCheckGrid.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. Ext.define('erp.view.ma.SysCheckGrid',{
  2. extend : 'Ext.grid.Panel',
  3. alias : 'widget.erpSysCheckGrid',
  4. requires : [ 'erp.view.core.toolbar.Toolbar' ],
  5. layout : 'fit',
  6. id : 'sysgrid',
  7. emptyText : $I18N.common.grid.emptyText,
  8. columnLines : true,
  9. autoScroll : true,
  10. animCollapse : false,
  11. columns : [],
  12. store : [],
  13. bodyStyle : 'background-color:#f1f1f1;',
  14. plugins : [ {
  15. ptype : 'rowexpander',
  16. rowBodyTpl : [ '<p><b>包含信息:</b> {details}</p>', ]
  17. } ],
  18. features : [ {
  19. ftype : 'summary',
  20. showSummaryRow : false,// 不显示默认合计行
  21. generateSummaryData : function() {
  22. var me = this, data = {}, store = me.view.store, columns = me.view.headerCt
  23. .getColumnsForTpl(), i = 0, length = columns.length,
  24. // fieldData,
  25. // key,
  26. comp;
  27. // 将feature的data打印在toolbar上面
  28. for (i = 0, length = columns.length; i < length; ++i) {
  29. comp = Ext.getCmp(columns[i].id);
  30. data[comp.id] = me
  31. .getSummary(store, comp.summaryType,
  32. comp.dataIndex, false);
  33. var tb = Ext.getCmp(columns[i].dataIndex + '_'
  34. + comp.summaryType);
  35. if (tb) {
  36. var val = data[comp.id];
  37. if (columns[i].xtype == 'numbercolumn') {
  38. val = Ext.util.Format.number(val,(columns[i].format || '0,000.000'));
  39. }
  40. tb.setText(tb.text.split(':')[0] + ':'
  41. + val);
  42. }
  43. }
  44. return data;
  45. }
  46. } ],
  47. bbar : {
  48. xtype : 'erpToolbar',
  49. id:'systoolbar',
  50. listeners : {
  51. afterrender : function(bar) {
  52. bar.removeAll();
  53. bar.add('-', {
  54. text : '合计栏',
  55. xtype : 'tbtext',
  56. }, {
  57. xtype : 'splitter',
  58. width : 10
  59. }, {
  60. id : 'warncount_sum',
  61. itemId : 'warncount',
  62. xtype : 'tbtext',
  63. text : '提醒:0',
  64. margin : '0 0 10 0'
  65. }, {
  66. xtype : 'splitter',
  67. width : 10
  68. }, {
  69. id : 'publishcount_sum',
  70. itemId : 'publishcount',
  71. xtype : 'tbtext',
  72. text : '处罚:0',
  73. margin : '0 0 10 0'
  74. }, {
  75. xtype : 'splitter',
  76. width : 10
  77. }, {
  78. id : 'publishamountcount_sum',
  79. itemId : 'publishamountcount',
  80. xtype : 'tbtext',
  81. text : '处罚分数:0',
  82. margin : '0 0 10 0'
  83. });
  84. }
  85. }
  86. },
  87. GridUtil : Ext.create('erp.util.GridUtil'),
  88. BaseUtil : Ext.create('erp.util.BaseUtil'),
  89. necessaryField : '',// 必填字段
  90. detno : '',// 编号字段
  91. keyField : '',// 主键字段
  92. mainField : '',// 对应主表主键的字段
  93. dbfinds : [],
  94. caller : null,
  95. condition : null,
  96. initComponent : function() {
  97. this.getStore(this);
  98. this.callParent(arguments);
  99. },
  100. getStore : function(grid) {
  101. var columns = [ {
  102. name : 'orgid',
  103. dataIndex : 'orgid',
  104. id : 'orgid',
  105. header : '组织ID',
  106. width : 0,
  107. cls : 'x-grid-header-1'
  108. }, {
  109. name : 'orgname',
  110. id : 'orgname',
  111. dataIndex : 'orgname',
  112. header : '对象名称',
  113. flex:1,
  114. cls : 'x-grid-header-1'
  115. }, {
  116. name : 'warncount',
  117. id : 'warncount',
  118. dataIndex : 'warncount',
  119. header : '提醒总数',
  120. summaryType : 'sum',
  121. align:'right',
  122. cls : 'x-grid-header-1',
  123. }, {
  124. name : 'publishcount',
  125. id : 'publishcount',
  126. dataIndex : 'publishcount',
  127. header : '处罚总数',
  128. align:'right',
  129. summaryType : 'sum',
  130. cls : 'x-grid-header-1'
  131. }, {
  132. name : 'publishamountcount',
  133. id : 'publishamountcount',
  134. dataIndex : 'publishamountcount',
  135. header : '处罚分总数',
  136. align:'right',
  137. summaryType : 'sum',
  138. cls : 'x-grid-header-1'
  139. }, {
  140. name : 'orgheader',
  141. id : 'orgheader',
  142. dataIndex : 'orgheader',
  143. header : '组织负责人',
  144. cls : 'x-grid-header-1'
  145. }, {
  146. name : 'details',
  147. id : 'details',
  148. dataIndex : 'details',
  149. header : '详细信息',
  150. width:0,
  151. cls : 'x-grid-header-1'
  152. } ];
  153. Ext.Ajax.request({
  154. url : basePath+ 'ma/SysCheck/getDataByOrg.action',
  155. method : 'post',
  156. params : {
  157. _noc : 1,
  158. parentid : 0,
  159. },
  160. async : false,
  161. callback : function(options, success,
  162. response) {
  163. var res = new Ext.decode(
  164. response.responseText);
  165. if (res.exceptionInfo != null) {
  166. showError(res.exceptionInfo);
  167. return;
  168. } else {
  169. if (res.success) {
  170. var store = Ext
  171. .create(
  172. 'Ext.data.Store',
  173. {
  174. fields : [
  175. {
  176. type : 'int',
  177. name : 'orgid'
  178. },
  179. {
  180. type : 'string',
  181. name : 'orgname'
  182. },
  183. {
  184. type : 'int',
  185. name : 'warncount'
  186. },
  187. {
  188. type : 'int',
  189. name : 'publishcount'
  190. },
  191. {
  192. type : 'int',
  193. name : 'publishamountcount'
  194. },
  195. {
  196. type : 'string',
  197. name : 'orgheader'
  198. },
  199. {
  200. type : 'string',
  201. name : 'details'
  202. } ],
  203. data : new Ext.decode(
  204. res.data)
  205. });
  206. grid.columns = columns;
  207. grid.store = store;
  208. }
  209. }
  210. }
  211. });
  212. },
  213. getEffectiveData : function() {
  214. var me = this;
  215. var effective = new Array();
  216. var s = this.store.data.items;
  217. for ( var i = 0; i < s.length; i++) {
  218. var data = s[i].data;
  219. if (data[me.keyField] != null
  220. && data[me.keyField] != "") {
  221. effective.push(data);
  222. }
  223. }
  224. return effective;
  225. },
  226. loadNewStore:function(grid,param){
  227. var me = this;
  228. var main = parent.Ext.getCmp("content-panel");
  229. if(!main)
  230. main = parent.parent.Ext.getCmp("content-panel");
  231. if(main){
  232. main.getActiveTab().setLoading(true);//loading...
  233. }
  234. Ext.Ajax.request({//拿到grid的columns
  235. url : basePath +'ma/SysCheck/getDataByOrg.action',
  236. params: param,
  237. method : 'post',
  238. callback : function(options,success,response){
  239. if(main){
  240. main.getActiveTab().setLoading(false);
  241. }
  242. var res = new Ext.decode(response.responseText);
  243. if(res.exceptionInfo){
  244. showError(res.exceptionInfo);return;
  245. }
  246. var data = [];
  247. if(!res.data || res.data.length == 2){
  248. grid.store.removeAll();
  249. } else {
  250. data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  251. grid.store.loadData(data);
  252. }
  253. //自定义event
  254. grid.addEvents({
  255. storeloaded: true
  256. });
  257. grid.fireEvent('storeloaded', grid, data);
  258. }
  259. });
  260. },
  261. setReadOnly : function(bool) {
  262. this.readOnly = bool;
  263. },
  264. reconfigure : function(store, columns) {
  265. var d = this.headerCt;
  266. if (this.columns.length <= 1 && columns) {
  267. d.suspendLayout = true;
  268. d.removeAll();
  269. d.add(columns);
  270. }
  271. if (store) {
  272. try {
  273. this.bindStore(store);
  274. } catch (e) {
  275. }
  276. } else {
  277. this.getView().refresh();
  278. }
  279. if (columns) {
  280. d.suspendLayout = false;
  281. this.forceComponentLayout();
  282. }
  283. this.fireEvent("reconfigure", this);
  284. },
  285. /**
  286. * Grid上一条
  287. */
  288. /*
  289. * prev: function(grid, record){ grid = grid ||
  290. * Ext.getCmp('grid'); record = record ||
  291. * grid.selModel.lastSelected; if(record){ //递归查找上一条,并取到数据
  292. * var d = grid.store.getAt(record.index - 1); if(d){ try {
  293. * grid.selModel.select(d); return d; } catch (e){ } } else {
  294. * if(record.index - 1 > 0){ return this.prev(grid, d); }
  295. * else { return null; } } } },
  296. *//**
  297. * Grid下一条
  298. */
  299. /*
  300. * next: function(grid, record){ grid = grid ||
  301. * Ext.getCmp('grid'); record = record ||
  302. * grid.selModel.lastSelected; if(record){ //递归查找下一条,并取到数据
  303. * var d = grid.store.getAt(record.index + 1); if(d){ try {
  304. * grid.selModel.select(d); return d; } catch (e){ } } else {
  305. * if(record.index + 1 < grid.store.data.items.length){
  306. * return this.next(grid, d); } else { return null; } } } },
  307. */
  308. listeners : {
  309. afterrender : function(grid) {
  310. var me = this;
  311. if (Ext.isIE) {
  312. document.body
  313. .attachEvent(
  314. 'onkeydown',
  315. function() {
  316. if (window.event.ctrlKey
  317. && window.event.keyCode == 67) {// Ctrl
  318. // + C
  319. var e = window.event;
  320. if (e.srcElement) {
  321. window.clipboardData
  322. .setData(
  323. 'text',
  324. e.srcElement.innerHTML);
  325. }
  326. }
  327. });
  328. } else {
  329. document.body
  330. .addEventListener(
  331. "mouseover",
  332. function(e) {
  333. if (Ext.isFF5) {
  334. e = e || window.event;
  335. }
  336. window.mouseoverData = e.target.value;
  337. });
  338. document.body
  339. .addEventListener(
  340. "keydown",
  341. function(e) {
  342. if (Ext.isFF5) {
  343. e = e || window.event;
  344. }
  345. if (e.ctrlKey
  346. && e.keyCode == 67) {
  347. me
  348. .copyToClipboard(window.mouseoverData);
  349. }
  350. if (e.ctrlKey
  351. && e.keyCode == 67) {
  352. me
  353. .copyToClipboard(window.mouseoverData);
  354. }
  355. });
  356. }
  357. }
  358. },
  359. copyToClipboard : function(txt) {
  360. if (window.clipboardData) {
  361. window.clipboardData.clearData();
  362. window.clipboardData.setData('text', txt);
  363. } else if (navigator.userAgent.indexOf('Opera') != -1) {
  364. window.location = txt;
  365. } else if (window.netscape) {
  366. try {
  367. netscape.security.PrivilegeManager
  368. .enablePrivilege('UniversalXPConnect');
  369. } catch (e) {
  370. alert("您的firefox安全限制限制您进行剪贴板操作,请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试");
  371. return false;
  372. }
  373. }
  374. }
  375. });