Ext.define('erp.view.scm.purchase.B2CPurchase',{
extend: 'Ext.Viewport',
layout: 'anchor',
hideBorders: true,
initComponent : function(){
var me = this;
Ext.apply(me, {
items: [{
xtype: 'form',
anchor: '100% 10%',
defaultType: 'textfield',
layout:'column',
bodyStyle: 'background: #f1f1f1;border:none;',
items:[{
xtype:'tbtext',
text:'排序策略',
style: 'margin-left:10px;margin-top:4px;font-size:15px;border:1;'
},{
xtype: 'button',
text : '交货周期',
id:'deliverySort',
width:85
},{
xtype: 'button',
text : '价格',
iconCls: 'x-button-icon-up',
id:'priceSort',
style:'background:#e3e3e3;',
width:60
},{
columnWidth:.35,
fieldLabel:'请输入购买数量',
labelWidth:115,
xtype:'numberfield',
id:'buyQty',
value :qty,
style: 'margin-left:40px'
},{
columnWidth:.15,
xtype: 'button',
text:'自动分配数量',
iconCls: 'x-button-icon-check',
cls: 'x-btn-gray',
id:'autoBtn'
}]
},{
xtype: 'grid',
anchor: '100% 50%',
id:'reserveGrid',
sortableColumns :false,
store: Ext.create('Ext.data.Store',{
fields: ['gb_b2bbatchcode','gb_price','gb_deliverytime','gb_madedate','gb_onsaleqty','gb_minbuyqty','gb_minpackqty','buyQty','gb_minprice'],
data: [],
autoLoad:true
}),
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
columns: [{
xtype : 'rownumberer',
width : 35,
sortable : false,
text: '#',
align :'center'
},
{
text: '批次',
dataIndex: 'gb_b2bbatchcode',
flex: 1.8
},{
text: '单价',
dataIndex: 'gb_price',
flex: 1.5,
renderer:function(val, meta, record){
meta.style='white-space: normal;height: auto !important;';
var da = new Ext.decode(val);
var html = '';
Ext.Object.each(da,function(key, value){
html +='
'+value.start+'~'+value.end+'个:¥'+value.price+'
';
});
return html;
}
},{
text: '交期',
dataIndex: 'gb_deliverytime',
flex: 0.8 ,
renderer:function(val, meta, record){
return val+'天';
}
},{
text: '批次日期',
dataIndex: 'gb_madedate',
flex: 1.0,
xtype: 'datecolumn',
renderer:function(val, meta, record){
return Ext.Date.format(new Date(val),'Y-m-d');
}
},{
text: '库存',
dataIndex: 'gb_onsaleqty',
flex: 0.8
},{
text: '最小起订量',
dataIndex: 'gb_minbuyqty',
flex: 0.8,
listeners:{
afterrender: function(column) {}
}
},{
text: '最小包装数',
dataIndex: 'gb_minpackqty',
flex: 1,
listeners:{
afterrender: function(column) {}
}
},{
text: '购买数量',
dataIndex: 'buyQty',
xtype: 'numbercolumn',
flex: 1,
listeners:{
afterrender: function(column) {}
},
renderer:function(val, meta, record){
var minbuy = record.data['gb_minbuyqty'];
var minpack = record.data['gb_minpackqty'];
if(val!="" && val!=null && val <= 0){
showError('购买数量必须大于0!');
val = "";
}
if((val!="" && val!=null)&&((val>minpack && (val % minpack)) || val < minbuy)){
showError('购买数量必须大于最小起订量并且是最小包装数的整数倍!');
val = "";
}
if(val > record.data['gb_onsaleqty']){
showError('购买数量不允许超过库存!');
val = "";
}
if(record.data['buyQty'] != val) {
record.set('buyQty', val);
}
//统计购买数量
var grid = Ext.getCmp("reserveGrid");
var sum1 = 0;
var gdata = [];
grid.store.each(function(record){
sum1 += Number(record.data.buyQty);
if(Number(record.data.buyQty)>0){
gdata.push(Ext.clone(record.data));
}
});
Ext.getCmp("getGrid").getStore().loadData(gdata);
Ext.getCmp("totalbuyqty").setText('购买数量总计:' + sum1);
return val;
},
editor:{
xtype: 'numberfield',
msgTarget: 'under'
}
},{
xtype : 'numbercolumn',
dataIndex: 'gb_minprice',
sortable : true,
align :'center',
hidden:true
}],
listeners: {//滚动条有时候没反应,添加此监听器
scrollershow: function(scroller) {
if (scroller && scroller.scrollEl) {
scroller.clearManagedListeners();
scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
}
}
}
},{
title:'已选择数据',
xtype: 'grid',
anchor: '100% 40%',
id:'getGrid',
collapsible:true,
sortableColumns :false,
store: Ext.create('Ext.data.Store',{
fields: ['gb_b2bbatchcode','gb_price','gb_deliverytime','gb_madedate','gb_onsaleqty','gb_minbuyqty','gb_minpackqty','buyQty'],
data: [],
autoLoad:true
}),
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
columns: [{
xtype : 'rownumberer',
width : 35,
sortable : false,
text: '#',
align :'center'
},
{
text: '批次',
dataIndex: 'gb_b2bbatchcode',
flex: 1.8
},{
text: '单价',
dataIndex: 'gb_price',
flex: 1.5,
renderer:function(val, meta, record){
meta.style='white-space: normal;height: auto !important;';
var da = new Ext.decode(val);
var html = '';
Ext.Object.each(da,function(key, value){
html +=''+value.start+'~'+value.end+'个:¥'+value.price+'
';
});
return html;
}
},{
text: '交期',
dataIndex: 'gb_deliverytime',
flex: 0.8 ,
renderer:function(val, meta, record){
return val+'天';
}
},{
text: '批次日期',
dataIndex: 'gb_madedate',
flex: 1.0,
xtype: 'datecolumn',
renderer:function(val, meta, record){
return Ext.Date.format(new Date(val),'Y-m-d');
}
},{
text: '库存',
dataIndex: 'gb_onsaleqty',
flex: 0.8
},{
text: '最小起订量',
dataIndex: 'gb_minbuyqty',
flex: 0.8
},{
text: '最小包装数',
dataIndex: 'gb_minpackqty',
flex: 1
},{
text: '购买数量',
dataIndex: 'buyQty',
xtype: 'numbercolumn',
flex: 1
}],
bbar : [{
id: 'totalbuyqty',
xtype: 'tbtext',
text: '购买数量总计:'
},'-', '->',{
text: '确 认',
iconCls: 'x-button-icon-confirm',
cls: 'x-btn-gray',
xtype: 'button',
id:'confirmBuyBtn'
},{
text : '关 闭',
iconCls: 'x-button-icon-close',
cls: 'x-btn-gray',
xtype: 'button',
handler : function(){
parent.Ext.getCmp('dlwin').close();
}
},'->'],
listeners: {//滚动条有时候没反应,添加此监听器
scrollershow: function(scroller) {
if (scroller && scroller.scrollEl) {
scroller.clearManagedListeners();
scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
}
}
}
}]
});
me.callParent(arguments);
}
});