You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/TruckMng/Viewsjs/WlTruck/WlTruckEdit.js

338 lines
11 KiB
JavaScript

3 years ago
Ext.require(['*']);
Ext.namespace('DsTruck');
DsTruck.WlTruckEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.WlTruckEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.WlTruckEdit, Ext.Panel, {
parentWin: null,
opStatus: 'add',
storeList: null,
editRecord: null,
initUIComponents: function () {
//枚举参照
this.storeTruckType = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeTruckType.load({ params: { enumTypeId: 99001} });
this.comboxTruckType = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '车辆类型',
store: this.storeTruckType,
name: "TruckType"
});
//参照
this.storeDrvCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'WlDriver',
proxy: { url: '/TruckMng/WlTruck/GetDrvCodeList' }
});
this.storeDrvCode.load();
this.comboxDrvCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '驾驶员姓名',
store: this.storeDrvCode,
name: "DrvCode",
valueField: 'DrvCode',
displayField: 'DrvName'
});
this.formEdit = Ext.widget('form', {
title: '车辆信息维护',
region: 'center',
frame: true,
bodyPadding: 5,
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 90,
msgTarget: 'qtip'
},
items: [
{
xtype: 'fieldset',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
xtype: "hidden",
fieldLabel: "ModelUIStatus",
name: 'ModelUIStatus',
flex: 0,
margins: '0'
}, {
name: 'OrgCode',
fieldLabel: '组织编码',
allowBlank: false
}, {
name: 'TruckNo',
fieldLabel: '车牌号',
allowBlank: false
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '车辆型号',
name: 'TruckSpec',
allowBlank: false
}, this.comboxTruckType
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '车辆颜色',
name: 'TrunkColor',
allowBlank: false
}, {
fieldLabel: '车辆品牌',
name: 'TrunkBrand',
allowBlank: false
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
xtype: 'numberfield',
fieldLabel: '载重量',
name: 'LoadCount',
decimalPrecision: 4
}, {
fieldLabel: '车架号',
name: 'CjNo'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '发动机号',
name: 'FdjNo'
}, {
fieldLabel: '购置日期',
name: 'GzDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '转让日期',
name: 'ZrDate'
}, this.comboxDrvCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '所属部门',
name: 'DepCode',
allowBlank: false
}, {
fieldLabel: '所属车队',
name: 'TruncClass',
allowBlank: false
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '备注',
name: 'Remark'
}
]
}
]
}],
buttons: [{
text: 'Reset',
handler: function () {
this.up('form').getForm().reset();
}
}, {
text: 'Complete Purchase',
width: 150,
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
Ext.MessageBox.alert('Submitted Values', form.getValues(true));
}
}
}]
});
//按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
text: "保存",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
text: "保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
'-',
{
text: "保存并新建",
handler: function (button, event) {
this.Save('2');
},
scope: this
}
]
});
Ext.apply(this, {
items: [this.panelBtn, this.formEdit]
});
parentWin = window.parent.opener;
this.InitData();
},
InitData: function () {
this.opStatus = 'add';
var condition = '';
if (parentWin) {
var ret = parentWin.OprationSwap();
this.opStatus = ret[0];
this.StoreList = ret[1];
this.editRecord = ret[2];
}
if (this.opStatus == 'edit')
condition = " OrgCode ='" + this.editRecord.get('OrgCode') + "' and TruckNo='" + this.editRecord.get('TruckNo') + "'";
this.LoadData(this.opStatus, condition);
}, //InitData
LoadData: function (opstatus, condition) {
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/WlTruck/GetData',
params: {
handle: opstatus,
condition: condition
},
callback: function (options, success, response) {
if (success) {
var result = Ext.JSON.decode(response.responseText);
if (!result.Success) {
Ext.Msg.show({
title: '提示',
msg: result.Message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
return;
}
var data = result.data;
this.formEdit.getForm().reset();
this.formEdit.getForm().setValues(data);
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
},
Save: function (type) {
if (!this.formEdit.getForm().isValid()) {
return;
}
var data = this.formEdit.getForm().getValues();
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/WlTruck/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data)
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
if (this.opStatus == 'add') {
var p = Ext.create('WlTruck', data); // Ext.create('WlTruck', data, NewGuid()); //或者new WlTruck(data, NewGuid());
this.storeList.add(p);
this.editRecord = p;
}
else if (this.opStatus == 'edit') {
///todo 更新表格的记录
var editp = Ext.create('WlTruck', data);
this.editRecord.fields.each(function (field) {
if (field.persist) {
name = field.name;
if (name != 'id')
this.editRecord.set(name, editp.get(name));
}
}, this);
this.editRecord.commit();
}
if (type == '0') {
this.opStatus = 'edit';
} else if (type == '1') {
window.close();
} else {
this.LoadData('add', '');
}
} else {
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({ title: '请重试',
msg: '服务器响应出错',
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
}
});