DataList.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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/commons/endProduct/list',
  11. endAccount:'/api/commons/endProduct/endAccount',
  12. unEndAccount:'/api/commons/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_keyvalue",
  84. xtype:'',
  85. width : 160.0,
  86. },{
  87. text : "操作日期",
  88. width : 200.0,
  89. format:'Y-m-d H:i:s',
  90. dataIndex : "createTime",
  91. xtype:'datecolumn',
  92. },
  93. {
  94. text : "操作类型",
  95. dataIndex : "ml_content",
  96. width : 220.0,
  97. },
  98. {
  99. text : "操作员",
  100. dataIndex : "ml_man",
  101. width : 170.0,
  102. },
  103. {
  104. text : "结果",
  105. dataIndex : "ml_result",
  106. width : 220.0,
  107. }],
  108. condition:'',
  109. initComponent: function() {
  110. var me = this;
  111. if(me.columns){
  112. var fields = me.columns.map(column => column.dataIndex);
  113. me.store = Ext.create('Ext.data.Store',{
  114. fields:fields,
  115. autoLoad: true,
  116. pageSize: 11,
  117. data: [],
  118. proxy: {
  119. parent:this,
  120. async:false,
  121. timeout:8000,
  122. type: 'ajax',
  123. url: me.dataUrl,
  124. actionMethods: {
  125. read: 'GET'
  126. },
  127. reader: {
  128. type: 'json',
  129. rootProperty: 'data.item.list',
  130. totalProperty: 'data.total',
  131. },
  132. listeners:{
  133. endprocessresponse:function(proxy,res){
  134. if(res.status=='200'){
  135. var nowTime = res.responseJson.data.main;
  136. var day = proxy.parent.dockedItems.items[2].down('[name=day]');
  137. day.setValue('当前结算年月:' + nowTime);
  138. }
  139. }
  140. }
  141. },
  142. listeners: {
  143. beforeload: function (store, op) {
  144. var condition = me.condition;
  145. if (Ext.isEmpty(condition)) {
  146. condition = "";
  147. }
  148. Ext.apply(store.proxy.extraParams, {
  149. number: op._page,
  150. size: store.pageSize,
  151. condition: JSON.stringify(condition)
  152. });
  153. },
  154. datachanged:function(){
  155. }
  156. }
  157. });
  158. Ext.apply(me, {
  159. dockedItems:[{
  160. xtype: 'pagingtoolbar',
  161. dock: 'bottom',
  162. displayInfo: true,
  163. store: me.store
  164. }]
  165. });
  166. }
  167. me.callParent(arguments);
  168. },
  169. /**
  170. * 获得过滤条件
  171. */
  172. getCondition: function(items) {
  173. var me = this,
  174. conditions = [];
  175. for(var i = 0; i < items.length; i++) {
  176. var item = items[i];
  177. var field = item.name,
  178. func = item.getCondition,
  179. value = item.value,
  180. condition;
  181. if(typeof func == 'function') {
  182. condition = {
  183. type: 'condition',
  184. value: func(value)
  185. }
  186. }else {
  187. var xtype = item.xtype || 'textfield',
  188. type = item.fieldType || me.getDefaultFieldType(xtype),
  189. operation = item.operation || me.getDefaultFieldOperation(xtype),
  190. conditionValue = me.getConditionValue(xtype, value);
  191. if(!conditionValue) {
  192. continue;
  193. }
  194. condition = {
  195. type: type,
  196. field: field,
  197. operation: operation,
  198. value: conditionValue
  199. }
  200. }
  201. conditions.push(condition);
  202. };
  203. return conditions;
  204. },
  205. getDefaultFieldType: function(xtype) {
  206. var type;
  207. if(Ext.Array.contains(['numberfield'], xtype)) {
  208. type = 'number';
  209. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  210. type = 'date';
  211. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  212. type = 'enum';
  213. }else {
  214. type = 'string';
  215. }
  216. return type;
  217. },
  218. getDefaultFieldOperation: function(xtype) {
  219. var operation;
  220. if(Ext.Array.contains(['numberfield'], xtype)) {
  221. operation = '=';
  222. }else if(Ext.Array.contains(['datefield'], xtype)) {
  223. operation = '=';
  224. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  225. operation = 'between';
  226. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  227. operation = 'in';
  228. }else {
  229. operation = 'like';
  230. }
  231. return operation;
  232. },
  233. /**
  234. * 处理部分字段值
  235. */
  236. getConditionValue: function(xtype, value) {
  237. var conditionValue;
  238. if(xtype == 'datefield') {
  239. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  240. }else if(xtype == 'condatefield') {
  241. var from = value.from,
  242. to = value.to;
  243. 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');
  244. }else if(xtype == 'combobox' || xtype == 'combo') {
  245. conditionValue = '\'' + value + '\'';
  246. }else if(xtype == 'multicombo') {
  247. conditionValue = value.map(function(v) {
  248. return '\'' + v.value + '\'';
  249. }).join(',');
  250. }else {
  251. conditionValue = value;
  252. }
  253. return conditionValue;
  254. },
  255. refresh:function(){
  256. this.ownerCt.setTitle('结账/反结账')
  257. }
  258. });