InfoList.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. Ext.define('saas.view.home.infoCardList.InfoList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'home-infocardlist-infolist',
  4. cls: 'x-infocardlist',
  5. //基础属性
  6. border: 1,
  7. loadMask: true,
  8. columnWidth: 1.0,
  9. codeField: '',
  10. columns: [],
  11. condition: '1=1',
  12. initComponent: function () {
  13. var me = this,
  14. listUrl = me.listUrl,
  15. condition = me.initCondition(me.condition);
  16. if(me.idField == 'id') {
  17. me.idField = '_id';
  18. }
  19. Ext.apply(me, {
  20. actions: {
  21. copy: {
  22. iconCls: 'x-fa fa-copy',
  23. text: '复制单元格',
  24. handler: function() {
  25. me.onCopy(me.selectedData);
  26. }
  27. }
  28. },
  29. viewConfig: {
  30. deferEmptyText: false,
  31. listeners: {
  32. itemcontextmenu: function(view, rec, node, index, e) {
  33. e.stopEvent();
  34. me.getContextMenu().show().setLocalXY(e.getXY());
  35. me.selectedData = e.target.innerText;
  36. return false;
  37. }
  38. }
  39. },
  40. columns: me.initColumns(),
  41. store: Ext.create('Ext.data.Store', {
  42. fields: me.getFields(),
  43. autoLoad: true,
  44. pageSize: 15,
  45. data: [],
  46. proxy: {
  47. type: 'ajax',
  48. url: listUrl,
  49. timeout: 8000,
  50. actionMethods: {
  51. read: 'GET'
  52. },
  53. reader: {
  54. type: 'json',
  55. readRecordsOnFailure: false,
  56. rootProperty: 'data.list',
  57. totalProperty: 'data.total',
  58. },
  59. listeners: {
  60. exception: function(proxy, response, operation, eOpts) {
  61. if(operation.success) {
  62. if(response.timedout) {
  63. saas.util.BaseUtil.showErrorToast('请求超时');
  64. }
  65. }else {
  66. if(response.timedout) {
  67. saas.util.BaseUtil.showErrorToast('请求超时');
  68. }else{
  69. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  70. }
  71. }
  72. }
  73. }
  74. },
  75. listeners: {
  76. beforeload: function (store, op) {
  77. var conditions = [{
  78. type: 'condition',
  79. value: condition
  80. }];
  81. Ext.apply(store.proxy.extraParams, {
  82. number: store.exportNumber?store.exportNumber:op._page,
  83. size: store.exportPageSize?store.exportPageSize:store.pageSize,
  84. mode: 'DETAIL',
  85. condition: JSON.stringify(conditions)
  86. });
  87. },
  88. load: function(store, records, successful, operation, eOpts) {
  89. var datas = [];
  90. Ext.Array.each(records, function(r, i) {
  91. var d = Object.assign({}, r.data, { _id: r.data.id, id: Ext.id() });
  92. datas.push(d);
  93. });
  94. store.loadData(datas, false);
  95. me.reconfigure(store, me.initColumns());
  96. }
  97. }
  98. }),
  99. dockedItems: [{
  100. xtype: 'pagingtoolbar',
  101. cls: 'core-query-pagingtoolbar',
  102. dock: 'bottom',
  103. displayInfo: true,
  104. store: me.store
  105. }]
  106. });
  107. me.callParent(arguments);
  108. },
  109. listeners: {
  110. boxready: function(grid, width, height, eOpts) {
  111. var store = grid.getStore(),
  112. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  113. gridBodyBoxHeight = gridBodyBox.height;
  114. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  115. store.setPageSize(pageSize);
  116. },
  117. itemClick: function(tableView, record, item, index, e, eOpts) {
  118. var grid = tableView.up('grid');
  119. if(!grid.fireEvent('beforeopendetail', grid, record)) {
  120. return false;
  121. }
  122. var idField = grid.idField,
  123. codeField = grid.codeField,
  124. detailTitle = grid.detailTitle,
  125. detailXType = grid.detailXType;
  126. if(e.target.parentElement.classList.contains('x-code-column')) {
  127. var idValue = record.get(idField),
  128. codeValue = record.get(codeField),
  129. id = detailXType + '-' + idValue;
  130. saas.util.BaseUtil.openTab(detailXType, detailTitle+"("+codeValue+")", id, {
  131. initId: idValue
  132. });
  133. }
  134. },
  135. },
  136. initCondition: function(condition) {
  137. var companyId = saas.util.BaseUtil.getCurrentUser().companyId;
  138. return condition.replace('#{companyId}', companyId);;
  139. },
  140. initColumns: function() {
  141. var me = this,
  142. columns = me.listColumns;
  143. Ext.Array.each(columns, function(c) {
  144. if(c.dataIndex == me.codeField) {
  145. Ext.applyIf(c, {
  146. tdCls: 'x-code-column'
  147. });
  148. }
  149. });
  150. return columns;
  151. },
  152. getFields: function() {
  153. var me = this;
  154. return me.columns.filter(function(c) {
  155. return !!c.dataIndex;
  156. }).map(function(c) {
  157. return c.dataIndex;
  158. });
  159. },
  160. getContextMenu: function() {
  161. var me = this;
  162. return me.contextMenu || (me.contextMenu = me.add({
  163. xtype: 'menu',
  164. items: [
  165. // Actions can be converted into MenuItems
  166. '@copy',
  167. ]
  168. }));
  169. },
  170. onCopy: function(text) {
  171. var target = Ext.DomHelper.append(document.body, {
  172. tag: 'textarea',
  173. style: 'opacity: 0;position: absolute;top: -10000px;right: 0;',
  174. html: text
  175. });
  176. target.focus();
  177. target.select();
  178. document.execCommand('Copy');
  179. target.blur();
  180. document.body.removeChild(target);
  181. },
  182. refresh: function() {
  183. var me = this;
  184. me.store.reload();
  185. }
  186. });