DataList.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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(e) {
  33. saas.util.BaseUtil.showErrorToast('结账失败: ' + e.message);
  34. });
  35. }
  36. }
  37. },{
  38. xtype:'button',
  39. text:'反结账',
  40. listeners: {
  41. click:function(b){
  42. var grid = b.ownerCt.ownerCt;
  43. saas.util.BaseUtil.request({
  44. url: grid.unEndAccount,
  45. params: '',
  46. method: 'POST',
  47. })
  48. .then(function(localJson) {
  49. if(localJson.success){
  50. saas.util.BaseUtil.showSuccessToast('反结账成功');
  51. grid.store.loadPage(1);
  52. }
  53. })
  54. .catch(function(e) {
  55. saas.util.BaseUtil.showErrorToast('反结账失败: ' + e.message);
  56. });
  57. }
  58. }
  59. },'->',{
  60. cls:'x-formpanel-btn-blue',
  61. xtype:'button',
  62. text:'刷新',
  63. listeners: {
  64. click:function(b){
  65. var grid = b.ownerCt.ownerCt;
  66. grid.store.loadPage(1);
  67. }
  68. }
  69. }],
  70. //字段属性
  71. columns : [{
  72. text : "id",
  73. width : 0,
  74. dataIndex : "id",
  75. xtype : "numbercolumn",
  76. },{
  77. text:'结账期间',
  78. dataIndex : "ml_keyvalue",
  79. xtype:'',
  80. width : 110.0,
  81. },{
  82. text : "操作日期",
  83. width : 220.0,
  84. format:'Y-m-d H:i:s',
  85. dataIndex : "createTime",
  86. xtype:'datecolumn',
  87. },
  88. {
  89. text : "操作类型",
  90. dataIndex : "ml_content",
  91. width : 110.0,
  92. },
  93. {
  94. text : "操作员",
  95. dataIndex : "ml_man",
  96. width : 110.0,
  97. },
  98. {
  99. text : "结果",
  100. dataIndex : "ml_result",
  101. width : 250.0,
  102. }, {
  103. dataIndex: '',
  104. flex: 1
  105. }],
  106. condition:'',
  107. listeners:{
  108. boxready: function(grid, width, height, eOpts) {
  109. var store = grid.getStore(),
  110. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  111. gridBodyBoxHeight = gridBodyBox.height;
  112. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  113. store.setPageSize(pageSize);
  114. }
  115. },
  116. initComponent: function() {
  117. var me = this;
  118. if(me.columns){
  119. var fields = me.columns.map(column => column.dataIndex);
  120. me.store = Ext.create('Ext.data.Store',{
  121. fields:fields,
  122. autoLoad: true,
  123. pageSize: 11,
  124. data: [],
  125. proxy: {
  126. parent:this,
  127. async:false,
  128. timeout:8000,
  129. type: 'ajax',
  130. url: me.dataUrl,
  131. actionMethods: {
  132. read: 'GET'
  133. },
  134. reader: {
  135. type: 'json',
  136. rootProperty: 'data.item.list',
  137. totalProperty: 'data.item.total',
  138. },
  139. listeners:{
  140. endprocessresponse:function(proxy,res){
  141. if(res.status=='200'){
  142. var nowTime = res.responseJson.data.main;
  143. var day = proxy.parent.dockedItems.items[2].down('[name=day]');
  144. day.setValue('当前结算年月:' + nowTime);
  145. }
  146. }
  147. }
  148. },
  149. listeners: {
  150. beforeload: function (store, op) {
  151. var condition = me.condition;
  152. if (Ext.isEmpty(condition)) {
  153. condition = "";
  154. }
  155. Ext.apply(store.proxy.extraParams, {
  156. number: op._page,
  157. size: store.pageSize,
  158. condition: JSON.stringify(condition)
  159. });
  160. },
  161. datachanged:function(){
  162. }
  163. }
  164. });
  165. Ext.apply(me, {
  166. dockedItems:[{
  167. xtype: 'pagingtoolbar',
  168. dock: 'bottom',
  169. displayInfo: true,
  170. store: me.store
  171. }]
  172. });
  173. }
  174. me.callParent(arguments);
  175. },
  176. /**
  177. * 获得过滤条件
  178. */
  179. getCondition: function(items) {
  180. var me = this,
  181. conditions = [];
  182. for(var i = 0; i < items.length; i++) {
  183. var item = items[i];
  184. var field = item.name,
  185. func = item.getCondition,
  186. value = item.value,
  187. condition;
  188. if(value&&value!=''){
  189. if(typeof func == 'function') {
  190. condition = {
  191. type: 'condition',
  192. value: func(value)
  193. }
  194. }else {
  195. var xtype = item.xtype || 'textfield',
  196. type = item.fieldType || me.getDefaultFieldType(xtype),
  197. operation = item.operation || me.getDefaultFieldOperation(xtype),
  198. conditionValue = me.getConditionValue(xtype, value);
  199. if(!conditionValue) {
  200. continue;
  201. }
  202. condition = {
  203. type: type,
  204. field: field,
  205. operation: operation,
  206. value: conditionValue
  207. }
  208. }
  209. conditions.push(condition);
  210. }
  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. });