DataList.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. Ext.define('saas.view.sys.finish.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sys-finish-datalist',
  4. autoScroll: true,
  5. frame:true,
  6. layout:'fit',
  7. dataUrl:'/api/commons/endProduct/list',
  8. endAccount:'/api/commons/endProduct/endAccount',
  9. unEndAccount:'/api/commons/endProduct/unEndAccount',
  10. tbar: [{
  11. cls:'x-tbar-display',
  12. width: 180,
  13. name: 'day',
  14. xtype: 'displayfield'
  15. },{
  16. xtype:'button',
  17. text:'结账',
  18. listeners: {
  19. click:function(b){
  20. var grid = b.ownerCt.ownerCt;
  21. saas.util.BaseUtil.request({
  22. url: grid.endAccount,
  23. params: '',
  24. method: 'POST',
  25. })
  26. .then(function(localJson) {
  27. if(localJson.success){
  28. saas.util.BaseUtil.showSuccessToast('结账成功');
  29. grid.store.loadPage(1);
  30. }
  31. })
  32. .catch(function(res) {
  33. console.error(res);
  34. saas.util.BaseUtil.showErrorToast('结账失败: ' + res.message);
  35. });
  36. }
  37. }
  38. },{
  39. xtype:'button',
  40. text:'反结账',
  41. listeners: {
  42. click:function(b){
  43. var grid = b.ownerCt.ownerCt;
  44. saas.util.BaseUtil.request({
  45. url: grid.unEndAccount,
  46. params: '',
  47. method: 'POST',
  48. })
  49. .then(function(localJson) {
  50. if(localJson.success){
  51. saas.util.BaseUtil.showSuccessToast('反结账成功');
  52. grid.store.loadPage(1);
  53. }
  54. })
  55. .catch(function(res) {
  56. console.error(res);
  57. saas.util.BaseUtil.showErrorToast('反结账失败: ' + res.message);
  58. });
  59. }
  60. }
  61. },'->',{
  62. cls:'x-formpanel-btn-blue',
  63. xtype:'button',
  64. text:'刷新',
  65. listeners: {
  66. click:function(b){
  67. var grid = b.ownerCt.ownerCt;
  68. grid.store.loadPage(1);
  69. }
  70. }
  71. }],
  72. //字段属性
  73. columns : [{
  74. text : "id",
  75. width : 0,
  76. dataIndex : "id",
  77. xtype : "numbercolumn",
  78. },{
  79. text:'结账期间',
  80. dataIndex : "ml_keyvalue",
  81. xtype:'',
  82. width : 160.0,
  83. },{
  84. text : "操作日期",
  85. width : 200.0,
  86. format:'Y-m-d H:i:s',
  87. dataIndex : "createTime",
  88. xtype:'datecolumn',
  89. },
  90. {
  91. text : "操作类型",
  92. dataIndex : "ml_content",
  93. width : 220.0,
  94. },
  95. {
  96. text : "操作员",
  97. dataIndex : "ml_man",
  98. width : 170.0,
  99. },
  100. {
  101. text : "结果",
  102. dataIndex : "ml_result",
  103. width : 220.0,
  104. }],
  105. condition:'',
  106. listeners:{
  107. boxready: function(grid, width, height, eOpts) {
  108. var store = grid.getStore(),
  109. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  110. gridBodyBoxHeight = gridBodyBox.height;
  111. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  112. store.setPageSize(pageSize);
  113. }
  114. },
  115. initComponent: function() {
  116. var me = this;
  117. if(me.columns){
  118. var fields = me.columns.map(column => column.dataIndex);
  119. me.store = Ext.create('Ext.data.Store',{
  120. fields:fields,
  121. autoLoad: true,
  122. pageSize: 11,
  123. data: [],
  124. proxy: {
  125. parent:this,
  126. async:false,
  127. timeout:8000,
  128. type: 'ajax',
  129. url: me.dataUrl,
  130. actionMethods: {
  131. read: 'GET'
  132. },
  133. reader: {
  134. type: 'json',
  135. rootProperty: 'data.item.list',
  136. totalProperty: 'data.item.total',
  137. },
  138. listeners:{
  139. endprocessresponse:function(proxy,res){
  140. if(res.status=='200'){
  141. var nowTime = res.responseJson.data.main;
  142. var day = proxy.parent.dockedItems.items[2].down('[name=day]');
  143. day.setValue('当前结算年月:' + nowTime);
  144. }
  145. }
  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. datachanged:function(){
  161. }
  162. }
  163. });
  164. Ext.apply(me, {
  165. dockedItems:[{
  166. xtype: 'pagingtoolbar',
  167. dock: 'bottom',
  168. displayInfo: true,
  169. store: me.store
  170. }]
  171. });
  172. }
  173. me.callParent(arguments);
  174. },
  175. /**
  176. * 获得过滤条件
  177. */
  178. getCondition: function(items) {
  179. var me = this,
  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(typeof func == 'function') {
  188. condition = {
  189. type: 'condition',
  190. value: func(value)
  191. }
  192. }else {
  193. var xtype = item.xtype || 'textfield',
  194. type = item.fieldType || me.getDefaultFieldType(xtype),
  195. operation = item.operation || me.getDefaultFieldOperation(xtype),
  196. conditionValue = me.getConditionValue(xtype, 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. return conditions;
  210. },
  211. getDefaultFieldType: function(xtype) {
  212. var type;
  213. if(Ext.Array.contains(['numberfield'], xtype)) {
  214. type = 'number';
  215. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  216. type = 'date';
  217. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  218. type = 'enum';
  219. }else {
  220. type = 'string';
  221. }
  222. return type;
  223. },
  224. getDefaultFieldOperation: function(xtype) {
  225. var operation;
  226. if(Ext.Array.contains(['numberfield'], xtype)) {
  227. operation = '=';
  228. }else if(Ext.Array.contains(['datefield'], xtype)) {
  229. operation = '=';
  230. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  231. operation = 'between';
  232. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  233. operation = 'in';
  234. }else {
  235. operation = 'like';
  236. }
  237. return operation;
  238. },
  239. /**
  240. * 处理部分字段值
  241. */
  242. getConditionValue: function(xtype, value) {
  243. var conditionValue;
  244. if(xtype == 'datefield') {
  245. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  246. }else if(xtype == 'condatefield') {
  247. var from = value.from,
  248. to = value.to;
  249. 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');
  250. }else if(xtype == 'combobox' || xtype == 'combo') {
  251. conditionValue = '\'' + value + '\'';
  252. }else if(xtype == 'multicombo') {
  253. conditionValue = value.map(function(v) {
  254. return '\'' + v.value + '\'';
  255. }).join(',');
  256. }else {
  257. conditionValue = value;
  258. }
  259. return conditionValue;
  260. },
  261. refresh:function(){
  262. this.ownerCt.setTitle('结账/反结账')
  263. }
  264. });