/**
* 自动获取编号的trigger
*/
Ext.define('erp.view.core.trigger.AutoCodeTrigger', {
extend: 'Ext.form.field.Trigger',
alias: 'widget.autocodetrigger',
triggerCls: 'x-form-autocode-trigger',
afterrender: function() {
this.addEvent({
'aftertrigger': true
});
},
onTriggerClick: function() {
if("PreProduct" == caller) {
var k1 = Ext.getCmp('pre_kind'),
k2 = Ext.getCmp('pre_kind2'),
k3 = Ext.getCmp('pre_kind3');
if(k1 && !Ext.isEmpty(k1.getValue()) && k2 && !Ext.isEmpty(k2.getValue())
&& k3 && !Ext.isEmpty(k3.getValue())) {
var k4 = Ext.getCmp('pre_xikind');
this.askFor(k1.getValue(), k2.getValue(), k3.getValue(),
(k4 && !Ext.isEmpty(k4.getValue())) ? k4.getValue() : null);
return;
}
}
this.showWin();
},
showWin : function() {
var win = this.win;
if (!win) {
var type = this.type || this.getType();
this.win = win = new Ext.window.Window({
id: 'win',
height: "100%",
width: "80%",
maximizable: true,
closeAction: 'hide',
buttonAlign: 'center',
layout: 'anchor',
title: '获取编号',
items: [{
tag: 'iframe',
anchor: '100% 100%',
layout: 'fit',
html: ''
}]
});
}
win.show();
},
askFor : function(k1, k2, k3, k4) {
var me = this, s = '大类:' + k1 + ';中类:' + k2 + ';小类:' + k3 + (k4 ? (';细类' + k4) : '');
var box = Ext.create('Ext.window.MessageBox', {
buttonAlign : 'center',
buttons: [{
text: '生成编号',
handler: function(b) {
me.autoCode(k1, k2, k3, k4);
b.ownerCt.ownerCt.close();
}
},{
text: '重新选择',
handler: function(b) {
me.showWin();
b.ownerCt.ownerCt.close();
}
},{
text: '关闭',
handler : function(b) {
b.ownerCt.ownerCt.close();
}
}]
});
box.show({
title : "提示",
msg : "您已选择了【" + s + '】
现在立刻生成编号?',
icon : Ext.MessageBox.QUESTION
});
},
autoCode : function(k1, k2, k3, k4) {
var me = this;
Ext.Ajax.request({
url : basePath + me.getUrl(),
params: {
k1: k1,
k2: k2,
k3: k3,
k4: k4
},
method : 'post',
callback : function(opt, s, res){
var r = new Ext.decode(res.responseText);
if(r.exceptionInfo){
showError(r.exceptionInfo);
} else if(r.success && r.number){
me.setValue(r.number);
me.autoSave(r.number);
} else {
alert('取号失败!');
}
}
});
},
autoSave: function(num) {
var id = this.up('form').down('#pre_id');
if(id && id.value > 0) {
Ext.Ajax.request({
url : basePath + 'common/updateByCondition.action',
params: {
table: 'PreProduct',
update: 'pre_code=\'' + num + '\'',
condition: 'pre_id=' + id.value
},
method : 'post',
callback : function(opt, s, res){
var r = new Ext.decode(res.responseText);
if(r.exceptionInfo){
showError('编号保存失败.
' + r.exceptionInfo);
}
}
});
}
},
getType: function() {
var type = 'Product';
switch (caller) {
case 'PreProduct':
type = 'Product';
break;
case 'Vendor':
type = 'Vendor';
break;
case 'PreVendor':
type = 'Vendor';
break;
case 'Customer':
type = 'Customer';
break;
case 'PreCustomer':
type = 'Customer';
break;
}
return type;
},
getUrl: function(){
var type = this.getType();
var url = 'scm/product/getProductKindNum.action';
switch (type) {
case 'Vendor':
url = 'scm/purchase/getVendorKindNum.action';break;
case 'Customer':
url = 'scm/sale/getCustomerKindNum.action';break;
}
return url;
}
});