DataList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. setupRowData: function(record, rowIndex, rowValues) {
  16. var me = this.rowExpander;
  17. me.rowBodyFeature = this;
  18. rowValues.rowBodyCls = me.recordsExpanded[record.internalId] ? '' : me.rowBodyHiddenCls;
  19. if(record.get('qutations')==null){
  20. this.rowExpander.expanderColumn.setWidth(0)
  21. }else{
  22. this.rowExpander.expanderColumn.setWidth(40)
  23. }
  24. },
  25. widget: {
  26. frame:true,
  27. cls:'x-quotation-detail',
  28. xtype: 'grid',
  29. plugins: [{
  30. ptype: 'menuclipboard'
  31. }],
  32. bind: {
  33. store: '{record.qutations}'
  34. },
  35. columns: [{
  36. text: '供应商名称',
  37. dataIndex: 'vendName',
  38. width: 175
  39. }, {
  40. text: '联系电话',
  41. dataIndex: 'tel',
  42. width: 265
  43. }, {
  44. text: '替代型号',
  45. dataIndex: 'replaceOrispeccode',
  46. width: 100,
  47. }, {
  48. width: 120,
  49. text: '交期',
  50. dataIndex: 'leadTime'
  51. }, {
  52. width: 120,
  53. text: '税率',
  54. dataIndex: 'taxRate'
  55. }, {
  56. width: 120,
  57. text: '梯度/价格',
  58. dataIndex: 'replies',
  59. renderer:function(val, meta, record,x,y,store, view){
  60. if(val==null||val==''){
  61. return '<div style="text-align: center;color:#34baf6;">暂无</div>';
  62. }
  63. var id = record.id;
  64. var renderName=this.columns[y].dataIndex;
  65. var grid = view.ownerCt;
  66. var columnId;
  67. Ext.Array.each(grid.columns, function(c, index){
  68. if(c.dataIndex=='replies'){
  69. columnId = c.id
  70. }
  71. });
  72. if(!view.tip || view.tip.createFrom != renderName) {
  73. view.tip = Ext.create('Ext.tip.ToolTip', {
  74. target: view.el,
  75. delegate: '.x-grid-cell-'+columnId,
  76. trackMouse: true,
  77. createFrom:renderName,
  78. renderTo: Ext.getBody(),
  79. maxWidth :830,
  80. layout:'anchor',
  81. listeners: {
  82. beforeshow: function updateTipBody(tip) {
  83. var dg = Ext.getCmp('grid-'+id);
  84. dg.store.loadData(val);
  85. dg.show();
  86. }
  87. },
  88. items : [Ext.create('Ext.grid.Panel', {
  89. id: 'grid-'+id,
  90. frame:true,
  91. anchor: '100% 100%',
  92. width:205,
  93. store:[],
  94. columns: [{
  95. text: '分段数量',
  96. dataIndex: 'lapQty',
  97. width: 110
  98. }, {
  99. text: '分段价格',
  100. dataIndex: 'price',
  101. width: 90
  102. }]
  103. })]
  104. });
  105. }
  106. return '<div style="text-align: center;color:#34baf6;">查看报价信息</div>';
  107. }
  108. }, {
  109. width: 200,
  110. text: '操作',
  111. dataIndex: 'agreed'
  112. }]
  113. }
  114. }],
  115. tbar: [{
  116. bodyStyle:'padding:0px 10px 0 0',
  117. xtype:'panel',
  118. layout:'column',
  119. height:75,
  120. width:'100%',
  121. rbar:{style:'padding:0',items:[{
  122. xtype:'button',
  123. cls:'x-formpanel-btn-blue',
  124. text:'查询',
  125. listeners: {
  126. click:function(b){
  127. var grid = b.ownerCt.ownerCt.ownerCt.ownerCt;
  128. grid.condition = grid.getConditions();
  129. grid.store.loadPage(1);
  130. }
  131. }
  132. },{
  133. style:'text-align: center;',
  134. xtype:'displayfield',
  135. value:'<a href=\"javascript:saas.util.BaseUtil.openTab(\'purchase-sendQuotation-datalist\',\'发起询价\',\'maintab-query-sendQuotation\')\">立即询价</a>'
  136. }]},
  137. items:[{
  138. columnWidth:0.33,
  139. name: 'search',
  140. xtype: 'textfield',
  141. emptyText : '请输入供应商名称/物料编号/品牌/名称/型号',
  142. enableKeyEvents: true,
  143. getCondition: function (value) {
  144. return value;
  145. },
  146. listeners: {
  147. keydown: {
  148. fn: function(th, e, eOpts) {
  149. if(e.keyCode == 13) {
  150. var grid = th.up('grid');
  151. grid.condition = grid.getConditions();
  152. grid.store.loadPage(1);
  153. }
  154. }
  155. }
  156. }
  157. },{
  158. columnWidth:0.33,
  159. xtype: 'combobox',
  160. name: 'quoted',
  161. fieldLabel: '报价状态',
  162. allowBlank: true,
  163. value:1,
  164. editable: false,
  165. queryMode: 'local',
  166. displayField: 'pi_status',
  167. valueField: 'pi_statuscode',
  168. store: Ext.create('Ext.data.ArrayStore', {
  169. fields: ['pi_statuscode', 'pi_status'],
  170. data: [
  171. [1, "已报价"],
  172. [0, "未报价"]
  173. ]
  174. }),
  175. getCondition: function (value) {
  176. return null
  177. }
  178. },{
  179. columnWidth:0.33,
  180. xtype: 'combobox',
  181. name: 'overdue',
  182. fieldLabel: '截止状态',
  183. allowBlank: true,
  184. value:0,
  185. editable: false,
  186. queryMode: 'local',
  187. displayField: 'pi_status',
  188. valueField: 'pi_statuscode',
  189. store: Ext.create('Ext.data.ArrayStore', {
  190. fields: ['pi_statuscode', 'pi_status'],
  191. data: [
  192. [1, "已截止"],
  193. [0, "未截止"]
  194. ]
  195. }),
  196. getCondition: function (value) {
  197. return null
  198. }
  199. },{
  200. margin:'10px 0 0 0',
  201. columnWidth:0.5,
  202. xtype: 'condatefield',
  203. name: '_date',
  204. fieldLabel: '日期',
  205. operation: 'between'
  206. }]
  207. }],
  208. columns : [{
  209. text : 'id',
  210. width : 0,
  211. dataIndex : 'id',
  212. xtype : 'numbercolumn',
  213. hidden:true
  214. },{
  215. text : '物料编号',
  216. width : 200.0,
  217. dataIndex : 'prodCode',
  218. xtype : '',
  219. },
  220. {
  221. text : '品牌',
  222. dataIndex : 'prodBrand',
  223. width : 110.0,
  224. xtype : '',
  225. },
  226. {
  227. text : '名称',
  228. dataIndex : 'prodName',
  229. width : 150.0
  230. },{
  231. text : '型号',
  232. dataIndex : 'prodOrispeccode',
  233. width : 110.0
  234. },{
  235. text : '规格',
  236. dataIndex : 'prodSpec',
  237. width : 110.0
  238. },{
  239. text : '单位',
  240. dataIndex : 'prodUnit',
  241. width : 110.0
  242. },{
  243. text : '发起时间',
  244. dataIndex : 'startDate',
  245. width : 160.0
  246. },{
  247. text : '截止日期',
  248. dataIndex : 'endDate',
  249. width : 160.0
  250. },{
  251. text : '报价状态',
  252. dataIndex : 'quoted',
  253. width : 110.0
  254. }, {
  255. dataIndex: '',
  256. flex: 1
  257. }],
  258. dbSearchFields: [],
  259. condition:'',
  260. initComponent: function() {
  261. var me = this;
  262. if(me.columns){
  263. var fields = me.columns.map(column => column.dataIndex);
  264. me.store = Ext.create('Ext.data.Store',{
  265. fields:fields,
  266. autoLoad: true,
  267. pageSize: 15,
  268. proxy: {
  269. timeout:8000,
  270. type: 'ajax',
  271. headers:{
  272. 'Access-Control-Allow-Origin': '*',
  273. "Content-Type": 'application/json;charset=UTF-8'
  274. },
  275. url: me.dataUrl,
  276. actionMethods: {
  277. read: 'GET'
  278. },
  279. reader: {
  280. type: 'json',
  281. rootProperty: 'data.content',
  282. totalProperty: 'data.totalElements',
  283. }
  284. },
  285. listeners: {
  286. beforeload: function (store, op) {
  287. var date = Ext.ComponentQuery.query('[name=_date]')[0];
  288. var from = date.value.from || '';
  289. if(!Ext.isDate(from)){
  290. from = new Date(from);
  291. from = from.getTime()
  292. }else{
  293. from = date.value.from.getTime()
  294. }
  295. var to = date.value.to || '';
  296. if(!Ext.isDate(to)){
  297. to = new Date(to);
  298. to = to.getTime()
  299. }else{
  300. to = date.value.to.getTime()
  301. }
  302. var search = Ext.ComponentQuery.query('[name=search]')[0].value;
  303. var quoted = Ext.ComponentQuery.query('[name=quoted]')[0].value;
  304. var overdue = Ext.ComponentQuery.query('[name=overdue]')[0].value;
  305. Ext.apply(store.proxy.extraParams, {
  306. keyword :search,//search==''?' ':search,
  307. pageNumber: op._page,
  308. pageSize: store.pageSize,
  309. quoted:quoted,
  310. fromDate:from,
  311. endDate:to,
  312. overdue:overdue
  313. });
  314. }
  315. }
  316. });
  317. Ext.apply(me, {
  318. dockedItems:[{
  319. xtype: 'pagingtoolbar',
  320. dock: 'bottom',
  321. displayInfo: true,
  322. store: me.store
  323. }]
  324. });
  325. }
  326. me.callParent(arguments);
  327. },
  328. listeners:{
  329. boxready: function(grid, width, height, eOpts) {
  330. var store = grid.getStore(),
  331. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  332. gridBodyBoxHeight = gridBodyBox.height;
  333. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  334. store.setPageSize(pageSize);
  335. grid.ownerCt.el.dom.style.left = '8px';
  336. grid.el.dom.style.padding = '0px'
  337. },
  338. itemClick: function(view,record,a,index,c) {
  339. }
  340. },
  341. getGridSelected:function(type){
  342. var isErrorSelect = false;
  343. var checkField = this.statusCodeField;
  344. var me = this,
  345. items = me.selModel.getSelection(),
  346. data = new Array() ;
  347. Ext.each(items, function(item, index){
  348. if(!Ext.isEmpty(item.data[me.idField])){
  349. var o = new Object();
  350. if(me.idField){
  351. o['id'] = item.data[me.idField];
  352. }
  353. if(me.codeField){
  354. o['code'] = item.data[me.codeField];
  355. }
  356. if(type&&type==item.data[checkField]){
  357. isErrorSelect = true
  358. }
  359. data.push(o);
  360. }
  361. });
  362. if(isErrorSelect){
  363. return false;
  364. }
  365. return data;
  366. },
  367. /**
  368. * 获得过滤条件
  369. */
  370. getConditions: function() {
  371. var me = this,
  372. tbar = me.getDockedItems()[0],
  373. items = Ext.Array.filter(tbar.items.items, function(item) {
  374. return !!item.name;
  375. }),
  376. conditions = [];
  377. for(var i = 0; i < items.length; i++) {
  378. var item = items[i];
  379. var field = item.name,
  380. func = item.getCondition,
  381. value = item.value,
  382. condition;
  383. if(value&&value!=''){
  384. if(typeof func == 'function') {
  385. condition = {
  386. type: 'condition',
  387. value: func(value)
  388. }
  389. }else {
  390. var type = item.fieldType || me.getDefaultFieldType(item),
  391. operation = item.operation || me.getDefaultFieldOperation(item),
  392. conditionValue = me.getConditionValue(item, value);
  393. if(!conditionValue) {
  394. continue;
  395. }
  396. condition = {
  397. type: type,
  398. field: field,
  399. operation: operation,
  400. value: conditionValue
  401. }
  402. }
  403. conditions.push(condition);
  404. }
  405. }
  406. return conditions;
  407. },
  408. /**
  409. * 只要arr1和arr2中存在相同项即返回真
  410. */
  411. isContainsAny: function (arr1, arr2) {
  412. for (var i = 0; i < arr2.length; i++) {
  413. var a2 = arr2[i];
  414. if (!!arr1.find(function (a1) {
  415. return a1 == a2
  416. })) {
  417. return true;
  418. }
  419. }
  420. return false;
  421. },
  422. getDefaultFieldType: function (field) {
  423. var me = this,
  424. xtypes = field.getXTypes().split('/'),
  425. type;
  426. if (me.isContainsAny(xtypes, ['numberfield'])) {
  427. type = 'number';
  428. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  429. type = 'date';
  430. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  431. type = 'enum';
  432. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  433. type = 'enum';
  434. } else {
  435. type = 'string';
  436. }
  437. return type;
  438. },
  439. getDefaultFieldOperation: function (field) {
  440. var me = this,
  441. xtypes = field.getXTypes().split('/'),
  442. operation;
  443. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  444. operation = '=';
  445. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  446. operation = 'between';
  447. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  448. operation = 'in';
  449. } else {
  450. operation = 'like';
  451. }
  452. return operation;
  453. },
  454. /**
  455. * 处理部分字段值
  456. */
  457. getConditionValue: function (field, value) {
  458. var me = this,
  459. xtypes = field.getXTypes().split('/'),
  460. conditionValue;
  461. if (me.isContainsAny(xtypes, ['datefield'])) {
  462. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  463. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  464. var from = value.from,
  465. to = value.to;
  466. conditionValue = from + ',' + to;
  467. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  468. var from = value.from,
  469. to = value.to;
  470. 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');
  471. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  472. conditionValue = value;
  473. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  474. conditionValue = '\'' + value + '\'';
  475. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  476. conditionValue = value.map ? value.map(function (v) {
  477. return '\'' + v.value + '\'';
  478. }).join(',') : '';
  479. } else {
  480. conditionValue = value;
  481. }
  482. return conditionValue;
  483. }
  484. })