DataList.js 6.7 KB

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