DataList.js 9.2 KB

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