DataList.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. enableKeyEvents: true,
  14. listeners: {
  15. keydown: {
  16. fn: function(th, e, eOpts) {
  17. if(e.keyCode == 13) {
  18. var grid = th.up('grid');
  19. grid.condition = grid.getConditions();
  20. grid.store.loadPage(1);
  21. }
  22. }
  23. }
  24. }
  25. },{
  26. width: 150,
  27. name: 'ml_code',
  28. xtype: 'textfield',
  29. emptyText : '单据编号',
  30. enableKeyEvents: true,
  31. listeners: {
  32. keydown: {
  33. fn: function(th, e, eOpts) {
  34. if(e.keyCode == 13) {
  35. var grid = th.up('grid');
  36. grid.condition = grid.getConditions();
  37. grid.store.loadPage(1);
  38. }
  39. }
  40. }
  41. }
  42. },{
  43. width: 110,
  44. name: 'ml_man',
  45. xtype: 'textfield',
  46. emptyText : '操作人员',
  47. enableKeyEvents: true,
  48. listeners: {
  49. keydown: {
  50. fn: function(th, e, eOpts) {
  51. if(e.keyCode == 13) {
  52. var grid = th.up('grid');
  53. grid.condition = grid.getConditions();
  54. grid.store.loadPage(1);
  55. }
  56. }
  57. }
  58. }
  59. },{
  60. cls:'x-formpanel-btn-blue',
  61. xtype:'button',
  62. text:'查询',
  63. listeners: {
  64. click:function(b){
  65. var grid = b.ownerCt.ownerCt;
  66. grid.condition = grid.getConditions();
  67. grid.store.loadPage(1);
  68. }
  69. }
  70. },'->'],
  71. //字段属性
  72. columns : [{
  73. text : "id",
  74. width : 0,
  75. dataIndex : "id",
  76. xtype : "numbercolumn",
  77. },{
  78. text:'单据类型',
  79. dataIndex : "ml_name",
  80. width : 110.0,
  81. },{
  82. text : "单据编号",
  83. width : 150.0,
  84. dataIndex : "ml_code",
  85. },
  86. {
  87. text : "操作",
  88. dataIndex : "ml_content",
  89. width : 200.0,
  90. },
  91. {
  92. xtype:'datecolumn',
  93. format:'Y-m-d H:i:s',
  94. text : "操作时间",
  95. dataIndex : "createTime",
  96. width : 150.0,
  97. },
  98. {
  99. text : "结果",
  100. dataIndex : "ml_result",
  101. width : 150.0,
  102. },
  103. {
  104. text : "操作人员",
  105. dataIndex : "ml_man",
  106. width : 110,
  107. }, {
  108. dataIndex: '',
  109. flex: 1
  110. }],
  111. condition:'',
  112. listeners:{
  113. boxready: function(grid, width, height, eOpts) {
  114. var store = grid.getStore(),
  115. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  116. gridBodyBoxHeight = gridBodyBox.height;
  117. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  118. store.setPageSize(pageSize);
  119. }
  120. },
  121. initComponent: function() {
  122. var me = this;
  123. if(me.columns){
  124. var fields = me.columns.map(column => column.dataIndex);
  125. me.store = Ext.create('Ext.data.Store',{
  126. fields:fields,
  127. autoLoad: true,
  128. pageSize: 11,
  129. data: [],
  130. proxy: {
  131. timeout:8000,
  132. type: 'ajax',
  133. url: me.dataUrl,
  134. actionMethods: {
  135. read: 'GET'
  136. },
  137. reader: {
  138. type: 'json',
  139. rootProperty: 'data.list',
  140. totalProperty: 'data.total',
  141. }
  142. },
  143. listeners: {
  144. beforeload: function (store, op) {
  145. var condition = me.condition;
  146. if (Ext.isEmpty(condition)) {
  147. condition = "";
  148. }
  149. Ext.apply(store.proxy.extraParams, {
  150. number: op._page,
  151. size: store.pageSize,
  152. condition: JSON.stringify(condition)
  153. });
  154. }
  155. }
  156. });
  157. Ext.apply(me, {
  158. dockedItems:[{
  159. xtype: 'pagingtoolbar',
  160. dock: 'bottom',
  161. displayInfo: true,
  162. store: me.store
  163. }]
  164. });
  165. }
  166. me.callParent(arguments);
  167. },
  168. /**
  169. * 获得过滤条件
  170. */
  171. getConditions: function() {
  172. var me = this,
  173. tbar = me.getDockedItems()[0],
  174. items = tbar.items.items,
  175. conditions = [];
  176. for(var i = 0; i < items.length; i++) {
  177. var item = items[i];
  178. var field = item.name,
  179. func = item.getCondition,
  180. value = item.value,
  181. condition;
  182. if(value&&value!=''){
  183. if(typeof func == 'function') {
  184. condition = {
  185. type: 'condition',
  186. value: func(value)
  187. }
  188. }else {
  189. var type = item.fieldType || me.getDefaultFieldType(item),
  190. operation = item.operation || me.getDefaultFieldOperation(item),
  191. conditionValue = me.getConditionValue(item, value);
  192. if(!conditionValue) {
  193. continue;
  194. }
  195. condition = {
  196. type: type,
  197. field: field,
  198. operation: operation,
  199. value: conditionValue
  200. }
  201. }
  202. conditions.push(condition);
  203. }
  204. }
  205. return conditions;
  206. },
  207. /**
  208. * 只要arr1和arr2中存在相同项即返回真
  209. */
  210. isContainsAny: function (arr1, arr2) {
  211. for (var i = 0; i < arr2.length; i++) {
  212. var a2 = arr2[i];
  213. if (!!arr1.find(function (a1) {
  214. return a1 == a2
  215. })) {
  216. return true;
  217. }
  218. }
  219. return false;
  220. },
  221. getDefaultFieldType: function (field) {
  222. var me = this,
  223. xtypes = field.getXTypes().split('/'),
  224. type;
  225. if (me.isContainsAny(xtypes, ['numberfield'])) {
  226. type = 'number';
  227. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  228. type = 'date';
  229. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  230. type = 'enum';
  231. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  232. type = 'enum';
  233. } else {
  234. type = 'string';
  235. }
  236. return type;
  237. },
  238. getDefaultFieldOperation: function (field) {
  239. var me = this,
  240. xtypes = field.getXTypes().split('/'),
  241. operation;
  242. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  243. operation = '=';
  244. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  245. operation = 'between';
  246. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  247. operation = 'in';
  248. } else {
  249. operation = 'like';
  250. }
  251. return operation;
  252. },
  253. /**
  254. * 处理部分字段值
  255. */
  256. getConditionValue: function (field, value) {
  257. var me = this,
  258. xtypes = field.getXTypes().split('/'),
  259. conditionValue;
  260. if (me.isContainsAny(xtypes, ['datefield'])) {
  261. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  262. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  263. var from = value.from,
  264. to = value.to;
  265. conditionValue = from + ',' + to;
  266. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  267. var from = value.from,
  268. to = value.to;
  269. 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');
  270. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  271. conditionValue = value;
  272. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  273. conditionValue = '\'' + value + '\'';
  274. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  275. conditionValue = value.map ? value.map(function (v) {
  276. return '\'' + v.value + '\'';
  277. }).join(',') : '';
  278. } else {
  279. conditionValue = value;
  280. }
  281. return conditionValue;
  282. }
  283. });