Ext.define('make.view.sale.saleforecast.TurnMakeWin', {
extend: 'Ext.window.Window',
xtype: 'sale-saleforecast-turnmakewin',
cls: 'x-window-dbfind',
modal: true,
// width: 1300,
// minHeight: 500,
scrollable: true,
bodyPadding: 10,
constrain: true,
closable: true,
layout: 'fit',
title: '转工单',
_id:0,
initComponent: function () {
var me = this;
Ext.apply(me, {
baseUrl : '/api/sale/saleforecast/getTurnMakeData/',
items:[{
xtype: 'grid',
selModel: {
checkOnly: true,
type: 'checkboxmodel',
mode: "MULTI",
ignoreRightMouseSelection: false
},
columns: [{
text: 'ID',
dataIndex: 'st_sdid',
hidden: true,
},{
text: '本次数量',
dataIndex: 'st_thisqty',
width: 100,
xtype: 'widgetcolumn',
/*renderer : function(val, meta, record, x, y, store, view) {
return val;
}, */
widget: {
xtype: "numberfield",
bind: '{record.st_thisqty}',
decimalPrecision: 6,
minValue: 0
}
},{
text: '行号',
dataIndex: 'st_sddetno',
width: 80
}, {
text: '物料编号',
dataIndex: 'st_prodcode',
width: 150
}, {
text: '物料名称',
dataIndex: 'st_proddetail',
width: 150
},{
text: '型号',
dataIndex: 'st_prodorispec',
width: 150,
renderer: function (v, m, r) {
var str = '';
if(r.data['st_prodbrand']){
str += '厂家/品牌:'+ r.data['st_prodbrand'] + '
';
}
if(r.data['st_prodspec']){
str += '规格:' + r.data['st_prodspec'];
}
if(str) m.tdAttr = 'data-qtip="'+ str +'"';
return v;
}
},{
text: '备货数量',
dataIndex: 'st_sdqty',
xtype: 'numbercolumn',
renderer: function(v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
},
},{
text: '已核销数',
dataIndex: 'st_yqty',
xtype: 'numbercolumn',
renderer: function(v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
},
},{
text: '已下达数量',
dataIndex: 'st_tomakeqty',
xtype: 'numbercolumn',
renderer: function(v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
},
},{
text: '订单冲减工单数',
dataIndex: 'sd_maqty',
xtype: 'numbercolumn',
width:140.0,
renderer: function(v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
},
},{
text: '安全库存',
dataIndex: 'st_prodsafetystock',
xtype: 'numbercolumn',
renderer: function(v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
},
},{
text: '总需求数',
dataIndex: 'st_needqty',
xtype: 'numbercolumn',
renderer: function (v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
}
}, {
text: '总供应数',
dataIndex: 'st_supplyqty',
xtype: 'numbercolumn',
renderer: function (v, m, r) {
return saas.util.BaseUtil.numberFormat(v, 6, true);
}
}, {
text: '供需平衡',
dataIndex: 'st_balance',
xtype: 'numbercolumn',
renderer: function (v, m, r) {
v = (r.get('st_supplyqty')||0) - (r.get('st_needqty')||0),
v = saas.util.BaseUtil.numberFormat(v, 6, true);
return v<0?''+v+'':v;
}
}],
store: {
autoLoad: true,
fields: [
{ name: 'st_thisqty', type: 'float' },
{ name: 'st_sddetno', type: 'int' },
{ name: 'st_sdid', type: 'int' },
{ name: 'st_prodcode', type: 'string' },
{ name: 'st_proddetail', type: 'string' },
{ name: 'st_prodspec', type: 'string' },
{ name: 'st_prodorispec', type: 'string' },
{ name: 'st_prodbrand', type: 'string' },
{ name: 'st_produnit', type: 'string' },
{ name: 'st_sdqty', type: 'float' },
{ name: 'st_tomakeqty', type: 'float' },
{ name: 'st_needqty', type: 'float' },
{ name: 'st_supplyqty', type: 'float' },
{ name: 'st_prodid', type: 'int' },
{ name: 'st_said', type: 'int' },
{ name: 'st_sfid', type: 'int' },
{ name: 'st_yqty', type: 'float' },
{ name: 'sd_maqty', type: 'float' },
],
proxy: {
type: 'ajax',
url: '/api/sale/saleforecast/getTurnMakeData',
timeout: 8000,
actionMethods: {
read: 'GET'
},
reader: {
type: 'json',
rootProperty: 'data',
totalProperty: '',
},
listeners: {
exception: function (proxy, response, operation, eOpts) {
if (operation.success) {
if (response.timedout) {
saas.util.BaseUtil.showErrorToast('请求超时');
}
} else {
if (response.timedout) {
saas.util.BaseUtil.showErrorToast('请求超时');
} else {
console.error('exception: ', response);
var message = response.responseJson ? (response.responseJson.message == null ? '没有数据' : response.responseJson.message) : '请求超时';
saas.util.BaseUtil.showErrorToast('查询失败:' + message);
}
}
}
}
},
listeners: {
beforeload: function (store, op) {
store.getProxy().url = me.baseUrl + me._id;
},
load: function (store, records, successful, operation, eOpts) {
}
}
},
buttonAlign: 'center',
buttons: [{
text: '确认',
handler: me.handleSave
}, {
text: '关闭',
handler: me.handleClose
}]
}],
})
me.callParent();
},
handleClose: function(btn){
btn.ownerCt.ownerCt.ownerCt.close();
},
handleSave:function(btn){
var me = this,
win = me.ownerCt.ownerCt.ownerCt;
var data = win.getGridSelected();
if(data && data.length>0){
win.setLoading(true);
var params = JSON.stringify(data);
saas.util.BaseUtil.request({
url: '/api/sale/saleforecast/turnMake',
params: params,
method: 'POST',
async:false
})
.then(function(res) {
if (res.success) {
win.setLoading(false);
win.handleClose(btn);
//刷新销售订单页面
saas.util.FormUtil.loadData(win._parent);
saas.util.BaseUtil.showSuccessToast('生成工单成功,单号:'+res.data);
}
})
.catch(function(res) {
win.setLoading(false);
saas.util.BaseUtil.showErrorToast(('操作失败: ') + res.message);
});
}else{
saas.util.BaseUtil.showErrorToast('请勾选至少一条有效明细。');
}
},
/**
*获取grid 数据
*/
getGridSelected:function(){
var me = this,
grid = me.down('grid');
items = grid.selModel.getSelection(),
data = new Array() ;
var ids=[];
Ext.each(items, function(item, index){
var o = new Object();
if(item.data['st_thisqty']>0){
o['st_thisqty'] = item.data['st_thisqty'];
o['st_sdid'] = item.data['st_sdid'];
o['st_sfid'] = item.data['st_sfid'];
o['st_prodid'] = item.data['st_prodid'];
o['st_prodcode'] = item.data['st_prodcode'];
o['st_planenddate'] = item.data['st_planenddate'];
data.push(o);
}
});
return data;
}
})