DataList.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. grid.ownerCt.el.dom.style.left = '8px';
  115. grid.el.dom.style.padding = '0px'
  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(value&&value!=''){
  191. if(typeof func == 'function') {
  192. condition = {
  193. type: 'condition',
  194. value: func(value)
  195. }
  196. }else {
  197. var xtype = item.xtype || 'textfield',
  198. type = item.fieldType || me.getDefaultFieldType(xtype),
  199. operation = item.operation || me.getDefaultFieldOperation(xtype),
  200. conditionValue = me.getConditionValue(xtype, value);
  201. if(!conditionValue) {
  202. continue;
  203. }
  204. condition = {
  205. type: type,
  206. field: field,
  207. operation: operation,
  208. value: conditionValue
  209. }
  210. }
  211. conditions.push(condition);
  212. }
  213. };
  214. return conditions;
  215. },
  216. getDefaultFieldType: function(xtype) {
  217. var type;
  218. if(Ext.Array.contains(['numberfield'], xtype)) {
  219. type = 'number';
  220. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  221. type = 'date';
  222. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  223. type = 'enum';
  224. }else {
  225. type = 'string';
  226. }
  227. return type;
  228. },
  229. getDefaultFieldOperation: function(xtype) {
  230. var operation;
  231. if(Ext.Array.contains(['numberfield'], xtype)) {
  232. operation = '=';
  233. }else if(Ext.Array.contains(['datefield'], xtype)) {
  234. operation = '=';
  235. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  236. operation = 'between';
  237. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  238. operation = 'in';
  239. }else {
  240. operation = 'like';
  241. }
  242. return operation;
  243. },
  244. /**
  245. * 处理部分字段值
  246. */
  247. getConditionValue: function(xtype, value) {
  248. var conditionValue;
  249. if(xtype == 'datefield') {
  250. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  251. }else if(xtype == 'condatefield') {
  252. var from = value.from,
  253. to = value.to;
  254. 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');
  255. }else if(xtype == 'combobox' || xtype == 'combo') {
  256. conditionValue = '\'' + value + '\'';
  257. }else if(xtype == 'multicombo') {
  258. conditionValue = value.map(function(v) {
  259. return '\'' + v.value + '\'';
  260. }).join(',');
  261. }else {
  262. conditionValue = value;
  263. }
  264. return conditionValue;
  265. },
  266. refresh:function(){
  267. this.ownerCt.setTitle('结账/反结账')
  268. }
  269. });