DataList.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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: 150,
  10. name: 'ml_caller',
  11. xtype: 'textfield',
  12. emptyText : '单据Caller'
  13. },{
  14. width: 150,
  15. name: 'ml_code',
  16. xtype: 'textfield',
  17. emptyText : '单据编号'
  18. },{
  19. width: 150,
  20. name: 'ml_man',
  21. xtype: 'textfield',
  22. emptyText : '处理人'
  23. },{
  24. cls:'x-formpanel-btn-orange',
  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:'单据Caller',
  53. dataIndex : "ml_caller",
  54. width : 200.0,
  55. },{
  56. text : "单据编号",
  57. width : 200.0,
  58. dataIndex : "ml_code",
  59. },
  60. {
  61. text : "操作",
  62. dataIndex : "ml_content",
  63. width : 220.0,
  64. },
  65. {
  66. text : "结果",
  67. dataIndex : "ml_result",
  68. width : 120.0,
  69. },
  70. {
  71. text : "处理人",
  72. dataIndex : "ml_man",
  73. width : 200,
  74. }],
  75. condition:'',
  76. initComponent: function() {
  77. var me = this;
  78. if(me.columns){
  79. var fields = me.columns.map(column => column.dataIndex);
  80. me.store = Ext.create('Ext.data.Store',{
  81. fields:fields,
  82. autoLoad: true,
  83. pageSize: 11,
  84. data: [],
  85. proxy: {
  86. timeout:8000,
  87. type: 'ajax',
  88. url: me.dataUrl,
  89. actionMethods: {
  90. read: 'GET'
  91. },
  92. reader: {
  93. type: 'json',
  94. rootProperty: 'data.list',
  95. totalProperty: 'data.total',
  96. }
  97. },
  98. listeners: {
  99. beforeload: function (store, op) {
  100. var condition = me.condition;
  101. if (Ext.isEmpty(condition)) {
  102. condition = "";
  103. }
  104. Ext.apply(store.proxy.extraParams, {
  105. number: op._page,
  106. size: store.pageSize,
  107. condition: JSON.stringify(condition)
  108. });
  109. }
  110. }
  111. });
  112. Ext.apply(me, {
  113. dockedItems:[{
  114. xtype: 'pagingtoolbar',
  115. dock: 'bottom',
  116. displayInfo: true,
  117. store: me.store
  118. }]
  119. });
  120. }
  121. me.callParent(arguments);
  122. },
  123. /**
  124. * 获得过滤条件
  125. */
  126. getCondition: function(items) {
  127. var me = this,
  128. conditions = [];
  129. for(var i = 0; i < items.length; i++) {
  130. var item = items[i];
  131. var field = item.name,
  132. func = item.getCondition,
  133. value = item.value,
  134. condition;
  135. if(typeof func == 'function') {
  136. condition = {
  137. type: 'condition',
  138. value: func(value)
  139. }
  140. }else {
  141. var xtype = item.xtype || 'textfield',
  142. type = item.fieldType || me.getDefaultFieldType(xtype),
  143. operation = item.operation || me.getDefaultFieldOperation(xtype),
  144. conditionValue = me.getConditionValue(xtype, value);
  145. if(!conditionValue) {
  146. continue;
  147. }
  148. condition = {
  149. type: type,
  150. field: field,
  151. operation: operation,
  152. value: conditionValue
  153. }
  154. }
  155. conditions.push(condition);
  156. };
  157. return conditions;
  158. },
  159. getDefaultFieldType: function(xtype) {
  160. var type;
  161. if(Ext.Array.contains(['numberfield'], xtype)) {
  162. type = 'number';
  163. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  164. type = 'date';
  165. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  166. type = 'enum';
  167. }else {
  168. type = 'string';
  169. }
  170. return type;
  171. },
  172. getDefaultFieldOperation: function(xtype) {
  173. var operation;
  174. if(Ext.Array.contains(['numberfield'], xtype)) {
  175. operation = '=';
  176. }else if(Ext.Array.contains(['datefield'], xtype)) {
  177. operation = '=';
  178. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  179. operation = 'between';
  180. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  181. operation = 'in';
  182. }else {
  183. operation = 'like';
  184. }
  185. return operation;
  186. },
  187. /**
  188. * 处理部分字段值
  189. */
  190. getConditionValue: function(xtype, value) {
  191. var conditionValue;
  192. if(xtype == 'datefield') {
  193. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  194. }else if(xtype == 'condatefield') {
  195. var from = value.from,
  196. to = value.to;
  197. 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');
  198. }else if(xtype == 'combobox' || xtype == 'combo') {
  199. conditionValue = '\'' + value + '\'';
  200. }else if(xtype == 'multicombo') {
  201. conditionValue = value.map(function(v) {
  202. return '\'' + v.value + '\'';
  203. }).join(',');
  204. }else {
  205. conditionValue = value;
  206. }
  207. return conditionValue;
  208. },
  209. refresh:function(){
  210. //debugger
  211. }
  212. });