Ext.define('saas.view.purchase.quotationList.DataList', {
extend: 'Ext.grid.Panel',
xtype: 'purchase-quotationList-datalist',
controller: 'purchase-quotationList-datalist',
viewModel: 'purchase-quotationList-datalist',
autoScroll: true,
frame:true,
cls:'x-quotation-main',
layout:'fit',
dataUrl:'/api/purchase/purchase/inquiry/list',
quotationListUrl:'/api/commons/number/delete/',
plugins: [{
ptype: 'menuclipboard'
},{
ptype: 'rowwidget',
setupRowData: function(record, rowIndex, rowValues) {
var me = this.rowExpander;
me.rowBodyFeature = this;
rowValues.rowBodyCls = me.recordsExpanded[record.internalId] ? '' : me.rowBodyHiddenCls;
if(record.get('qutations')==null){
this.rowExpander.expanderColumn.setWidth(0)
}else{
this.rowExpander.expanderColumn.setWidth(40)
}
},
widget: {
frame:true,
cls:'x-quotation-detail',
xtype: 'grid',
plugins: [{
ptype: 'menuclipboard'
}],
bind: {
store: '{record.qutations}'
},
columns: [{
text: '供应商名称',
dataIndex: 'vendName',
width: 175
}, {
text: '联系电话',
dataIndex: 'tel',
width: 265
}, {
text: '替代型号',
dataIndex: 'replaceOrispeccode',
width: 100,
}, {
width: 120,
text: '交期',
dataIndex: 'leadTime'
}, {
width: 120,
text: '税率',
dataIndex: 'taxRate'
}, {
width: 120,
text: '梯度/价格',
dataIndex: 'replies',
renderer:function(val, meta, record,x,y,store, view){
if(val==null||val==''){
return '
暂无
';
}
var id = record.id;
var renderName=this.columns[y].dataIndex;
var grid = view.ownerCt;
var columnId;
Ext.Array.each(grid.columns, function(c, index){
if(c.dataIndex=='replies'){
columnId = c.id
}
});
if(!view.tip || view.tip.createFrom != renderName) {
view.tip = Ext.create('Ext.tip.ToolTip', {
target: view.el,
delegate: '.x-grid-cell-'+columnId,
trackMouse: true,
createFrom:renderName,
renderTo: Ext.getBody(),
maxWidth :830,
layout:'anchor',
listeners: {
beforeshow: function updateTipBody(tip) {
var dg = Ext.getCmp('grid-'+id);
var rowindex = tip.triggerElement.parentNode.rowIndex;
var rec = Ext.getCmp(grid.id).getStore().getAt(rowindex-1);
dg.store.loadData(val);
dg.show();
}
},
items : [Ext.create('Ext.grid.Panel', {
id: 'grid-'+id,
frame:true,
anchor: '100% 100%',
width:205,
store:[],
columns: [{
text: '分段数量',
dataIndex: 'lapQty',
width: 110
}, {
text: '分段价格',
dataIndex: 'price',
width: 90
}]
})]
});
}
return '查看报价信息
';
}
}, {
width: 200,
text: '操作',
dataIndex: 'agreed',
renderer:function(val, meta, record,x,y,store, view){
var id = record.get('id');
window.sendMessage = function(id,status,refusereason){
var params = {
id:id,
status:status,
refusereason:refusereason
};
Ext.Ajax.request({
url : '/api/purchase/purchase/inquiry/deal',
timeout: 8000,
headers:{
'Access-Control-Allow-Origin': '*',
'Authorization': saas.util.State.get('session').token,
"Content-Type": 'application/json;charset=UTF-8'
},
method: 'POST',
params:JSON.stringify(params),
success: function(response, o){
var res = Ext.decode(response.responseText);
if(res.success){
saas.util.BaseUtil.showSuccessToast('操作成功');
}else{
saas.util.BaseUtil.showErrorToast('操作失败:'+res.message);
}
},
failure: function (response, opts) {
saas.util.BaseUtil.showErrorToast('操作失败,请重试');
}
});
};
window.checkPrice = function(status,id){
if(status=='0'){
var panel = view.ownerCt.ownerCmp.ownerCt;
var win = Ext.create('Ext.window.Window', {
renderTo: panel.getEl(),
cls:'x-window-dbfind',
height: 100,
width: 450,
modal:true,
title: '提示',
bodyPadding: 10,
constrain: true,
closable: true,
layout: {
type: 'vbox',
align: 'center'
},
items:[{
xtype:'panel',
layout:'hbox',
items:[{
margin:'0 10 0 0',
labelWidth:60,
xtype : "textfield",
name : "refusereason",
fieldLabel : "拒绝信息"
},{
margin:'0 0 0 5',
xtype:'button',
text:'确认',
handler:function(b){
var refusereason = b.ownerCt.down('[name=refusereason]').value;
window.sendMessage(id,status,refusereason);
b.ownerCt.ownerCt.close();
}
}]
}]
});
win.show();
}else if(status=='1'){
window.sendMessage(id,status,'');
}
}
window.showRefuse = function(msg){
var panel = view.ownerCt.ownerCmp.ownerCt;
var win = Ext.create('Ext.window.Window', {
renderTo: panel.getEl(),
cls:'x-window-dbfind',
height: 100,
width: 450,
modal:true,
title: '查看',
bodyPadding: 10,
constrain: true,
closable: true,
layout: {
type: 'vbox',
align: 'center'
},
items:[{
xtype:'panel',
layout:'hbox',
items:[{
margin:'0 10 0 0',
labelWidth:60,
xtype : "displayfield",
name : "refusereason",
fieldLabel : "拒绝信息",
value:msg
}]
}]
});
win.show();
}
if((!val||val=='')&&val!=0){
//未采纳状态
return ''+
""+
""+
'
';
}else if(val==1||val=='1'){
return '已采纳
'
}else if(val==0||val=='0'){
var refusereason = record.get('refusereason');
if(!refusereason||refusereason==''){
return '已拒绝
'
}else{
return ''+
""+
'
';
}
}
}
}]
}
}],
tbar: [{
bodyStyle:'padding:0px 10px 0 0',
xtype:'panel',
layout:'column',
height:75,
width:'100%',
rbar:{style:'padding:0',items:[{
xtype:'button',
cls:'x-formpanel-btn-blue',
text:'查询',
listeners: {
click:function(b){
var grid = b.ownerCt.ownerCt.ownerCt.ownerCt;
grid.condition = grid.getConditions();
grid.store.loadPage(1);
}
}
},{
style:'text-align: center;',
xtype:'displayfield',
value:'立即询价'
}]},
items:[{
columnWidth:0.33,
name: 'search',
xtype: 'textfield',
emptyText : '请输入供应商名称/物料编号/品牌/名称/型号',
enableKeyEvents: true,
getCondition: function (value) {
return value;
},
listeners: {
keydown: {
fn: function(th, e, eOpts) {
if(e.keyCode == 13) {
var grid = th.up('grid');
grid.condition = grid.getConditions();
grid.store.loadPage(1);
}
}
}
}
},{
columnWidth:0.33,
xtype: 'combobox',
name: 'quoted',
fieldLabel: '报价状态',
allowBlank: true,
value:1,
editable: false,
queryMode: 'local',
displayField: 'pi_status',
valueField: 'pi_statuscode',
store: Ext.create('Ext.data.ArrayStore', {
fields: ['pi_statuscode', 'pi_status'],
data: [
[1, "已报价"],
[0, "未报价"]
]
}),
getCondition: function (value) {
return null
}
},{
columnWidth:0.33,
xtype: 'combobox',
name: 'overdue',
fieldLabel: '截止状态',
allowBlank: true,
value:0,
editable: false,
queryMode: 'local',
displayField: 'pi_status',
valueField: 'pi_statuscode',
store: Ext.create('Ext.data.ArrayStore', {
fields: ['pi_statuscode', 'pi_status'],
data: [
[1, "已截止"],
[0, "未截止"]
]
}),
getCondition: function (value) {
return null
}
},{
margin:'10px 0 0 0',
columnWidth:0.5,
xtype: 'condatefield',
name: '_date',
fieldLabel: '日期',
operation: 'between'
}]
}],
columns : [{
text : 'id',
width : 0,
dataIndex : 'id',
xtype : 'numbercolumn',
hidden:true
},{
text : '物料编号',
width : 200.0,
dataIndex : 'prodCode',
xtype : '',
},
{
text : '品牌',
dataIndex : 'prodBrand',
width : 110.0,
xtype : '',
},
{
text : '名称',
dataIndex : 'prodName',
width : 150.0
},{
text : '型号',
dataIndex : 'prodOrispeccode',
width : 110.0
},{
text : '规格',
dataIndex : 'prodSpec',
width : 110.0
},{
text : '单位',
dataIndex : 'prodUnit',
width : 110.0
},{
text : '发起时间',
dataIndex : 'startDate',
width : 160.0
},{
text : '截止日期',
dataIndex : 'endDate',
width : 160.0
},{
text : '报价状态',
dataIndex : 'qutations',
width : 110.0,
renderer:function(val, meta, record,x,y,store, view){
if(!val||val==0||val.length==0){
return '否'
}else{
return '是'
}
}
}, {
dataIndex: '',
flex: 1
}],
dbSearchFields: [],
condition:'',
initComponent: function() {
var me = this;
if(me.columns){
var fields = me.columns.map(column => column.dataIndex);
me.store = Ext.create('Ext.data.Store',{
fields:fields,
autoLoad: true,
pageSize: 15,
proxy: {
timeout:8000,
type: 'ajax',
headers:{
'Access-Control-Allow-Origin': '*',
"Content-Type": 'application/json;charset=UTF-8'
},
url: me.dataUrl,
actionMethods: {
read: 'GET'
},
reader: {
type: 'json',
rootProperty: 'data.content',
totalProperty: 'data.totalElements',
}
},
listeners: {
beforeload: function (store, op) {
var date = Ext.ComponentQuery.query('[name=_date]')[0];
var from = date.value.from || '';
if(!Ext.isDate(from)){
from = new Date(from);
from = from.getTime()
}else{
from = date.value.from.getTime()
}
var to = date.value.to || '';
if(!Ext.isDate(to)){
to = new Date(to);
to = to.getTime()
}else{
to = date.value.to.getTime()
}
var search = Ext.ComponentQuery.query('[name=search]')[0].value;
var quoted = Ext.ComponentQuery.query('[name=quoted]')[0].value;
var overdue = Ext.ComponentQuery.query('[name=overdue]')[0].value;
Ext.apply(store.proxy.extraParams, {
keyword :search,//search==''?' ':search,
pageNumber: op._page,
pageSize: store.pageSize,
quoted:quoted,
fromDate:from,
endDate:to,
overdue:overdue
});
}
}
});
Ext.apply(me, {
dockedItems:[{
xtype: 'pagingtoolbar',
dock: 'bottom',
displayInfo: true,
store: me.store
}]
});
}
me.callParent(arguments);
},
listeners:{
boxready: function(grid, width, height, eOpts) {
var store = grid.getStore(),
gridBodyBox = grid.body.dom.getBoundingClientRect(),
gridBodyBoxHeight = gridBodyBox.height;
var pageSize = Math.floor(gridBodyBoxHeight / 33);
store.setPageSize(pageSize);
grid.ownerCt.el.dom.style.left = '8px';
grid.el.dom.style.padding = '0px'
},
itemClick: function(view,record,a,index,c) {
}
},
getGridSelected:function(type){
var isErrorSelect = false;
var checkField = this.statusCodeField;
var me = this,
items = me.selModel.getSelection(),
data = new Array() ;
Ext.each(items, function(item, index){
if(!Ext.isEmpty(item.data[me.idField])){
var o = new Object();
if(me.idField){
o['id'] = item.data[me.idField];
}
if(me.codeField){
o['code'] = item.data[me.codeField];
}
if(type&&type==item.data[checkField]){
isErrorSelect = true
}
data.push(o);
}
});
if(isErrorSelect){
return false;
}
return data;
},
/**
* 获得过滤条件
*/
getConditions: function() {
var me = this,
tbar = me.getDockedItems()[0],
items = Ext.Array.filter(tbar.items.items, function(item) {
return !!item.name;
}),
conditions = [];
for(var i = 0; i < items.length; i++) {
var item = items[i];
var field = item.name,
func = item.getCondition,
value = item.value,
condition;
if(value&&value!=''){
if(typeof func == 'function') {
condition = {
type: 'condition',
value: func(value)
}
}else {
var type = item.fieldType || me.getDefaultFieldType(item),
operation = item.operation || me.getDefaultFieldOperation(item),
conditionValue = me.getConditionValue(item, value);
if(!conditionValue) {
continue;
}
condition = {
type: type,
field: field,
operation: operation,
value: conditionValue
}
}
conditions.push(condition);
}
}
return conditions;
},
/**
* 只要arr1和arr2中存在相同项即返回真
*/
isContainsAny: function (arr1, arr2) {
for (var i = 0; i < arr2.length; i++) {
var a2 = arr2[i];
if (!!arr1.find(function (a1) {
return a1 == a2
})) {
return true;
}
}
return false;
},
getDefaultFieldType: function (field) {
var me = this,
xtypes = field.getXTypes().split('/'),
type;
if (me.isContainsAny(xtypes, ['numberfield'])) {
type = 'number';
} else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
type = 'date';
} else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
type = 'enum';
} else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
type = 'enum';
} else {
type = 'string';
}
return type;
},
getDefaultFieldOperation: function (field) {
var me = this,
xtypes = field.getXTypes().split('/'),
operation;
if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
operation = '=';
} else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
operation = 'between';
} else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
operation = 'in';
} else {
operation = 'like';
}
return operation;
},
/**
* 处理部分字段值
*/
getConditionValue: function (field, value) {
var me = this,
xtypes = field.getXTypes().split('/'),
conditionValue;
if (me.isContainsAny(xtypes, ['datefield'])) {
conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
} else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
var from = value.from,
to = value.to;
conditionValue = from + ',' + to;
} else if (me.isContainsAny(xtypes, ['condatefield'])) {
var from = value.from,
to = value.to;
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');
} else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
conditionValue = value;
} else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
conditionValue = '\'' + value + '\'';
} else if (me.isContainsAny(xtypes, ['multicombo'])) {
conditionValue = value.map ? value.map(function (v) {
return '\'' + v.value + '\'';
}).join(',') : '';
} else {
conditionValue = value;
}
return conditionValue;
}
})