DataList.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. Ext.define('saas.view.sys.messagelog.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sys-messagelog-datalist',
  4. autoScroll: true,
  5. frame:true,
  6. layout:'fit',
  7. dataUrl:'/api/commons/messagelog/list',
  8. tbar: [{
  9. width: 110,
  10. name: 'ml_name',
  11. xtype: 'textfield',
  12. emptyText : '单据类型'
  13. },{
  14. width: 150,
  15. name: 'ml_code',
  16. xtype: 'textfield',
  17. emptyText : '单据编号'
  18. },{
  19. width: 110,
  20. name: 'ml_man',
  21. xtype: 'textfield',
  22. emptyText : '操作人员'
  23. },{
  24. cls:'x-formpanel-btn-blue',
  25. xtype:'button',
  26. text:'查询',
  27. listeners: {
  28. click:function(b){
  29. var grid = b.ownerCt.ownerCt;
  30. var tbar = b.ownerCt;
  31. grid.condition = '';
  32. var items = [];
  33. var fields = tbar.items.items.map(f => f.name);
  34. Ext.each(fields, function(f, index){
  35. var field = tbar.down('[name='+f+']');
  36. if(field){
  37. items.push(field);
  38. }
  39. });
  40. grid.condition = grid.getCondition(items);
  41. grid.store.loadPage(1);
  42. }
  43. }
  44. },'->'],
  45. //字段属性
  46. columns : [{
  47. text : "id",
  48. width : 0,
  49. dataIndex : "id",
  50. xtype : "numbercolumn",
  51. },{
  52. text:'单据类型',
  53. dataIndex : "ml_name",
  54. width : 110.0,
  55. },{
  56. text : "单据编号",
  57. width : 150.0,
  58. dataIndex : "ml_code",
  59. },
  60. {
  61. text : "操作",
  62. dataIndex : "ml_content",
  63. width : 200.0,
  64. },
  65. {
  66. xtype:'datecolumn',
  67. format:'Y-m-d H:i:s',
  68. text : "操作时间",
  69. dataIndex : "createTime",
  70. width : 150.0,
  71. },
  72. {
  73. text : "结果",
  74. dataIndex : "ml_result",
  75. width : 150.0,
  76. },
  77. {
  78. text : "操作人员",
  79. dataIndex : "ml_man",
  80. width : 110,
  81. }],
  82. condition:'',
  83. listeners:{
  84. boxready: function(grid, width, height, eOpts) {
  85. var store = grid.getStore(),
  86. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  87. gridBodyBoxHeight = gridBodyBox.height;
  88. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  89. store.setPageSize(pageSize);
  90. }
  91. },
  92. initComponent: function() {
  93. var me = this;
  94. if(me.columns){
  95. var fields = me.columns.map(column => column.dataIndex);
  96. me.store = Ext.create('Ext.data.Store',{
  97. fields:fields,
  98. autoLoad: true,
  99. pageSize: 11,
  100. data: [],
  101. proxy: {
  102. timeout:8000,
  103. type: 'ajax',
  104. url: me.dataUrl,
  105. actionMethods: {
  106. read: 'GET'
  107. },
  108. reader: {
  109. type: 'json',
  110. rootProperty: 'data.list',
  111. totalProperty: 'data.total',
  112. }
  113. },
  114. listeners: {
  115. beforeload: function (store, op) {
  116. var condition = me.condition;
  117. if (Ext.isEmpty(condition)) {
  118. condition = "";
  119. }
  120. Ext.apply(store.proxy.extraParams, {
  121. number: op._page,
  122. size: store.pageSize,
  123. condition: JSON.stringify(condition)
  124. });
  125. }
  126. }
  127. });
  128. Ext.apply(me, {
  129. dockedItems:[{
  130. xtype: 'pagingtoolbar',
  131. dock: 'bottom',
  132. displayInfo: true,
  133. store: me.store
  134. }]
  135. });
  136. }
  137. me.callParent(arguments);
  138. },
  139. /**
  140. * 获得过滤条件
  141. */
  142. getCondition: function(items) {
  143. var me = this,
  144. conditions = [];
  145. for(var i = 0; i < items.length; i++) {
  146. var item = items[i];
  147. var field = item.name,
  148. func = item.getCondition,
  149. value = item.value,
  150. condition;
  151. if(typeof func == 'function') {
  152. condition = {
  153. type: 'condition',
  154. value: func(value)
  155. }
  156. }else {
  157. var xtype = item.xtype || 'textfield',
  158. type = item.fieldType || me.getDefaultFieldType(xtype),
  159. operation = item.operation || me.getDefaultFieldOperation(xtype),
  160. conditionValue = me.getConditionValue(xtype, value);
  161. if(!conditionValue) {
  162. continue;
  163. }
  164. condition = {
  165. type: type,
  166. field: field,
  167. operation: operation,
  168. value: conditionValue
  169. }
  170. }
  171. conditions.push(condition);
  172. };
  173. return conditions;
  174. },
  175. getDefaultFieldType: function(xtype) {
  176. var type;
  177. if(Ext.Array.contains(['numberfield'], xtype)) {
  178. type = 'number';
  179. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  180. type = 'date';
  181. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  182. type = 'enum';
  183. }else {
  184. type = 'string';
  185. }
  186. return type;
  187. },
  188. getDefaultFieldOperation: function(xtype) {
  189. var operation;
  190. if(Ext.Array.contains(['numberfield'], xtype)) {
  191. operation = '=';
  192. }else if(Ext.Array.contains(['datefield'], xtype)) {
  193. operation = '=';
  194. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  195. operation = 'between';
  196. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  197. operation = 'in';
  198. }else {
  199. operation = 'like';
  200. }
  201. return operation;
  202. },
  203. /**
  204. * 处理部分字段值
  205. */
  206. getConditionValue: function(xtype, value) {
  207. var conditionValue;
  208. if(xtype == 'datefield') {
  209. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  210. }else if(xtype == 'condatefield') {
  211. var from = value.from,
  212. to = value.to;
  213. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d 00:00:00') + ',' + Ext.Date.format(new Date(to), 'Y-m-d 23:59:59');
  214. }else if(xtype == 'combobox' || xtype == 'combo') {
  215. conditionValue = '\'' + value + '\'';
  216. }else if(xtype == 'multicombo') {
  217. conditionValue = value.map(function(v) {
  218. return '\'' + v.value + '\'';
  219. }).join(',');
  220. }else {
  221. conditionValue = value;
  222. }
  223. return conditionValue;
  224. },
  225. refresh:function(){
  226. //debugger
  227. }
  228. });