DataList.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. Ext.define('saas.view.sys.finish.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sys-finish-datalist',
  4. //工具类
  5. FormUtil: Ext.create('saas.util.FormUtil'),
  6. BaseUtil: Ext.create('saas.util.BaseUtil'),
  7. autoScroll: true,
  8. frame:true,
  9. layout:'fit',
  10. dataUrl:'/api/common/finish/list',
  11. tbar: [{
  12. width: 250,
  13. name: 'ml_caller',
  14. xtype: 'displayfield',
  15. fieldLable : '结账日'
  16. },{
  17. xtype:'button',
  18. text:'结账',
  19. },{
  20. xtype:'button',
  21. text:'反结账',
  22. },'->',{
  23. cls:'x-formpanel-btn-blue',
  24. xtype:'button',
  25. text:'刷新',
  26. listeners: {
  27. click:function(b){
  28. var grid = b.ownerCt.ownerCt;
  29. grid.store.loadPage(1);
  30. }
  31. }
  32. }],
  33. //字段属性
  34. columns : [{
  35. text : "id",
  36. width : 0,
  37. dataIndex : "id",
  38. xtype : "numbercolumn",
  39. },{
  40. text:'结账日',
  41. dataIndex : "ml_caller",
  42. xtype:'datecolumn',
  43. width : 200.0,
  44. },{
  45. text : "操作日期",
  46. width : 200.0,
  47. dataIndex : "ml_code",
  48. xtype:'datecolumn',
  49. },
  50. {
  51. text : "操作员",
  52. dataIndex : "ml_content",
  53. width : 220.0,
  54. }],
  55. condition:'',
  56. initComponent: function() {
  57. var me = this;
  58. if(me.columns){
  59. var fields = me.columns.map(column => column.dataIndex);
  60. me.store = Ext.create('Ext.data.Store',{
  61. fields:fields,
  62. autoLoad: true,
  63. pageSize: 11,
  64. data: [],
  65. proxy: {
  66. timeout:8000,
  67. type: 'ajax',
  68. url: me.dataUrl,
  69. actionMethods: {
  70. read: 'GET'
  71. },
  72. reader: {
  73. type: 'json',
  74. rootProperty: 'data.list',
  75. totalProperty: 'data.total',
  76. }
  77. },
  78. listeners: {
  79. beforeload: function (store, op) {
  80. var condition = me.condition;
  81. if (Ext.isEmpty(condition)) {
  82. condition = "";
  83. }
  84. Ext.apply(store.proxy.extraParams, {
  85. number: op._page,
  86. size: store.pageSize,
  87. condition: JSON.stringify(condition)
  88. });
  89. }
  90. }
  91. });
  92. Ext.apply(me, {
  93. dockedItems:[{
  94. xtype: 'pagingtoolbar',
  95. dock: 'bottom',
  96. displayInfo: true,
  97. store: me.store
  98. }]
  99. });
  100. }
  101. me.callParent(arguments);
  102. },
  103. /**
  104. * 获得过滤条件
  105. */
  106. getCondition: function(items) {
  107. var me = this,
  108. conditions = [];
  109. for(var i = 0; i < items.length; i++) {
  110. var item = items[i];
  111. var field = item.name,
  112. func = item.getCondition,
  113. value = item.value,
  114. condition;
  115. if(typeof func == 'function') {
  116. condition = {
  117. type: 'condition',
  118. value: func(value)
  119. }
  120. }else {
  121. var xtype = item.xtype || 'textfield',
  122. type = item.fieldType || me.getDefaultFieldType(xtype),
  123. operation = item.operation || me.getDefaultFieldOperation(xtype),
  124. conditionValue = me.getConditionValue(xtype, value);
  125. if(!conditionValue) {
  126. continue;
  127. }
  128. condition = {
  129. type: type,
  130. field: field,
  131. operation: operation,
  132. value: conditionValue
  133. }
  134. }
  135. conditions.push(condition);
  136. };
  137. return conditions;
  138. },
  139. getDefaultFieldType: function(xtype) {
  140. var type;
  141. if(Ext.Array.contains(['numberfield'], xtype)) {
  142. type = 'number';
  143. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  144. type = 'date';
  145. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  146. type = 'enum';
  147. }else {
  148. type = 'string';
  149. }
  150. return type;
  151. },
  152. getDefaultFieldOperation: function(xtype) {
  153. var operation;
  154. if(Ext.Array.contains(['numberfield'], xtype)) {
  155. operation = '=';
  156. }else if(Ext.Array.contains(['datefield'], xtype)) {
  157. operation = '=';
  158. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  159. operation = 'between';
  160. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  161. operation = 'in';
  162. }else {
  163. operation = 'like';
  164. }
  165. return operation;
  166. },
  167. /**
  168. * 处理部分字段值
  169. */
  170. getConditionValue: function(xtype, value) {
  171. var conditionValue;
  172. if(xtype == 'datefield') {
  173. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d h:i:s');
  174. }else if(xtype == 'condatefield') {
  175. var from = value.from,
  176. to = value.to;
  177. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d h:i:s') + ',' + Ext.Date.format(new Date(to), 'Y-m-d h:i:s');
  178. }else if(xtype == 'combobox' || xtype == 'combo') {
  179. conditionValue = '\'' + value + '\'';
  180. }else if(xtype == 'multicombo') {
  181. conditionValue = value.map(function(v) {
  182. return '\'' + v.value + '\'';
  183. }).join(',');
  184. }else {
  185. conditionValue = value;
  186. }
  187. return conditionValue;
  188. },
  189. refresh:function(){
  190. //debugger
  191. }
  192. });