InfoList.js 6.7 KB

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