DataList.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. cls:'x-quotation-main',
  9. layout:'fit',
  10. dataUrl:'/api/purchase/purchase/inquiry/list',
  11. quotationListUrl:'/api/commons/number/delete/',
  12. plugins: [{
  13. ptype: 'menuclipboard'
  14. },{
  15. ptype: 'rowwidget',
  16. setupRowData: function(record, rowIndex, rowValues) {
  17. var me = this.rowExpander;
  18. me.rowBodyFeature = this;
  19. rowValues.rowBodyCls = me.recordsExpanded[record.internalId] ? '' : me.rowBodyHiddenCls;
  20. if(record.get('qutations')==null){
  21. this.rowExpander.expanderColumn.setWidth(0)
  22. }else{
  23. this.rowExpander.expanderColumn.setWidth(40)
  24. }
  25. },
  26. widget: {
  27. frame:true,
  28. cls:'x-quotation-detail',
  29. xtype: 'grid',
  30. plugins: [{
  31. ptype: 'menuclipboard'
  32. }],
  33. bind: {
  34. store: '{record.qutations}'
  35. },
  36. columns: [{
  37. text: '供应商名称',
  38. dataIndex: 'vendName',
  39. width: 175
  40. }, {
  41. text: '联系电话',
  42. dataIndex: 'tel',
  43. width: 265
  44. }, {
  45. text: '替代型号',
  46. dataIndex: 'replaceOrispeccode',
  47. width: 100,
  48. }, {
  49. width: 120,
  50. text: '交期',
  51. dataIndex: 'leadTime'
  52. }, {
  53. width: 120,
  54. text: '税率',
  55. dataIndex: 'taxRate'
  56. }, {
  57. width: 120,
  58. text: '梯度/价格',
  59. dataIndex: 'replies',
  60. renderer:function(val, meta, record,x,y,store, view){
  61. if(val==null||val==''){
  62. return '<div style="text-align: center;color:#34baf6;">暂无</div>';
  63. }
  64. var id = record.id;
  65. var renderName=this.columns[y].dataIndex;
  66. var grid = view.ownerCt;
  67. var columnId;
  68. Ext.Array.each(grid.columns, function(c, index){
  69. if(c.dataIndex=='replies'){
  70. columnId = c.id
  71. }
  72. });
  73. if(!view.tip || view.tip.createFrom != renderName) {
  74. view.tip = Ext.create('Ext.tip.ToolTip', {
  75. target: view.el,
  76. delegate: '.x-grid-cell-'+columnId,
  77. trackMouse: true,
  78. createFrom:renderName,
  79. renderTo: Ext.getBody(),
  80. maxWidth :830,
  81. layout:'anchor',
  82. listeners: {
  83. beforeshow: function updateTipBody(tip) {
  84. var dg = Ext.getCmp('grid-'+id);
  85. var rowindex = tip.triggerElement.parentNode.rowIndex;
  86. var rec = Ext.getCmp(grid.id).getStore().getAt(rowindex-1);
  87. dg.store.loadData(val);
  88. dg.show();
  89. }
  90. },
  91. items : [Ext.create('Ext.grid.Panel', {
  92. id: 'grid-'+id,
  93. frame:true,
  94. anchor: '100% 100%',
  95. width:205,
  96. store:[],
  97. columns: [{
  98. text: '分段数量',
  99. dataIndex: 'lapQty',
  100. width: 110
  101. }, {
  102. text: '分段价格',
  103. dataIndex: 'price',
  104. width: 90
  105. }]
  106. })]
  107. });
  108. }
  109. return '<div style="text-align: center;color:#34baf6;">查看报价信息</div>';
  110. }
  111. }, {
  112. width: 200,
  113. text: '操作',
  114. dataIndex: 'agreed',
  115. renderer:function(val, meta, record,x,y,store, view){
  116. var id = record.get('id');
  117. window.sendMessage = function(id,status,refusereason){
  118. var params = {
  119. id:id,
  120. status:status,
  121. refusereason:refusereason
  122. };
  123. Ext.Ajax.request({
  124. url : '/api/purchase/purchase/inquiry/deal',
  125. timeout: 8000,
  126. headers:{
  127. 'Access-Control-Allow-Origin': '*',
  128. 'Authorization': saas.util.State.get('session').token,
  129. "Content-Type": 'application/json;charset=UTF-8'
  130. },
  131. method: 'POST',
  132. params:JSON.stringify(params),
  133. success: function(response, o){
  134. var res = Ext.decode(response.responseText);
  135. if(res.success){
  136. saas.util.BaseUtil.showSuccessToast('操作成功');
  137. }else{
  138. saas.util.BaseUtil.showErrorToast('操作失败:'+res.message);
  139. }
  140. },
  141. failure: function (response, opts) {
  142. saas.util.BaseUtil.showErrorToast('操作失败,请重试');
  143. }
  144. });
  145. };
  146. window.checkPrice = function(status,id){
  147. if(status=='0'){
  148. var panel = view.ownerCt.ownerCmp.ownerCt;
  149. var win = Ext.create('Ext.window.Window', {
  150. renderTo: panel.getEl(),
  151. cls:'x-window-dbfind',
  152. height: 100,
  153. width: 450,
  154. modal:true,
  155. title: '提示',
  156. bodyPadding: 10,
  157. constrain: true,
  158. closable: true,
  159. layout: {
  160. type: 'vbox',
  161. align: 'center'
  162. },
  163. items:[{
  164. xtype:'panel',
  165. layout:'hbox',
  166. items:[{
  167. margin:'0 10 0 0',
  168. labelWidth:60,
  169. xtype : "textfield",
  170. name : "refusereason",
  171. fieldLabel : "拒绝信息"
  172. },{
  173. margin:'0 0 0 5',
  174. xtype:'button',
  175. text:'确认',
  176. handler:function(b){
  177. var refusereason = b.ownerCt.down('[name=refusereason]').value;
  178. window.sendMessage(id,status,refusereason);
  179. b.ownerCt.ownerCt.close();
  180. }
  181. }]
  182. }]
  183. });
  184. win.show();
  185. }else if(status=='1'){
  186. window.sendMessage(id,status,'');
  187. }
  188. }
  189. window.showRefuse = function(msg){
  190. var panel = view.ownerCt.ownerCmp.ownerCt;
  191. var win = Ext.create('Ext.window.Window', {
  192. renderTo: panel.getEl(),
  193. cls:'x-window-dbfind',
  194. height: 100,
  195. width: 450,
  196. modal:true,
  197. title: '查看',
  198. bodyPadding: 10,
  199. constrain: true,
  200. closable: true,
  201. layout: {
  202. type: 'vbox',
  203. align: 'center'
  204. },
  205. items:[{
  206. xtype:'panel',
  207. layout:'hbox',
  208. items:[{
  209. margin:'0 10 0 0',
  210. labelWidth:60,
  211. xtype : "displayfield",
  212. name : "refusereason",
  213. fieldLabel : "拒绝信息",
  214. value:msg
  215. }]
  216. }]
  217. });
  218. win.show();
  219. }
  220. if((!val||val=='')&&val!=0){
  221. //未采纳状态
  222. return '<div style="width:100%;vertical-align: middle; text-align: center;">'+
  223. "<input type='button' value='采纳' name='agree' style='border: 1px solid;color:#34baf6;cursor:pointer;background:#fff;' onClick='window.checkPrice(1,"+id+")'>"+
  224. "<input type='button' value='拒绝' name='disagree' style='margin:0 0 0 20px;border: 1px solid;color:#ff0000;cursor:pointer;background:#fff;' onClick='window.checkPrice(0,"+id+")'>"+
  225. '</div>';
  226. }else if(val==1||val=='1'){
  227. return '<div style="color:#34baf6;width:100%;vertical-align: middle; text-align: center;">已采纳</div>'
  228. }else if(val==0||val=='0'){
  229. var refusereason = record.get('refusereason');
  230. if(!refusereason||refusereason==''){
  231. return '<div style="color:#ff6c00;width:100%;vertical-align: middle; text-align: center;">已拒绝</div>'
  232. }else{
  233. return '<div style="width:100%;vertical-align: middle; text-align: center;">'+
  234. "<input type='button' value='查看拒绝理由' name='showRefuse' style='border: 1px solid;color:#ff6c00;cursor:pointer;background:#fff;' onClick='window.showRefuse("+refusereason+")'></input>"+
  235. '</div>';
  236. }
  237. }
  238. }
  239. }]
  240. }
  241. }],
  242. tbar: [{
  243. bodyStyle:'padding:0px 10px 0 0',
  244. xtype:'panel',
  245. layout:'column',
  246. height:75,
  247. width:'100%',
  248. rbar:{style:'padding:0',items:[{
  249. xtype:'button',
  250. cls:'x-formpanel-btn-blue',
  251. text:'查询',
  252. listeners: {
  253. click:function(b){
  254. var grid = b.ownerCt.ownerCt.ownerCt.ownerCt;
  255. grid.condition = grid.getConditions();
  256. grid.store.loadPage(1);
  257. }
  258. }
  259. },{
  260. style:'text-align: center;',
  261. xtype:'displayfield',
  262. value:'<a href=\"javascript:saas.util.BaseUtil.openTab(\'purchase-sendQuotation-datalist\',\'发起询价\',\'maintab-query-sendQuotation\')\">立即询价</a>'
  263. }]},
  264. items:[{
  265. columnWidth:0.33,
  266. name: 'search',
  267. xtype: 'textfield',
  268. emptyText : '请输入供应商名称/物料编号/品牌/名称/型号',
  269. enableKeyEvents: true,
  270. getCondition: function (value) {
  271. return value;
  272. },
  273. listeners: {
  274. keydown: {
  275. fn: function(th, e, eOpts) {
  276. if(e.keyCode == 13) {
  277. var grid = th.up('grid');
  278. grid.condition = grid.getConditions();
  279. grid.store.loadPage(1);
  280. }
  281. }
  282. }
  283. }
  284. },{
  285. columnWidth:0.33,
  286. xtype: 'combobox',
  287. name: 'quoted',
  288. fieldLabel: '报价状态',
  289. allowBlank: true,
  290. value:1,
  291. editable: false,
  292. queryMode: 'local',
  293. displayField: 'pi_status',
  294. valueField: 'pi_statuscode',
  295. store: Ext.create('Ext.data.ArrayStore', {
  296. fields: ['pi_statuscode', 'pi_status'],
  297. data: [
  298. [1, "已报价"],
  299. [0, "未报价"]
  300. ]
  301. }),
  302. getCondition: function (value) {
  303. return null
  304. }
  305. },{
  306. columnWidth:0.33,
  307. xtype: 'combobox',
  308. name: 'overdue',
  309. fieldLabel: '截止状态',
  310. allowBlank: true,
  311. value:0,
  312. editable: false,
  313. queryMode: 'local',
  314. displayField: 'pi_status',
  315. valueField: 'pi_statuscode',
  316. store: Ext.create('Ext.data.ArrayStore', {
  317. fields: ['pi_statuscode', 'pi_status'],
  318. data: [
  319. [1, "已截止"],
  320. [0, "未截止"]
  321. ]
  322. }),
  323. getCondition: function (value) {
  324. return null
  325. }
  326. },{
  327. margin:'10px 0 0 0',
  328. columnWidth:0.5,
  329. xtype: 'condatefield',
  330. name: '_date',
  331. fieldLabel: '日期',
  332. operation: 'between'
  333. }]
  334. }],
  335. columns : [{
  336. text : 'id',
  337. width : 0,
  338. dataIndex : 'id',
  339. xtype : 'numbercolumn',
  340. hidden:true
  341. },{
  342. text : '物料编号',
  343. width : 200.0,
  344. dataIndex : 'prodCode',
  345. xtype : '',
  346. },
  347. {
  348. text : '品牌',
  349. dataIndex : 'prodBrand',
  350. width : 110.0,
  351. xtype : '',
  352. },
  353. {
  354. text : '名称',
  355. dataIndex : 'prodName',
  356. width : 150.0
  357. },{
  358. text : '型号',
  359. dataIndex : 'prodOrispeccode',
  360. width : 110.0
  361. },{
  362. text : '规格',
  363. dataIndex : 'prodSpec',
  364. width : 110.0
  365. },{
  366. text : '单位',
  367. dataIndex : 'prodUnit',
  368. width : 110.0
  369. },{
  370. text : '发起时间',
  371. dataIndex : 'startDate',
  372. width : 160.0
  373. },{
  374. text : '截止日期',
  375. dataIndex : 'endDate',
  376. width : 160.0
  377. },{
  378. text : '报价状态',
  379. dataIndex : 'qutations',
  380. width : 110.0,
  381. renderer:function(val, meta, record,x,y,store, view){
  382. if(!val||val==0||val.length==0){
  383. return '否'
  384. }else{
  385. return '是'
  386. }
  387. }
  388. }, {
  389. dataIndex: '',
  390. flex: 1
  391. }],
  392. dbSearchFields: [],
  393. condition:'',
  394. initComponent: function() {
  395. var me = this;
  396. if(me.columns){
  397. var fields = me.columns.map(column => column.dataIndex);
  398. me.store = Ext.create('Ext.data.Store',{
  399. fields:fields,
  400. autoLoad: true,
  401. pageSize: 15,
  402. proxy: {
  403. timeout:8000,
  404. type: 'ajax',
  405. headers:{
  406. 'Access-Control-Allow-Origin': '*',
  407. "Content-Type": 'application/json;charset=UTF-8'
  408. },
  409. url: me.dataUrl,
  410. actionMethods: {
  411. read: 'GET'
  412. },
  413. reader: {
  414. type: 'json',
  415. rootProperty: 'data.content',
  416. totalProperty: 'data.totalElements',
  417. }
  418. },
  419. listeners: {
  420. beforeload: function (store, op) {
  421. var date = Ext.ComponentQuery.query('[name=_date]')[0];
  422. var from = date.value.from || '';
  423. if(!Ext.isDate(from)){
  424. from = new Date(from);
  425. from = from.getTime()
  426. }else{
  427. from = date.value.from.getTime()
  428. }
  429. var to = date.value.to || '';
  430. if(!Ext.isDate(to)){
  431. to = new Date(to);
  432. to = to.getTime()
  433. }else{
  434. to = date.value.to.getTime()
  435. }
  436. var search = Ext.ComponentQuery.query('[name=search]')[0].value;
  437. var quoted = Ext.ComponentQuery.query('[name=quoted]')[0].value;
  438. var overdue = Ext.ComponentQuery.query('[name=overdue]')[0].value;
  439. Ext.apply(store.proxy.extraParams, {
  440. keyword :search,//search==''?' ':search,
  441. pageNumber: op._page,
  442. pageSize: store.pageSize,
  443. quoted:quoted,
  444. fromDate:from,
  445. endDate:to,
  446. overdue:overdue
  447. });
  448. }
  449. }
  450. });
  451. Ext.apply(me, {
  452. dockedItems:[{
  453. xtype: 'pagingtoolbar',
  454. dock: 'bottom',
  455. displayInfo: true,
  456. store: me.store
  457. }]
  458. });
  459. }
  460. me.callParent(arguments);
  461. },
  462. listeners:{
  463. boxready: function(grid, width, height, eOpts) {
  464. var store = grid.getStore(),
  465. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  466. gridBodyBoxHeight = gridBodyBox.height;
  467. var pageSize = Math.floor(gridBodyBoxHeight / 33);
  468. store.setPageSize(pageSize);
  469. grid.ownerCt.el.dom.style.left = '8px';
  470. grid.el.dom.style.padding = '0px'
  471. },
  472. itemClick: function(view,record,a,index,c) {
  473. }
  474. },
  475. getGridSelected:function(type){
  476. var isErrorSelect = false;
  477. var checkField = this.statusCodeField;
  478. var me = this,
  479. items = me.selModel.getSelection(),
  480. data = new Array() ;
  481. Ext.each(items, function(item, index){
  482. if(!Ext.isEmpty(item.data[me.idField])){
  483. var o = new Object();
  484. if(me.idField){
  485. o['id'] = item.data[me.idField];
  486. }
  487. if(me.codeField){
  488. o['code'] = item.data[me.codeField];
  489. }
  490. if(type&&type==item.data[checkField]){
  491. isErrorSelect = true
  492. }
  493. data.push(o);
  494. }
  495. });
  496. if(isErrorSelect){
  497. return false;
  498. }
  499. return data;
  500. },
  501. /**
  502. * 获得过滤条件
  503. */
  504. getConditions: function() {
  505. var me = this,
  506. tbar = me.getDockedItems()[0],
  507. items = Ext.Array.filter(tbar.items.items, function(item) {
  508. return !!item.name;
  509. }),
  510. conditions = [];
  511. for(var i = 0; i < items.length; i++) {
  512. var item = items[i];
  513. var field = item.name,
  514. func = item.getCondition,
  515. value = item.value,
  516. condition;
  517. if(value&&value!=''){
  518. if(typeof func == 'function') {
  519. condition = {
  520. type: 'condition',
  521. value: func(value)
  522. }
  523. }else {
  524. var type = item.fieldType || me.getDefaultFieldType(item),
  525. operation = item.operation || me.getDefaultFieldOperation(item),
  526. conditionValue = me.getConditionValue(item, value);
  527. if(!conditionValue) {
  528. continue;
  529. }
  530. condition = {
  531. type: type,
  532. field: field,
  533. operation: operation,
  534. value: conditionValue
  535. }
  536. }
  537. conditions.push(condition);
  538. }
  539. }
  540. return conditions;
  541. },
  542. /**
  543. * 只要arr1和arr2中存在相同项即返回真
  544. */
  545. isContainsAny: function (arr1, arr2) {
  546. for (var i = 0; i < arr2.length; i++) {
  547. var a2 = arr2[i];
  548. if (!!arr1.find(function (a1) {
  549. return a1 == a2
  550. })) {
  551. return true;
  552. }
  553. }
  554. return false;
  555. },
  556. getDefaultFieldType: function (field) {
  557. var me = this,
  558. xtypes = field.getXTypes().split('/'),
  559. type;
  560. if (me.isContainsAny(xtypes, ['numberfield'])) {
  561. type = 'number';
  562. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  563. type = 'date';
  564. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  565. type = 'enum';
  566. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  567. type = 'enum';
  568. } else {
  569. type = 'string';
  570. }
  571. return type;
  572. },
  573. getDefaultFieldOperation: function (field) {
  574. var me = this,
  575. xtypes = field.getXTypes().split('/'),
  576. operation;
  577. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  578. operation = '=';
  579. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  580. operation = 'between';
  581. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  582. operation = 'in';
  583. } else {
  584. operation = 'like';
  585. }
  586. return operation;
  587. },
  588. /**
  589. * 处理部分字段值
  590. */
  591. getConditionValue: function (field, value) {
  592. var me = this,
  593. xtypes = field.getXTypes().split('/'),
  594. conditionValue;
  595. if (me.isContainsAny(xtypes, ['datefield'])) {
  596. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  597. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  598. var from = value.from,
  599. to = value.to;
  600. conditionValue = from + ',' + to;
  601. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  602. var from = value.from,
  603. to = value.to;
  604. 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');
  605. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  606. conditionValue = value;
  607. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  608. conditionValue = '\'' + value + '\'';
  609. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  610. conditionValue = value.map ? value.map(function (v) {
  611. return '\'' + v.value + '\'';
  612. }).join(',') : '';
  613. } else {
  614. conditionValue = value;
  615. }
  616. return conditionValue;
  617. }
  618. })