DataList.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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:'http://192.168.253.31:8920/endProduct/list',
  11. endAccount:'http://192.168.253.31:8920/endProduct/endAccount',
  12. unEndAccount:'http://192.168.253.31:8920/endProduct/unEndAccount',
  13. tbar: [{
  14. cls:'x-tbar-display',
  15. width: 180,
  16. name: 'day',
  17. xtype: 'displayfield'
  18. },{
  19. xtype:'button',
  20. text:'结账',
  21. listeners: {
  22. click:function(b){
  23. var grid = b.ownerCt.ownerCt;
  24. grid.BaseUtil.request({
  25. url: grid.endAccount,
  26. params: '',
  27. method: 'POST',
  28. })
  29. .then(function(localJson) {
  30. if(localJson.success){
  31. showToast('结账成功');
  32. grid.store.loadPage(1);
  33. }
  34. })
  35. .catch(function(res) {
  36. console.error(res);
  37. showToast('结账失败: ' + res.message);
  38. });
  39. }
  40. }
  41. },{
  42. xtype:'button',
  43. text:'反结账',
  44. listeners: {
  45. click:function(b){
  46. var grid = b.ownerCt.ownerCt;
  47. grid.BaseUtil.request({
  48. url: grid.unEndAccount,
  49. params: '',
  50. method: 'POST',
  51. })
  52. .then(function(localJson) {
  53. if(localJson.success){
  54. showToast('反结账成功');
  55. grid.store.loadPage(1);
  56. }
  57. })
  58. .catch(function(res) {
  59. console.error(res);
  60. showToast('反结账失败: ' + res.message);
  61. });
  62. }
  63. }
  64. },'->',{
  65. cls:'x-formpanel-btn-blue',
  66. xtype:'button',
  67. text:'刷新',
  68. listeners: {
  69. click:function(b){
  70. var grid = b.ownerCt.ownerCt;
  71. grid.store.loadPage(1);
  72. }
  73. }
  74. }],
  75. //字段属性
  76. columns : [{
  77. text : "id",
  78. width : 0,
  79. dataIndex : "id",
  80. xtype : "numbercolumn",
  81. },{
  82. text:'结账日',
  83. dataIndex : "ml_caller",
  84. xtype:'datecolumn',
  85. width : 200.0,
  86. },{
  87. text : "操作日期",
  88. width : 200.0,
  89. dataIndex : "ml_code",
  90. xtype:'datecolumn',
  91. },
  92. {
  93. text : "操作员",
  94. dataIndex : "ml_content",
  95. width : 220.0,
  96. }],
  97. condition:'',
  98. initComponent: function() {
  99. var me = this;
  100. if(me.columns){
  101. var fields = me.columns.map(column => column.dataIndex);
  102. me.store = Ext.create('Ext.data.Store',{
  103. fields:fields,
  104. autoLoad: true,
  105. pageSize: 11,
  106. data: [],
  107. proxy: {
  108. parent:this,
  109. async:false,
  110. timeout:8000,
  111. type: 'ajax',
  112. url: me.dataUrl,
  113. actionMethods: {
  114. read: 'GET'
  115. },
  116. reader: {
  117. type: 'json',
  118. rootProperty: 'data.item.list',
  119. totalProperty: 'data.total',
  120. },
  121. listeners:{
  122. endprocessresponse:function(proxy,res){
  123. if(res.status=='200'){
  124. var nowTime = res.responseJson.data.main;
  125. var day = proxy.parent.dockedItems.items[2].down('[name=day]');
  126. day.setValue('当前结算年月:' + nowTime);
  127. }
  128. }
  129. }
  130. },
  131. listeners: {
  132. beforeload: function (store, op) {
  133. var condition = me.condition;
  134. if (Ext.isEmpty(condition)) {
  135. condition = "";
  136. }
  137. Ext.apply(store.proxy.extraParams, {
  138. number: op._page,
  139. size: store.pageSize,
  140. condition: JSON.stringify(condition)
  141. });
  142. },
  143. datachanged:function(){
  144. }
  145. }
  146. });
  147. Ext.apply(me, {
  148. dockedItems:[{
  149. xtype: 'pagingtoolbar',
  150. dock: 'bottom',
  151. displayInfo: true,
  152. store: me.store
  153. }]
  154. });
  155. }
  156. me.callParent(arguments);
  157. },
  158. /**
  159. * 获得过滤条件
  160. */
  161. getCondition: function(items) {
  162. var me = this,
  163. conditions = [];
  164. for(var i = 0; i < items.length; i++) {
  165. var item = items[i];
  166. var field = item.name,
  167. func = item.getCondition,
  168. value = item.value,
  169. condition;
  170. if(typeof func == 'function') {
  171. condition = {
  172. type: 'condition',
  173. value: func(value)
  174. }
  175. }else {
  176. var xtype = item.xtype || 'textfield',
  177. type = item.fieldType || me.getDefaultFieldType(xtype),
  178. operation = item.operation || me.getDefaultFieldOperation(xtype),
  179. conditionValue = me.getConditionValue(xtype, value);
  180. if(!conditionValue) {
  181. continue;
  182. }
  183. condition = {
  184. type: type,
  185. field: field,
  186. operation: operation,
  187. value: conditionValue
  188. }
  189. }
  190. conditions.push(condition);
  191. };
  192. return conditions;
  193. },
  194. getDefaultFieldType: function(xtype) {
  195. var type;
  196. if(Ext.Array.contains(['numberfield'], xtype)) {
  197. type = 'number';
  198. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  199. type = 'date';
  200. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  201. type = 'enum';
  202. }else {
  203. type = 'string';
  204. }
  205. return type;
  206. },
  207. getDefaultFieldOperation: function(xtype) {
  208. var operation;
  209. if(Ext.Array.contains(['numberfield'], xtype)) {
  210. operation = '=';
  211. }else if(Ext.Array.contains(['datefield'], xtype)) {
  212. operation = '=';
  213. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  214. operation = 'between';
  215. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  216. operation = 'in';
  217. }else {
  218. operation = 'like';
  219. }
  220. return operation;
  221. },
  222. /**
  223. * 处理部分字段值
  224. */
  225. getConditionValue: function(xtype, value) {
  226. var conditionValue;
  227. if(xtype == 'datefield') {
  228. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  229. }else if(xtype == 'condatefield') {
  230. var from = value.from,
  231. to = value.to;
  232. 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');
  233. }else if(xtype == 'combobox' || xtype == 'combo') {
  234. conditionValue = '\'' + value + '\'';
  235. }else if(xtype == 'multicombo') {
  236. conditionValue = value.map(function(v) {
  237. return '\'' + v.value + '\'';
  238. }).join(',');
  239. }else {
  240. conditionValue = value;
  241. }
  242. return conditionValue;
  243. },
  244. refresh:function(){
  245. //debugger
  246. }
  247. });