DataList.js 24 KB

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