DataList.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. }
  123. },
  124. initComponent: function() {
  125. var me = this;
  126. if(me.columns){
  127. var fields = me.columns.map(column => column.dataIndex);
  128. me.store = Ext.create('Ext.data.Store',{
  129. fields:fields,
  130. autoLoad: true,
  131. pageSize: 11,
  132. data: [],
  133. proxy: {
  134. timeout:8000,
  135. type: 'ajax',
  136. url: me.dataUrl,
  137. actionMethods: {
  138. read: 'GET'
  139. },
  140. reader: {
  141. type: 'json',
  142. rootProperty: 'data.list',
  143. totalProperty: 'data.total',
  144. }
  145. },
  146. listeners: {
  147. beforeload: function (store, op) {
  148. var condition = me.condition;
  149. if (Ext.isEmpty(condition)) {
  150. condition = "";
  151. }
  152. Ext.apply(store.proxy.extraParams, {
  153. number: op._page,
  154. size: store.pageSize,
  155. condition: JSON.stringify(condition)
  156. });
  157. }
  158. }
  159. });
  160. Ext.apply(me, {
  161. dockedItems:[{
  162. xtype: 'pagingtoolbar',
  163. dock: 'bottom',
  164. displayInfo: true,
  165. store: me.store
  166. }]
  167. });
  168. }
  169. me.callParent(arguments);
  170. },
  171. /**
  172. * 获得过滤条件
  173. */
  174. getConditions: function() {
  175. var me = this,
  176. tbar = me.getDockedItems()[0],
  177. items = Ext.Array.filter(tbar.items.items, function(item) {
  178. return !!item.name;
  179. }),
  180. conditions = [];
  181. for(var i = 0; i < items.length; i++) {
  182. var item = items[i];
  183. var field = item.name,
  184. func = item.getCondition,
  185. value = item.value,
  186. condition;
  187. if(value&&value!=''){
  188. if(typeof func == 'function') {
  189. condition = {
  190. type: 'condition',
  191. value: func(value)
  192. }
  193. }else {
  194. var type = item.fieldType || me.getDefaultFieldType(item),
  195. operation = item.operation || me.getDefaultFieldOperation(item),
  196. conditionValue = me.getConditionValue(item, value);
  197. if(!conditionValue) {
  198. continue;
  199. }
  200. condition = {
  201. type: type,
  202. field: field,
  203. operation: operation,
  204. value: conditionValue
  205. }
  206. }
  207. conditions.push(condition);
  208. }
  209. }
  210. return conditions;
  211. },
  212. /**
  213. * 只要arr1和arr2中存在相同项即返回真
  214. */
  215. isContainsAny: function (arr1, arr2) {
  216. for (var i = 0; i < arr2.length; i++) {
  217. var a2 = arr2[i];
  218. if (!!arr1.find(function (a1) {
  219. return a1 == a2
  220. })) {
  221. return true;
  222. }
  223. }
  224. return false;
  225. },
  226. getDefaultFieldType: function (field) {
  227. var me = this,
  228. xtypes = field.getXTypes().split('/'),
  229. type;
  230. if (me.isContainsAny(xtypes, ['numberfield'])) {
  231. type = 'number';
  232. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  233. type = 'date';
  234. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  235. type = 'enum';
  236. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  237. type = 'enum';
  238. } else {
  239. type = 'string';
  240. }
  241. return type;
  242. },
  243. getDefaultFieldOperation: function (field) {
  244. var me = this,
  245. xtypes = field.getXTypes().split('/'),
  246. operation;
  247. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  248. operation = '=';
  249. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  250. operation = 'between';
  251. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  252. operation = 'in';
  253. } else {
  254. operation = 'like';
  255. }
  256. return operation;
  257. },
  258. /**
  259. * 处理部分字段值
  260. */
  261. getConditionValue: function (field, value) {
  262. var me = this,
  263. xtypes = field.getXTypes().split('/'),
  264. conditionValue;
  265. if (me.isContainsAny(xtypes, ['datefield'])) {
  266. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  267. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  268. var from = value.from,
  269. to = value.to;
  270. conditionValue = from + ',' + to;
  271. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  272. var from = value.from,
  273. to = value.to;
  274. 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');
  275. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  276. conditionValue = value;
  277. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  278. conditionValue = '\'' + value + '\'';
  279. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  280. conditionValue = value.map ? value.map(function (v) {
  281. return '\'' + v.value + '\'';
  282. }).join(',') : '';
  283. } else {
  284. conditionValue = value;
  285. }
  286. return conditionValue;
  287. }
  288. });