DataList.js 8.6 KB

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