DataList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. Ext.define('saas.view.purchase.reconciliation.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'purchase-reconciliation-datalist',
  4. controller: 'purchase-reconciliation-datalist',
  5. viewModel: 'purchase-reconciliation-datalist',
  6. autoScroll: true,
  7. frame:true,
  8. layout:'fit',
  9. dataUrl:'http://10.1.80.35:8560/api/money/apcheck/list',
  10. plugins: [{
  11. ptype: 'cellediting',
  12. clicksToEdit: 1
  13. }, {
  14. ptype: 'menuclipboard'
  15. }],
  16. tbar: [{
  17. width: 280,
  18. name: 'ac_vendname',
  19. xtype: 'textfield',
  20. emptyText : '请输入供应商名称',
  21. enableKeyEvents: true,
  22. listeners: {
  23. keydown: {
  24. fn: function(th, e, eOpts) {
  25. if(e.keyCode == 13) {
  26. var grid = th.up('grid');
  27. grid.condition = grid.getConditions();
  28. grid.store.loadPage(1);
  29. }
  30. }
  31. }
  32. }
  33. },{
  34. columnWidth:0.5,
  35. xtype: 'condatefield',
  36. name: 'ac_date',
  37. fieldLabel: '日期',
  38. operation: 'between'
  39. },'->',{
  40. xtype:'button',
  41. text:'查询',
  42. listeners: {
  43. click:function(b){
  44. var grid = b.ownerCt.ownerCt;
  45. grid.condition = grid.getConditions();
  46. grid.store.loadPage(1);
  47. }
  48. }
  49. }],
  50. columns : [{
  51. text : '对账单编号',
  52. width:150,
  53. dataIndex : 'ac_code',
  54. cls:'x-querygrid-code-column',
  55. renderer:function(v,style,a,b,c){
  56. return '<span class="x-query-link" style="cursor: pointer;color: #3e80f6;border-bottom: 1px solid #3e80f6;">'+v+'</span>';
  57. }
  58. },{
  59. text : 'id',
  60. hidden:true,
  61. dataIndex : 'id',
  62. xtype : 'numbercolumn',
  63. },{
  64. text : 'ac_b2bid',
  65. hidden:true,
  66. dataIndex : 'ac_b2bid',
  67. xtype : 'numbercolumn',
  68. },{
  69. text : 'accountId',
  70. hidden:true,
  71. dataIndex : 'accountId',
  72. xtype : 'numbercolumn',
  73. },{
  74. text : 'ac_sendstatus',
  75. hidden:true,
  76. dataIndex : 'ac_sendstatus'
  77. },{
  78. text : '供应商编号',
  79. dataIndex : 'ac_vendcode',
  80. hidden:true
  81. },{
  82. text : '供应商名称',
  83. dataIndex : 'ac_vendname',
  84. width:110
  85. },{
  86. text : '币别',
  87. width : 90.0,
  88. dataIndex : 'ac_currency',
  89. },{
  90. text : '本期应付',
  91. dataIndex : 'ac_thisamount',
  92. xtype:'numbercolumn',
  93. width : 110.0,
  94. },{
  95. text : '本期发货',
  96. dataIndex : 'ac_thissend',
  97. xtype:'numbercolumn',
  98. width : 110.0,
  99. },{
  100. text : '本期未对账',
  101. dataIndex : 'ac_thisuncheck',
  102. xtype:'numbercolumn',
  103. width : 110.0,
  104. },{
  105. text : '本期已对账',
  106. dataIndex : 'ac_thischeck',
  107. xtype:'numbercolumn',
  108. width : 110.0,
  109. },{
  110. text : '本期已付',
  111. dataIndex : 'ac_thispay',
  112. xtype:'numbercolumn',
  113. width : 110.0,
  114. },{
  115. text : '应付金额',
  116. dataIndex : 'ac_payamont',
  117. xtype:'numbercolumn',
  118. width : 110.0,
  119. }],
  120. dbSearchFields: [],
  121. condition:'',
  122. initComponent: function() {
  123. var me = this;
  124. if(me.columns){
  125. var fields = me.columns.map(column => column.dataIndex);
  126. me.store = Ext.create('Ext.data.Store',{
  127. fields:fields,
  128. autoLoad: true,
  129. pageSize: 11,
  130. data: [],
  131. proxy: {
  132. timeout:8000,
  133. type: 'ajax',
  134. url: me.dataUrl,
  135. actionMethods: {
  136. read: 'GET'
  137. },
  138. reader: {
  139. type: 'json',
  140. rootProperty: 'data.list',
  141. totalProperty: 'data.total',
  142. },
  143. listeners: {
  144. exception: function(proxy, response, operation, eOpts) {
  145. if(operation.success) {
  146. if(response.timedout) {
  147. saas.util.BaseUtil.showErrorToast('请求超时');
  148. }
  149. }else {
  150. if(response.timedout) {
  151. saas.util.BaseUtil.showErrorToast('请求超时');
  152. }else{
  153. if(proxy.showPowerMessage){
  154. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  155. }
  156. }
  157. }
  158. }
  159. }
  160. },
  161. listeners: {
  162. beforeload: function (store, op) {
  163. var condition = me.condition;
  164. if (Ext.isEmpty(condition)) {
  165. condition = [];
  166. }
  167. Ext.apply(store.proxy.extraParams, {
  168. number: op._page,
  169. size: store.pageSize,
  170. condition: JSON.stringify(condition)
  171. });
  172. }
  173. }
  174. });
  175. Ext.apply(me, {
  176. dockedItems:[{
  177. xtype: 'pagingtoolbar',
  178. dock: 'bottom',
  179. displayInfo: true,
  180. store: me.store
  181. }]
  182. });
  183. }
  184. me.callParent(arguments);
  185. },
  186. listeners:{
  187. boxready: function(grid, width, height, eOpts) {
  188. var store = grid.getStore(),
  189. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  190. gridBodyBoxHeight = gridBodyBox.height;
  191. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  192. store.setPageSize(pageSize);
  193. grid.ownerCt.el.dom.style.left = '8px';
  194. grid.el.dom.style.padding = '0px'
  195. },
  196. itemClick: function(tableView, record, item, index, e, eOpts) {
  197. if(e.target.classList.contains('x-query-link')) {
  198. idValue = record.get('id'),
  199. codeValue = record.get('ac_code'),
  200. id = 'purchase-reconciliation-formpanel-' + idValue;
  201. saas.util.BaseUtil.openTab('purchase-reconciliation-formpanel', "平台对账单("+codeValue+")", id, {
  202. initId: idValue
  203. });
  204. }
  205. },
  206. },
  207. getGridSelected:function(type){
  208. var isErrorSelect = false;
  209. var checkField = this.statusCodeField;
  210. var me = this,
  211. items = me.selModel.getSelection(),
  212. data = new Array() ;
  213. Ext.each(items, function(item, index){
  214. if(!Ext.isEmpty(item.data[me.idField])){
  215. var o = new Object();
  216. if(me.idField){
  217. o['id'] = item.data[me.idField];
  218. }
  219. if(me.codeField){
  220. o['code'] = item.data[me.codeField];
  221. }
  222. if(type&&type==item.data[checkField]){
  223. isErrorSelect = true
  224. }
  225. data.push(o);
  226. }
  227. });
  228. if(isErrorSelect){
  229. return false;
  230. }
  231. return data;
  232. },
  233. /**
  234. * 获得过滤条件
  235. */
  236. getConditions: function() {
  237. var me = this,
  238. tbar = me.getDockedItems()[0],
  239. items = Ext.Array.filter(tbar.items.items, function(item) {
  240. return !!item.name;
  241. }),
  242. conditions = [];
  243. for(var i = 0; i < items.length; i++) {
  244. var item = items[i];
  245. var field = item.name,
  246. func = item.getCondition,
  247. value = item.value,
  248. condition;
  249. if(value&&value!=''){
  250. if(typeof func == 'function') {
  251. condition = {
  252. type: 'condition',
  253. value: func(value)
  254. }
  255. }else {
  256. var type = item.fieldType || me.getDefaultFieldType(item),
  257. operation = item.operation || me.getDefaultFieldOperation(item),
  258. conditionValue = me.getConditionValue(item, value);
  259. if(!conditionValue) {
  260. continue;
  261. }
  262. condition = {
  263. type: type,
  264. field: field,
  265. operation: operation,
  266. value: conditionValue
  267. }
  268. }
  269. conditions.push(condition);
  270. }
  271. }
  272. return conditions;
  273. },
  274. /**
  275. * 只要arr1和arr2中存在相同项即返回真
  276. */
  277. isContainsAny: function (arr1, arr2) {
  278. for (var i = 0; i < arr2.length; i++) {
  279. var a2 = arr2[i];
  280. if (!!arr1.find(function (a1) {
  281. return a1 == a2
  282. })) {
  283. return true;
  284. }
  285. }
  286. return false;
  287. },
  288. getDefaultFieldType: function (field) {
  289. var me = this,
  290. xtypes = field.getXTypes().split('/'),
  291. type;
  292. if (me.isContainsAny(xtypes, ['numberfield'])) {
  293. type = 'number';
  294. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  295. type = 'date';
  296. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  297. type = 'enum';
  298. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  299. type = 'enum';
  300. } else {
  301. type = 'string';
  302. }
  303. return type;
  304. },
  305. getDefaultFieldOperation: function (field) {
  306. var me = this,
  307. xtypes = field.getXTypes().split('/'),
  308. operation;
  309. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  310. operation = '=';
  311. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  312. operation = 'between';
  313. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  314. operation = 'in';
  315. } else {
  316. operation = 'like';
  317. }
  318. return operation;
  319. },
  320. /**
  321. * 处理部分字段值
  322. */
  323. getConditionValue: function (field, value) {
  324. var me = this,
  325. xtypes = field.getXTypes().split('/'),
  326. conditionValue;
  327. if (me.isContainsAny(xtypes, ['datefield'])) {
  328. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  329. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  330. var from = value.from,
  331. to = value.to;
  332. conditionValue = from + ',' + to;
  333. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  334. var from = value.from,
  335. to = value.to;
  336. 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');
  337. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  338. conditionValue = value;
  339. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  340. conditionValue = '\'' + value + '\'';
  341. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  342. conditionValue = value.map ? value.map(function (v) {
  343. return '\'' + v.value + '\'';
  344. }).join(',') : '';
  345. } else {
  346. conditionValue = value;
  347. }
  348. return conditionValue;
  349. }
  350. })