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/MsWlPcHead/MsWlPcHeadEdit.js

490 lines
18 KiB
JavaScript

3 years ago
Ext.namespace('DsTruck');
DsTruck.MsWlPcHeadEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsWlPcHeadEdit.superclass.constructor.call(this);
};
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1, //month
"d+": this.getDate(), //day
"h+": this.getHours(), //hour
"m+": this.getMinutes(), //minute
"s+": this.getSeconds(), //second
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
(this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length == 1 ? o[k] :
("00" + o[k]).substr(("" + o[k]).length));
return format;
}
var xhr = new XMLHttpRequest();
var currdate = new Date();
if (!xhr) {
//...其他生成xmlhttprequest方法
}
xhr.open("HEAD", location.href, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var datestr = xhr.getResponseHeader("Date");
currdate = new Date(datestr);
// alert(currdate.format('yyyy-MM-dd'));
}
}
xhr.send(null);
Ext.extend(DsTruck.MsWlPcHeadEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
//枚举参照相关
//表参照相关
this.storeTruckNo = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsWlTruckRef',
proxy: { url: '/TruckMng/MsWlPcHead/GetTruckNoList' }
});
this.storeTruckNo.load({ params: { condition: ""} });
this.comboxTruckNo = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '车牌号',
store: this.storeTruckNo,
name: 'TruckNo',
valueField: 'TruckNo',
disabled: true,
displayField: 'TruckNo'
});
//////////////////
this.storeDrvName = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsWlDriverRef',
proxy: { url: '/TruckMng/MsWlPcHead/GetDrvNameList' }
});
this.storeDrvName.load({ params: { condition: ""} });
this.comboxDrvName = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '司机姓名',
store: this.storeDrvName,
name: 'DrvCode',
valueField: 'DrvCode',
disabled: true,
displayField: 'CodeAndName'
});
this.storeContainerType = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.CtnRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetCtnRefList' }
});
this.storeContainerType.load({ params: { condition: ""} });
this.comboxContainerType = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '箱型',
store: this.storeContainerType,
name: 'ContainerType',
valueField: 'CtnCode',
disabled: true,
displayField: 'CodeAndName'
});
this.storeYardCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.CustomRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' }
});
this.storeYardCode.load({ params: { condition: "ISYARD='1'"} });
this.comboxYardCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '拖箱场站',
store: this.storeYardCode,
name: 'YardCode',
valueField: 'CustCode',
disabled: true,
displayField: 'CodeAndName'
});
this.comboxRtnYardCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '返箱场站',
store: this.storeYardCode,
name: 'RtnYardCode',
valueField: 'CustCode',
disabled: true,
displayField: 'CodeAndName'
});
this.storeYouLiaoType = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeYouLiaoType.load({ params: { enumTypeId: 99049} });
this.comboxYouLiaoType = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '油料类型',
store: this.storeYouLiaoType,
name: 'YouLiaoType',
disabled: true,
flex: 1,
valueField: 'EnumValueName',
displayField: 'EnumValueName'
});
this.storeOilUser = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeOilUser.load({ params: { condition: ""} });
this.comboxOilUser = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '加油录入人',
store: this.storeOilUser,
flex: 2,
name: 'OilUser',
valueField: 'UserCode',
displayField: 'CodeAndName'
});
//编辑form
this.formEdit = Ext.widget('form', {
region: 'center',
frame: true,
bodyPadding: 5,
fieldDefaults: {
margins: '2 2 2 2',
labelAlign: 'right',
flex: 1,
labelWidth: 90,
msgTarget: 'qtip'
},
items: [
{//fieldset 1
xtype: 'fieldset',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '录入日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'LrDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '记账日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'JzDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '用户编码',
name: 'UserCode', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '用户姓名',
name: 'UserName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '组织编码',
name: 'OrgCode', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '组织名称',
name: 'OrgName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '船名航次',
name: 'VoyVeg', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '开船日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'EtDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '截港日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'EndPortDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '拖箱场站名称',
name: 'YardName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '返箱场站名称',
name: 'RtnYardName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
disabled: true,
name: 'BillNo'
}, this.comboxTruckNo, this.comboxDrvName
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '司机手机',
disabled: true,
name: 'Mobile'
}, {
fieldLabel: '派车日期',
format: 'Y-m-d',
xtype: 'datefield',
disabled: true,
name: 'ExpDate'
}, this.comboxContainerType
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '箱量',
xtype: 'numberfield',
allowBlank: false,
disabled: true,
name: 'ContainerQty'
}, {
fieldLabel: '提单号',
disabled: true,
name: 'MblNo'
}, this.comboxYardCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxRtnYardCode, {
fieldLabel: '本次加油量',
xtype: 'numberfield',
allowBlank: false,
name: 'FuelQty',
id: 'FuelQty',
listeners: {
change: function (field, newValue, oldValue) {
var price= Ext.getCmp('UnitPrice').getValue();
var cnt = Ext.getCmp('FuelQty').getValue();
Ext.getCmp('Amount').setValue(price*cnt);
}
}
}, {
fieldLabel: '加油录入日期',
format: 'Y-m-d',
xtype: 'datefield',
//disabled: true,
name: 'OilLrDate'
/*{
fieldLabel: '保险开始日期',
format: 'Y-m-d',
xtype: 'datefield',
allowBlank: false,
name: 'InsureBgnDate'
},*/
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxYouLiaoType, {
fieldLabel: '单价',
xtype: 'numberfield',
allowBlank: false,
name: 'UnitPrice',
id: 'UnitPrice',
listeners: {
change : function(field,newValue,oldValue) {
var price = Ext.getCmp('UnitPrice').getValue();
var cnt = Ext.getCmp('FuelQty').getValue();
Ext.getCmp('Amount').setValue(price * cnt);
}
}
}, {
fieldLabel: '金额',
xtype: 'numberfield',
allowBlank: false,
id: 'Amount',
name: 'Amount'
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxOilUser
]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
text: "保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
}
]
}); //end 按钮Toolbar
Ext.apply(this, {
items: [this.panelBtn, this.formEdit]
});
parentWin = window.parent.opener;
this.InitData();
}, //end initUIComponents
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 = " BillNo='" + this.editRecord.get('BillNo') + "'";
this.LoadData(this.opStatus, condition);
}, //end InitData
LoadData: function (opstatus, condition) {
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/MsWlPcHead/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();
if (data.OilLrDate == "") { data.OilLrDate = currdate.format('yyyy-MM-dd') };
if (data.OilUser == "") { data.OilUser = str };
this.formEdit.getForm().setValues(data);
// var xcondition = " BSNO='" + this.editRecord.get('BillNo') + "'";
// _this.Loading = true;
// _this.storeDocList.load({
// params: { condition: xcondition },
// waitMsg: "正在查询数据...",
// scope: this,
// callback: function () {
// _this.Loading = false;
// }
// });
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!this.formEdit.getForm().isValid()) {
return;
}
basicForm.findField('BillNo').setDisabled(false);
var data = this.formEdit.getForm().getValues();
basicForm.findField('BillNo').setDisabled(true);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsWlPcHead/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) {
var returnData = jsonresult.Data;
this.formEdit.getForm().setValues(returnData);
if (this.opStatus == 'add') {
var arrNewRecords = this.StoreList.add(returnData);
this.editRecord = arrNewRecords[0];
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('MsWlPcHead', returnData);
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
});
}
}
});
} //end save
});