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/MsWlDj/MsWlDjEdit.js

802 lines
27 KiB
JavaScript

Ext.namespace('DsTruck');
DsTruck.MsWlDjEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsWlDjEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.MsWlDjEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
PNUM: 0,
PKGS: 0,
initUIComponents: function () {
//枚举参照相关
this.storeBillStatus = Ext.create('DsExt.ux.RefEnumStore', {});
this.storeBillStatus.load({ params: { enumTypeId: 99029} });
this.comboxBillStatus = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '托单状态',
store: this.storeBillStatus,
name: 'BillStatus',
readOnly: true
});
//表参照相关
this.storeSalesCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeSalesCode.load();
this.comboxSalesCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '揽货人',
store: this.storeSalesCode,
name: 'SalesCode',
valueField: 'UserCode',
displayField: 'CodeAndName'
});
this.storeCustCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.CustomRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' }
});
this.storeCustCode.load({ params: { condition: "ISCONTROLLER='1'"} });
this.comboxCustCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '委托单位代码',
store: this.storeCustCode,
name: 'CustCode',
valueField: 'CustCode',
displayField: 'CodeAndName',
listeners: {
scope: this,
'select': function (combo, records, eOpts) {
if (records.length > 0) {
var recs = DsStoreQueryBy(this.storeCustCode, 'CustCode', records[0].data.CustCode);
var custname = this.formEdit.getForm().findField('CustName');
if (recs.getCount() > 0) {
var data = recs.getAt(0).data;
custname.setValue(data.CustName);
} else {
custname.setValue('');
}
}
}
}
});
//编辑form
this.formEdit = Ext.widget('form', {
region: 'north',
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: 'YwType', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '时间戳',
name: 'TimeMark', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '惟一编号',
name: 'GId', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '揽货人姓名',
name: 'SalesName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '委托单位',
name: 'CustName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
readOnly: true,
name: 'BillNo'
}, this.comboxSalesCode, this.comboxCustCode, {
fieldLabel: '托运时间',
format: 'Y-m-d',
xtype: 'datefield',
name: 'CustDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '装货地点',
name: 'SedArea'
}, {
fieldLabel: '要求起运日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'NeedLoadDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '装货详细地址',
name: 'SedNation'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '卸货地点',
name: 'DstArea'
}, {
fieldLabel: '要求到达日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'NeedArriveDate'
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '卸货详细地址',
name: 'DetNation'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '品名',
name: 'ClsName'
}, {
fieldLabel: '件数',
xtype: 'numberfield',
allowBlank: false,
name: 'PNum',
hideTrigger: true,
keyNavEnabled: false,
mouseWheelEnabled: false,
listeners: {
focus: function (field, eOpts) {
this.PNUM = field.value;
},
blur: function (field, eOpts) {
var newValue = field.value;
this.PNumChange(field, newValue, this.PNUM);
},
scope: this
}
}, {
fieldLabel: '件重',
xtype: 'numberfield',
allowBlank: false,
name: 'PKgs',
hideTrigger: true,
keyNavEnabled: false,
mouseWheelEnabled: false,
listeners: {
focus: function (field, eOpts) {
this.PKGS = field.value;
},
blur: function (field, eOpts) {
var newValue = field.value;
this.PKgsChange(field, newValue, this.PKGS);
},
scope: this
}
}, {
fieldLabel: '总重量',
xtype: 'numberfield',
allowBlank: false,
name: 'Weight'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '长',
xtype: 'numberfield',
allowBlank: false,
name: 'Length'
}, {
fieldLabel: '宽',
xtype: 'numberfield',
allowBlank: false,
name: 'Wide'
}, {
fieldLabel: '高',
xtype: 'numberfield',
allowBlank: false,
name: 'Height'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '保险金额',
xtype: 'numberfield',
allowBlank: false,
name: 'InsureTotal'
}, this.comboxBillStatus
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '备注',
name: 'Remark'
}
]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
id: 'btnESave',
text: "保存",
iconCls: "btnsave",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
id: 'btnESaveAndClose',
text: "保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
{
id: 'btnESaveAndNew',
text: "保存并新建",
handler: function (button, event) {
this.Save('2');
},
scope: this
},
'-',
{
text: "关闭",
handler: function (button, event) {
window.close();
},
scope: this
},
{
text: "新建",
handler: function (button, event) {
this.LoadData('add', '');
var basicForm = this.formEdit.getForm();
basicForm.findField('BillNo').setDisabled(false);
},
scope: this
},
'-',
{
id: 'btnEAccount',
text: "记账",
handler: function (button, event) {
this.onAccountClick(button, event);
},
scope: this
},
'-',
{
text: "打印",
iconCls: "btnprint",
handler: function (button, event) {
this.Print();
},
scope: this
}
]
}); //end 按钮Toolbar
//明细表-数据集
this.storePoundBodyList = Ext.create('Ext.data.Store', {
model: 'MsWlDjPoundView',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/MsWlDj/GetDetailDataList',
reader: {
id: 'BillNo,SerialNo',
root: 'data',
totalProperty: 'totalCount'
}
}
});
this.PoundgridList = new Ext.grid.GridPanel({
store: this.storePoundBodyList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
selType: 'cellmodel',
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'SerialNo',
header: '序号',
width: 30
}, {
sortable: true,
dataIndex: 'BillNo',
header: '派车单号',
width: 150
}, {
sortable: true,
dataIndex: 'TruckNo_Ref',
header: '车号',
width: 150
}, {
sortable: true,
dataIndex: 'DrvName_Ref',
header: '司机',
width: 150
}
, {
sortable: true,
dataIndex: 'GId',
header: '惟一编号',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'DepartureDate',
header: '起运时间',
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
width: 80
}, {
sortable: true,
dataIndex: 'LoadPlace',
header: '起点',
width: 60
}, {
sortable: true,
dataIndex: 'UnLoadPlace',
header: '止点',
width: 60
}, {
sortable: true,
dataIndex: 'PlanOverLoadMil',
header: '计划重驶里程',
width: 76
}, {
sortable: true,
dataIndex: 'PlanNoLoadMil',
header: '计划空驶里程',
width: 76
}, {
sortable: true,
dataIndex: 'PlanLoadCount',
header: '计划运行次数',
width: 76
}, {
sortable: true,
dataIndex: 'OverLoadMil',
header: '实际重驶里程',
width: 76
}, {
sortable: true,
dataIndex: 'NoLoadMil',
header: '实际空驶里程',
width: 76
}, {
sortable: true,
dataIndex: 'LoadCount',
header: '实际运行次数',
width: 76
}, {
sortable: true,
dataIndex: 'PNum',
header: '装运件数',
width: 76
}, {
sortable: true,
dataIndex: 'PKgs',
header: '件重',
width: 76
}, {
sortable: true,
dataIndex: 'Weight',
header: '实际运输总重量',
width: 76
}, {
sortable: true,
dataIndex: 'RatedFuel',
header: '额定油耗',
width: 76
}, {
sortable: true,
dataIndex: 'TonMil',
header: '吨公里',
width: 76
}, {
sortable: true,
dataIndex: 'WorkTime',
header: '工作时间',
hidden: true,
width: 160
}
]
});
this.panelBodypound = new Ext.Panel({
title: '派车明细',
layout: "border",
region: 'center',
margin: '5 10',
height: 240,
items: [this.PoundgridList]
});
Ext.apply(this, {
items: [this.panelBtn, this.formEdit, this.panelBodypound]
});
parentWin = window.parent.opener;
this.InitData();
}, //end initUIComponents
InitData: function () {
this.opStatus = 'add';
var condition = '';
var detailcond = '';
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') + "'";
detailcond = " DjBillNo='" + this.editRecord.get('BillNo') + "'";
}
this.LoadData(this.opStatus, condition, detailcond);
}, //end InitData
LoadData: function (opstatus, condition, detailcond) {
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/MsWlDj/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);
if (data.WcDate == null || data.WcDate == '') {
this.setSaveBtnStatus(true);
} else {
this.setSaveBtnStatus(false);
}
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
if (this.opStatus == 'edit') {
this.storePoundBodyList.load({ params: { condition: detailcond} });
}
}, // end LoadDate
Save: function (type) {
if (!this.formEdit.getForm().isValid()) {
return;
}
var data = this.formEdit.getForm().getValues();
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsWlDj/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('MsWlDjHead', 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
,
PNumChange: function (field, newValue, oldValue) {
if (this.DataLoading == true) return;
if (newValue == oldValue) return;
var PNum = newValue;
var basicForm = this.formEdit.getForm();
var PKgs = basicForm.findField('PKgs').value;
var Weight = 0;
if (PNum == null || PNum == "" || PKgs == null || PKgs == 0) {
Weight = 0;
return;
} else {
Weight = (PKgs * PNum).toFixed(3);
}
basicForm.findField('Weight').setValue(Weight);
},
PKgsChange: function (field, newValue, oldValue) {
if (this.DataLoading == true) return;
if (newValue == oldValue) return;
var PKgs = newValue;
var basicForm = this.formEdit.getForm();
var PNum = basicForm.findField('PNum').value;
var Weight = 0;
if (PNum == null || PNum == "" || PKgs == null || PKgs == 0) {
Weight = 0;
return;
} else {
Weight = (PKgs * PNum).toFixed(3);
}
basicForm.findField('Weight').setValue(Weight);
},
onAccountClick: function (button, event) {
Ext.MessageBox.confirm('提示', '记账后数据无法修改,确认记账吗?', function (btn) {
if (btn == 'yes') {
this.Account();
}
}, this);
},
Account: function () {
var basicForm = this.formEdit.getForm();
basicForm.findField('BillNo').setDisabled(false);
var headdata = basicForm.getValues();
basicForm.findField('BillNo').setDisabled(true);
Ext.MessageBox.wait("正在记账,请稍侯.");
Ext.Ajax.request({
waitMsg: '正在记账...',
scope: this,
url: '/CommMng/PubSys/Account',
params: {
billno: headdata.BillNo,
ywtype: '0117'//headdata.YwType
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) //成功
{
var returnData = jsonresult.Data;
this.formEdit.getForm().setValues(returnData);
var editp = Ext.create('MsWlDjHead', 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();
this.setSaveBtnStatus(false);
Ext.MessageBox.alert("提示", jsonresult.Message);
} else //记账失败失败
{
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({ title: '请重试', msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
},
failure: function (response, options) {
Ext.Msg.show({ title: '警告', msg: '服务器响应出错,请重试', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
}); //end Ext.Ajax.request
},
setSaveBtnStatus: function (enable) {
var btnESave = Ext.getCmp('btnESave');
var btnESaveAndClose = Ext.getCmp('btnESaveAndClose');
var btnESaveAndNew = Ext.getCmp('btnESaveAndNew');
var btnEbtnEAccount = Ext.getCmp('btnEAccount');
if (enable) {
btnESave.enable();
btnESaveAndClose.enable();
btnESaveAndNew.enable();
btnEbtnEAccount.enable();
} else {
btnESave.disable();
btnESaveAndClose.disable();
btnESaveAndNew.disable();
btnEbtnEAccount.disable();
}
},
Print: function () {
var basicForm = this.formEdit.getForm();
var billNo = basicForm.findField('BillNo').value;
if (billNo == '*' || billNo == '') {
Ext.Msg.show({ title: '错误', msg: '单据还没有保存,请保存后再打印', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
return;
}
var printType = 'MSWLDJBS';
var sql1 = "SET LANGUAGE 'us_english' SELECT * FROM tMsWlDjHead WHERE BillNo = '" + billNo + "'";
var sql2 = "";
var sql3 = "";
var sql4 = "";
var sql5 = "";
var sql6 = "";
PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6);
}
});