InfoList.js 6.6 KB

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