DataList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. Ext.define('saas.view.purchase.quotationList.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'purchase-quotationList-datalist',
  4. controller: 'purchase-quotationList-datalist',
  5. viewModel: 'purchase-quotationList-datalist',
  6. autoScroll: true,
  7. frame:true,
  8. layout:'fit',
  9. dataUrl:'http://10.1.80.23:8560/api/purchase/purchase/inquiry/list',
  10. quotationListUrl:'/api/commons/number/delete/',
  11. plugins: [{
  12. ptype: 'menuclipboard'
  13. },{
  14. ptype: 'rowwidget',
  15. widget: {
  16. frame:true,
  17. xtype: 'grid',
  18. bind: {
  19. store: '{record.quotationRspDTOList}',
  20. //title: 'Orders for {record.name}'
  21. },
  22. columns: [{
  23. text: '供应商名称',
  24. dataIndex: 'vendName',
  25. width: 175
  26. }, {
  27. text: '联系电话',
  28. dataIndex: 'tel',
  29. width: 265
  30. }, {
  31. text: '替代型号',
  32. dataIndex: 'replaceOrispeccode',
  33. width: 100,
  34. }, {
  35. width: 120,
  36. text: '交期',
  37. dataIndex: 'leadTime'
  38. }, {
  39. width: 120,
  40. text: '税率',
  41. dataIndex: 'taxRate'
  42. }, {
  43. width: 120,
  44. text: '分段信息',
  45. dataIndex: 'replies'
  46. }, {
  47. width: 120,
  48. text: '操作',
  49. dataIndex: 'agreed'
  50. }]
  51. }
  52. }],
  53. tbar: [{
  54. width: 310,
  55. name: 'search',
  56. xtype: 'textfield',
  57. emptyText : '请输入物料编号/品牌/名称/型号',
  58. enableKeyEvents: true,
  59. getCondition: function (value) {
  60. return ' (pr_code like\'%' + value + '%\' or pr_detail like \'%' + value + '%\' or pr_brand like \'%' + value + '%\' or pr_orispeccode like \'%' + value + '%\') ';
  61. },
  62. listeners: {
  63. keydown: {
  64. fn: function(th, e, eOpts) {
  65. if(e.keyCode == 13) {
  66. var grid = th.up('grid');
  67. grid.condition = grid.getConditions();
  68. grid.store.loadPage(1);
  69. }
  70. }
  71. }
  72. }
  73. },{
  74. cls:'x-formpanel-btn-blue',
  75. xtype:'button',
  76. text:'查询',
  77. listeners: {
  78. click:function(b){
  79. var grid = b.ownerCt.ownerCt;
  80. grid.condition = grid.getConditions();
  81. grid.store.loadPage(1);
  82. }
  83. }
  84. }],
  85. columns : [{
  86. text : 'id',
  87. width : 0,
  88. dataIndex : 'id',
  89. xtype : 'numbercolumn',
  90. hidden:true
  91. },{
  92. text : '物料编号',
  93. width : 200.0,
  94. dataIndex : 'prodCode',
  95. xtype : '',
  96. },
  97. {
  98. text : '品牌',
  99. dataIndex : 'prodBrand',
  100. width : 110.0,
  101. xtype : '',
  102. },
  103. {
  104. text : '名称',
  105. dataIndex : 'prodName',
  106. width : 150.0
  107. },{
  108. text : '型号',
  109. dataIndex : 'prodOrispeccode',
  110. width : 110.0
  111. },{
  112. text : '规格',
  113. dataIndex : 'prodSpec',
  114. width : 110.0
  115. },{
  116. text : '单位',
  117. dataIndex : 'prodUnit',
  118. width : 110.0
  119. },{
  120. text : '发起时间',
  121. dataIndex : 'startDate',
  122. width : 160.0
  123. },{
  124. text : '截止日期',
  125. dataIndex : 'endDate',
  126. width : 160.0
  127. },{
  128. text : '报价状态',
  129. dataIndex : 'quoted',
  130. width : 110.0
  131. }, {
  132. dataIndex: '',
  133. flex: 1
  134. }],
  135. dbSearchFields: [],
  136. condition:'',
  137. initComponent: function() {
  138. var me = this;
  139. if(me.columns){
  140. var fields = me.columns.map(column => column.dataIndex);
  141. me.store = Ext.create('Ext.data.Store',{
  142. fields:fields,
  143. autoLoad: true,
  144. pageSize: 15,
  145. proxy: {
  146. timeout:8000,
  147. type: 'ajax',
  148. headers:{
  149. 'Access-Control-Allow-Origin': '*',
  150. "Content-Type": 'application/json;charset=UTF-8'
  151. },
  152. url: me.dataUrl,
  153. actionMethods: {
  154. read: 'GET'
  155. },
  156. reader: {
  157. type: 'json',
  158. rootProperty: 'data.content',
  159. totalProperty: 'data.totalElements',
  160. }
  161. },
  162. listeners: {
  163. beforeload: function (store, op) {
  164. var condition = me.condition;
  165. if (Ext.isEmpty(condition)) {
  166. condition = '';
  167. }
  168. Ext.apply(store.proxy.extraParams, {
  169. keyword:condition,
  170. pageNumber: op._page,
  171. pageSize: store.pageSize,
  172. quoted:1,
  173. fromDate:null,
  174. endDate:null,
  175. overdue:0
  176. });
  177. }
  178. }
  179. });
  180. Ext.apply(me, {
  181. dockedItems:[{
  182. xtype: 'pagingtoolbar',
  183. dock: 'bottom',
  184. displayInfo: true,
  185. store: me.store
  186. }]
  187. });
  188. }
  189. me.callParent(arguments);
  190. },
  191. listeners:{
  192. boxready: function(grid, width, height, eOpts) {
  193. var store = grid.getStore(),
  194. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  195. gridBodyBoxHeight = gridBodyBox.height;
  196. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  197. store.setPageSize(pageSize);
  198. },
  199. itemClick: function(view,record,a,index,c) {
  200. }
  201. },
  202. getGridSelected:function(type){
  203. var isErrorSelect = false;
  204. var checkField = this.statusCodeField;
  205. var me = this,
  206. items = me.selModel.getSelection(),
  207. data = new Array() ;
  208. Ext.each(items, function(item, index){
  209. if(!Ext.isEmpty(item.data[me.idField])){
  210. var o = new Object();
  211. if(me.idField){
  212. o['id'] = item.data[me.idField];
  213. }
  214. if(me.codeField){
  215. o['code'] = item.data[me.codeField];
  216. }
  217. if(type&&type==item.data[checkField]){
  218. isErrorSelect = true
  219. }
  220. data.push(o);
  221. }
  222. });
  223. if(isErrorSelect){
  224. return false;
  225. }
  226. return data;
  227. },
  228. /**
  229. * 获得过滤条件
  230. */
  231. getConditions: function() {
  232. var me = this,
  233. tbar = me.getDockedItems()[0],
  234. items = Ext.Array.filter(tbar.items.items, function(item) {
  235. return !!item.name;
  236. }),
  237. conditions = [];
  238. for(var i = 0; i < items.length; i++) {
  239. var item = items[i];
  240. var field = item.name,
  241. func = item.getCondition,
  242. value = item.value,
  243. condition;
  244. if(value&&value!=''){
  245. if(typeof func == 'function') {
  246. condition = {
  247. type: 'condition',
  248. value: func(value)
  249. }
  250. }else {
  251. var type = item.fieldType || me.getDefaultFieldType(item),
  252. operation = item.operation || me.getDefaultFieldOperation(item),
  253. conditionValue = me.getConditionValue(item, value);
  254. if(!conditionValue) {
  255. continue;
  256. }
  257. condition = {
  258. type: type,
  259. field: field,
  260. operation: operation,
  261. value: conditionValue
  262. }
  263. }
  264. conditions.push(condition);
  265. }
  266. }
  267. return conditions;
  268. },
  269. /**
  270. * 只要arr1和arr2中存在相同项即返回真
  271. */
  272. isContainsAny: function (arr1, arr2) {
  273. for (var i = 0; i < arr2.length; i++) {
  274. var a2 = arr2[i];
  275. if (!!arr1.find(function (a1) {
  276. return a1 == a2
  277. })) {
  278. return true;
  279. }
  280. }
  281. return false;
  282. },
  283. getDefaultFieldType: function (field) {
  284. var me = this,
  285. xtypes = field.getXTypes().split('/'),
  286. type;
  287. if (me.isContainsAny(xtypes, ['numberfield'])) {
  288. type = 'number';
  289. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  290. type = 'date';
  291. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  292. type = 'enum';
  293. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  294. type = 'enum';
  295. } else {
  296. type = 'string';
  297. }
  298. return type;
  299. },
  300. getDefaultFieldOperation: function (field) {
  301. var me = this,
  302. xtypes = field.getXTypes().split('/'),
  303. operation;
  304. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  305. operation = '=';
  306. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  307. operation = 'between';
  308. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  309. operation = 'in';
  310. } else {
  311. operation = 'like';
  312. }
  313. return operation;
  314. },
  315. /**
  316. * 处理部分字段值
  317. */
  318. getConditionValue: function (field, value) {
  319. var me = this,
  320. xtypes = field.getXTypes().split('/'),
  321. conditionValue;
  322. if (me.isContainsAny(xtypes, ['datefield'])) {
  323. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  324. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  325. var from = value.from,
  326. to = value.to;
  327. conditionValue = from + ',' + to;
  328. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  329. var from = value.from,
  330. to = value.to;
  331. 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');
  332. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  333. conditionValue = value;
  334. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  335. conditionValue = '\'' + value + '\'';
  336. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  337. conditionValue = value.map ? value.map(function (v) {
  338. return '\'' + v.value + '\'';
  339. }).join(',') : '';
  340. } else {
  341. conditionValue = value;
  342. }
  343. return conditionValue;
  344. }
  345. })