DataList.js 24 KB

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