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/MsWlBulkPc/MsWlBulkPcEdit.js

1388 lines
51 KiB
JavaScript

3 years ago
Ext.namespace('DsTruck');
DsTruck.MsWlBulkPcEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsWlBulkPcEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.MsWlBulkPcEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
DataLoading: true,
initUIComponents: function () {
this.serialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑form)
this.storeTruckNo = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsWlPcHeadRefMsWlTruck',
proxy: { url: '/TruckMng/MsWlBulkPc/GetTruckNoList' }
});
this.storeTruckNo.load({ params: { condition: ""} });
this.comboxTruckNo = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '车牌号',
store: this.storeTruckNo,
name: 'TruckNo',
allowBlank: false,
valueField: 'TruckNo',
displayField: 'TruckNo',
listeners: {
change: function (field, newValue, oldValue) {
this.TruckNoChange(field, newValue, oldValue);
},
scope: this
}
});
this.storeDrvName = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsWlPcHeadRefMsWlDriver',
proxy: { url: '/TruckMng/MsWlBulkPc/GetDrvNameList' }
});
this.storeDrvName.load({ params: { condition: ""} });
this.comboxDrvName = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '司机姓名',
store: this.storeDrvName,
name: 'DrvCode',
valueField: 'DrvCode',
displayField: 'CodeAndName',
listeners: {
scope: this,
'select': function (combo, records, eOpts) {
if (records.length > 0) {
this.setDrvName(records[0].data.DrvCode);
}
}
}
});
//编辑form
this.formEdit = Ext.widget('form', {
region: 'center',
frame: true,
bodyPadding: 5,
autoScroll: true,
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: '录入日期',
name: 'LrDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '记账日期',
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: 'DrvName',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '司机手机',
name: 'Mobile', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '目的地',
name: 'DstArea', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '工厂地址',
name: 'DetiNation', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '拖货地址',
name: 'FactoryAddr', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '联系电话',
name: 'LinkTel', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '联系人',
name: 'LinkMan', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '额定里程',
name: 'RatedMil', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '实际里程',
name: 'RealMil', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '运输次数',
name: 'LoadCount', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '到厂日期',
name: 'ArriveDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '调度员编码',
name: 'DdCode', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '调度员姓名',
name: 'DdName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '返回时间',
name: 'ReturnDate', flex: 0, hidden: true, margins: '0'
}, /*{
fieldLabel: '备注',
name: 'Remark', flex: 0, hidden: true, margins: '0'
}*/, {
fieldLabel: '业务锁定状态',
name: 'BillStatus', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '费用锁定状态',
name: 'FeeStatus', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '惟一编号',
name: 'GId', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '时间戳',
name: 'TimeMark', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '派车单类型',
name: 'PcBillType', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
disabled: true,
readOnly: true,
name: 'BillNo'
}, this.comboxTruckNo, this.comboxDrvName
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '派车日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'ExpDate',
listeners: {
change: function (field, eOpts) {
if (field.lastValue != "") {
var ACCDATE = (this.formEdit.getForm().findField('ACCDATE').getRawValue());
if (ACCDATE == "" || ACCDATE == null) {
_M = field.lastValue.getMonth() + 1;
var _M2 = "";
if (_M < 10) {
_M2 = "0" + _M;
} else {
_M2 = "" + _M;
}
_a = field.lastValue.getFullYear() + '-' + _M2;
this.formEdit.getForm().findField('ACCDATE').setValue(_a);
}
}
this.Cansearch = false;
},
scope: this
}
}, {
fieldLabel: '额定油耗',
xtype: 'numberfield',
allowBlank: false,
name: 'RatedFuel'
}, {
fieldLabel: '本次加油量',
xtype: 'numberfield',
allowBlank: false,
name: 'FuelQty'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '实际油耗',
xtype: 'numberfield',
allowBlank: false,
name: 'RealFuel'
}, {
fieldLabel: '空驶里程',
xtype: 'numberfield',
allowBlank: false,
readOnly: true,
name: 'NoLoadMil'
}, {
fieldLabel: '重驶里程',
xtype: 'numberfield',
allowBlank: false,
readOnly: true,
name: 'OverLoadMil'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '运量',
xtype: 'numberfield',
allowBlank: false,
readOnly: true,
name: 'Ton'
}, {
fieldLabel: '总里程',
xtype: 'numberfield',
allowBlank: false,
readOnly: true,
name: 'TotalMil'
}, {
fieldLabel: '油票号',
xtype: 'textfield',
name: 'OilticketNO'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '注意事项',
xtype: 'textfield',
//allowBlank: true,
//readOnly: true,
name: 'Remark',flex:2
}, {
fieldLabel: '统计期间',
name: 'ACCDATE',
xtype: 'monthfield',flex:1
}
]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//#endregion
//#region 按钮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
//#endregion
//#region 明细表
//#region 明细表表格相关
this.storeBulkBillNoRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsWlBulkPoundRefMsWlBulkHead',
proxy: { url: '/TruckMng/MsWlBulkPc/GetBulkBillNoList' }
});
this.storeBulkBillNoRef.load({ params: { condition: ""} });
this.comboxBulkBillNoRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeBulkBillNoRef,
name: 'BulkBillNo',
valueField: 'BillNo',
displayField: 'BillNo',
allowBlank: false,
editable: false
});
this.storeCustCodeRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.CustomRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetCustomRefList' }
});
this.storeCustCodeRef.load({ params: { condition: "ISCONTROLLER='1'"} });
this.comboxCustCodeRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeCustCodeRef,
name: 'CustCode',
valueField: 'CustCode',
displayField: 'CodeAndName'
});
this.comboxPayCustCodeRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeCustCodeRef,
name: 'PayCustCode',
valueField: 'CustCode',
displayField: 'CodeAndName'
});
//#endregion
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsWlBulkPound',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/MsWlBulkPc/GetBodyList',
reader: {
id: 'BillNo,SerialNo',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.gridList = new Ext.grid.GridPanel({
store: this.storeBodyList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridListCellEditing],
selType: 'cellmodel',
tbar: [{
text: '增加明细',
tooltip: '增加明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddDetailClick(button, event);
},
scope: this
}, '-', {
text: '删除明细',
tooltip: '删除明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelDetailClick(button, event);
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'SerialNo',
header: '序号',
width: 30
}, {
sortable: true,
dataIndex: 'BulkBillNo',
header: '托运单号',
editor: this.comboxBulkBillNoRef,
width: 150
}, {
sortable: true,
dataIndex: 'GId',
header: '惟一编号',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'CustCode',
header: '委托单位代码',
renderer: function (value, p, record) {
if (value == null || value == '')
return '';
else
return value + '-' + record.data.CustCode_Ref;
},
editor: this.comboxCustCodeRef,
width: 120
}, {
sortable: true,
dataIndex: 'CustName',
header: '委托单位',
hidden: true,
width: 80
}, {
sortable: true,
dataIndex: 'ClsName',
header: '品名',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 100
}, {
sortable: true,
dataIndex: 'DepartureDate',
header: '起运日期',
editor: {
xtype: 'datefield',
format: 'Y-m-d',
selectOnFocus: true
},
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
width: 80
}, {
sortable: true,
dataIndex: 'DepartureTime',
header: '起运时间',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 60
}, {
sortable: true,
dataIndex: 'LoadPlace',
header: '装货地点',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 80
}, {
sortable: true,
dataIndex: 'UnLoadPlace',
header: '卸货地点',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 80
}, {
sortable: true,
dataIndex: 'OneMil',
header: '间隔距离',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'PlanLoadCount',
header: '计划运行次数',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'LoadCount',
header: '实际运行次数',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'UnLoadCount',
header: '实际倾斜次数',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'OverLoadMil',
header: '实际重驶里程',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'NoLoadMil',
header: '实际空驶里程',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'Weight',
header: '实际运输总重量',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'TonMil',
header: '吨公里',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 76
}, {
sortable: true,
dataIndex: 'RatedFuel',
header: '额定油耗',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 80
}, {
sortable: true,
dataIndex: 'TransPrice',
header: '费率',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 85
}, {
sortable: true,
dataIndex: 'TransTotal',
header: '运费',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'TruckNo',
header: '车牌号',
hidden: true,
width: 200
}, {
sortable: true,
dataIndex: 'DrvName',
header: '司机姓名',
hidden: true,
width: 200
}, {
sortable: true,
dataIndex: 'WorkTime',
header: '工作时间',
hidden: true,
width: 160
}
]
});
//#endregion 明细表
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 190,
items: [this.panelBtn, this.formEdit]
});
Ext.apply(this, {
items: [this.panelTop, this.gridList]
});
//#endregion
//绑定查询窗体
this.ParentWin = window.parent.opener;
//初始化数据
this.InitData();
//绑定事件
this.gridList.on('edit', function (editor, e, eOpts) {
this.gridAfterEdit(editor, e, eOpts);
}, this);
}, //end initUIComponents
InitData: function () {
this.opStatus = 'add';
var condition = '';
if (this.ParentWin) {
var ret = this.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.serialNo = 0;
this.bodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/MsWlBulkPc/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.DataLoading = true;
this.formEdit.getForm().reset();
this.formEdit.getForm().setValues(data);
this.DataLoading = false;
if (data.JzDate == null || data.JzDate == '') {
this.setSaveBtnStatus(true);
} else {
this.setSaveBtnStatus(false);
}
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
var billno = '*';
if (this.opStatus == 'edit') {
billno = this.editRecord.get('BillNo');
this.formEdit.getForm().findField('BillNo').setDisabled(true);
}
this.storeBodyList.load({ params: { billno: billno} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
/* //判断表格数据是否合法
if (!validateEditorGridPanel(this.gridList)) {
return;
}
*/
basicForm.findField('BillNo').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('BillNo').setDisabled(true);
var bodydatas = [];
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
var member = this.storeBodyList.getAt(i);
bodydatas.push(member);
}
var jsonBody = ConvertRecordsToJson(bodydatas);
var jsonDelBody = ConvertRecordsToJsonAll(this.bodyDel);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsWlBulkPc/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody,
delbody: jsonDelBody
},
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';
basicForm.findField('BillNo').setDisabled(true);
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("BillNo", this.editRecord.get('BillNo'));
memberbody.commit();
};
} else if (type == '1') {
window.close();
} else {
this.LoadData('add', '');
basicForm.findField('BillNo').setDisabled(false);
}
} 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
onAddDetailClick: function (button, event) {
this.addDetail();
}, //end onAddDetailClick
onDelDetailClick: function (button, event) {
this.deleteDetail();
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
// if (e.field == 'CustCode' || e.field == 'PayCustCode') {
if (e.field == 'CustCode') {
var records = DsStoreQueryBy(this.storeCustCodeRef, 'CustCode', e.value);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
var custName = data.CustName;
if (e.field == 'CustCode') {
e.record.set('CustCode_Ref', custName);
e.record.set('CustName', custName);
// e.record.set('PayCustCode', e.value);
}
// e.record.set('PayCustCode_Ref', custName);
// e.record.set('PayCustName', custName);
} else {
if (e.field == 'CustCode') {
e.record.set('CustCode_Ref', '');
e.record.set('CustName', '');
// e.record.set('PayCustCode', '');
}
// e.record.set('PayCustCode_Ref', '');
// e.record.set('PayCustName', '');
}
}
else if (e.field == 'BulkBillNo') {
var opStatus = 'edit';
var bulkBillNo = e.value;
var condition = " BillNo='" + bulkBillNo + "'";
Ext.Ajax.request({
waitMsg: '正在查询散户托单数据...',
url: '/TruckMng/MsWlBulk/GetData',
async: false,
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
});
this.copyBulkHeadData(e, null);
return;
}
var bulkHeadData = result.data;
this.copyBulkHeadData(e, bulkHeadData);
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
this.copyBulkHeadData(e, null);
}
},
scope: this
});
}
else if (e.field == 'OneMil') {
var loadcount = e.record.data['LoadCount'];
var onemil = e.record.data['OneMil'];
e.record.set('OverLoadMil', (onemil * loadcount).toFixed(2));
this.setOverLoadMilTotal();
this.setMilTotal();
var overloadmil = e.record.data['OverLoadMil'];
var noloadmil = e.record.data['NoLoadMil'];
var weight = e.record.data['Weight'];
var unloadcount = e.record.data['UnLoadCount'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
var nofuel = this.getTruckLoadFuel((onemil * weight).toFixed(2), noloadmil, overloadmil, unloadcount);
e.record.set('RatedFuel', nofuel);
this.setNoFuelCountTotal();
}
else if (e.field == 'OverLoadMil') {
this.setOverLoadMilTotal();
this.setMilTotal();
var overloadmil = e.record.data['OverLoadMil'];
var noloadmil = e.record.data['NoLoadMil'];
var weight = e.record.data['Weight'];
var onemil = e.record.data['OneMil'];
var unloadcount = e.record.data['UnLoadCount'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
var nofuel = this.getTruckLoadFuel((onemil * weight).toFixed(2), noloadmil, overloadmil, unloadcount);
e.record.set('RatedFuel', nofuel);
this.setNoFuelCountTotal();
}
else if (e.field == 'NoLoadMil') {
this.setNoLoadMilTotal();
this.setMilTotal();
var overloadmil = e.record.data['OverLoadMil'];
var noloadmil = e.record.data['NoLoadMil'];
var weight = e.record.data['Weight'];
var unloadcount = e.record.data['UnLoadCount'];
var onemil = e.record.data['OneMil'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
var nofuel = this.getTruckLoadFuel((onemil * weight).toFixed(2), noloadmil, overloadmil, unloadcount);
this.setNoFuelCountTotal();
}
else if (e.field == 'PlanLoadCount') {
} else if (e.field == 'LoadCount') {
this.setLoadCountTotal();
var loadcount = e.record.data['LoadCount'];
var onemil = e.record.data['OneMil'];
e.record.set('OverLoadMil', (onemil * loadcount).toFixed(2));
} else if (e.field == 'UnLoadCount') {
var overloadmil = e.record.data['OverLoadMil'];
var noloadmil = e.record.data['NoLoadMil'];
var weight = e.record.data['Weight'];
var unloadcount = e.record.data['UnLoadCount'];
var onemil = e.record.data['OneMil'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
var nofuel = this.getTruckLoadFuel((onemil * weight).toFixed(2), noloadmil, overloadmil, unloadcount);
e.record.set('RatedFuel', nofuel);
this.setNoFuelCountTotal();
}
else if (e.field == 'Weight' || e.field == 'TransPrice') {
if (e.field == 'Weight') {
this.setWeightCountTotal();
var overloadmil = e.record.data['OverLoadMil'];
var noloadmil = e.record.data['NoLoadMil'];
var weight = e.record.data['Weight'];
var unloadcount = e.record.data['UnLoadCount'];
var onemil = e.record.data['OneMil'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
var nofuel = this.getTruckLoadFuel((onemil * weight).toFixed(2), noloadmil, overloadmil, unloadcount);
e.record.set('RatedFuel', nofuel);
this.setNoFuelCountTotal();
}
var transPrice = e.record.data['TransPrice'];
var weight = e.record.data['Weight'];
e.record.set('TransTotal', (transPrice * weight).toFixed(2));
}
},
//#region 明细表合计
setAllTotal: function () {
this.setOverLoadMilTotal();
this.setNoLoadMilTotal();
this.setLoadCountTotal();
this.setWeightCountTotal();
this.setMilTotal();
},
setMilTotal: function () {
var total = this.calcDetailTotal('OverLoadMil');
var nototal = this.calcDetailTotal('NoLoadMil');
this.setHeadFieldValue('TotalMil', total + nototal);
},
setOverLoadMilTotal: function () {
var total = this.calcDetailTotal('OverLoadMil');
this.setHeadFieldValue('OverLoadMil', total);
},
setNoLoadMilTotal: function () {
var total = this.calcDetailTotal('NoLoadMil');
this.setHeadFieldValue('NoLoadMil', total);
},
setLoadCountTotal: function () {
var total = this.calcDetailTotal('LoadCount');
this.setHeadFieldValue('LoadCount', total);
},
setWeightCountTotal: function () {
var total = this.calcDetailTotal('Weight');
this.setHeadFieldValue('Ton', total);
},
setNoFuelCountTotal: function () {
var total = this.calcDetailTotal('RatedFuel');
this.setHeadFieldValue('RatedFuel', total);
},
calcDetailTotal: function (fieldName) {
var total = 0;
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
var member = this.storeBodyList.getAt(i);
var value = member.get(fieldName);
total = total + value;
}
return total;
},
setHeadFieldValue: function (fieldName, value) {
var field = this.formEdit.getForm().findField(fieldName);
field.setValue(value);
},
//#endregion
TruckNoChange: function (field, newValue, oldValue) {
if (this.DataLoading == true) return;
if (field.name == 'TruckNo') {
var records = DsStoreQueryBy(this.storeTruckNo, 'TruckNo', newValue);
var basicForm = this.formEdit.getForm();
if (records.getCount() > 0) {
var data = records.getAt(0).data;
basicForm.findField('DrvCode').setValue(data.DrvCode);
this.setDrvName(data.DrvCode);
basicForm.findField('Mobile').setValue(data.Mobile);
} else {
basicForm.findField('DrvCode').setValue('');
basicForm.findField('Mobile').setValue('');
}
}
},
setDrvName: function (drvCode) {
var recs = DsStoreQueryBy(this.storeDrvName, 'DrvCode', drvCode);
var basicForm = this.formEdit.getForm();
var custname = basicForm.findField('DrvName');
var mobile = basicForm.findField('Mobile');
if (recs.getCount() > 0) {
var data = recs.getAt(0).data;
custname.setValue(data.DrvName);
mobile.setValue(data.Mobile);
} else {
custname.setValue('');
mobile.setValue('');
}
},
addDetail: function () {
var newSerialno = DsGetNewSerialNo(this.storeBodyList, this.serialNo);
this.serialNo = newSerialno;
var record = Ext.create('MsWlBulkPound', {
BillNo: '*',
SerialNo: newSerialno,
BulkBillNo: '',
BulkBillNo_Ref: '',
GId: NewGuid(),
CustCode: '',
CustCode_Ref: '',
CustName: '',
ClsName: '',
PackSpec: '',
DepartureDate: '',
DepartureTime: '',
LoadPlace: '',
UnLoadPlace: '',
OneMil: 0,
PlanOverLoadMil: 0,
PlanNoLoadMil: 0,
PlanLoadCount: 0,
OverLoadMil: 0,
NoLoadMil: 0,
LoadCount: 0,
Weight: 0,
PayCustCode: '',
PayCustCode_Ref: '',
PayCustName: '',
TransPrice: 0,
TransTotal: 0,
TruckNo: '',
DrvName: '',
WorkTime: ''
});
this.storeBodyList.add(record);
var n = this.storeBodyList.getCount();
this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 2 });
},
deleteDetail: function () {
this.serialNo = DsGetCurSerialNo(this.storeBodyList, this.serialNo);
var selectedRecords = this.gridList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
if (rec.BillNo != "" || rec.BillNo != "*") //如果是新增但没有保存的数据,没有必要提交到后台
{
this.bodyDel.push(rec);
}
this.storeBodyList.remove(selectedRecords[i]);
this.setAllTotal();
}
},
copyBulkHeadData: function (e, bulkHeadData) {
if (bulkHeadData != null) {
e.record.set('CustCode', bulkHeadData.CustCode);
e.record.set('CustCode_Ref', bulkHeadData.CustName);
e.record.set('CustName', bulkHeadData.CustName);
e.record.set('TransPrice', bulkHeadData.DumpPrice);
e.record.set('ClsName', bulkHeadData.ClsName);
e.record.set('PackSpec', bulkHeadData.PackSpec);
e.record.set('LoadPlace', bulkHeadData.LoadPlace);
e.record.set('UnLoadPlace', bulkHeadData.UnLoadPlace);
e.record.set('OneMil', bulkHeadData.OneMil);
} else {
e.record.set('CustCode', '');
e.record.set('CustCode_Ref', '');
e.record.set('CustName', '');
e.record.set('TransPrice', 0);
e.record.set('ClsName', '');
e.record.set('PackSpec', '');
e.record.set('LoadPlace', '');
e.record.set('UnLoadPlace', '');
e.record.set('OneMil', 0);
}
},
getTruckNo: function () {
var truckNo = this.formEdit.getForm().findField('TruckNo');
return truckNo.getValue();
},
getTruckLoadFuel: function (ton, nomil, overmil,unloadcount) {
var resultFuel = 0;
var truckNo = this.getTruckNo();
if (truckNo == null || truckNo == "") {
resultFuel = 0;
return resultFuel;
}
if ((ton == null || ton == "") && (nomil == null || nomil == 0) && (overmil == null || overmil == 0) && (unloadcount == null || unloadcount == 0)) {
resultFuel = 0;
return resultFuel;
}
resultFuel = this.getTruckFuel(truckNo, overmil, ton,nomil,unloadcount);
return resultFuel;
},
getTruckFuel: function (truckNo, overmil, ton, mil, unloadcount) {
var resultFuel = 0;
Ext.Ajax.request({
waitMsg: '正在计算车里油量信息...',
url: '/TruckMng/MsWlBulkPc/GetTruckFuel',
async: false,
params: {
truckNo: truckNo,
overmil: overmil,
ton: ton,
mil: mil,
unloadcount:unloadcount
},
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
});
resultFuel = 0;
}
var data = result.data;
resultFuel = data;
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
resultFuel = 0;
}
},
scope: this
});
return resultFuel;
},
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: '0115'//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('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();
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 = 'MSWLBULKPC';
var sql1 = "SELECT [BillNo],[LrDate],[JzDate],[UserCode],[UserName],[OrgCode],[OrgName],[TruckNo],[DrvName],[Mobile],[ExpDate],[ContainerType], [ContainerQty],[VoyVeg],[EtDate],[EndPortDate],[MblNo],[YardCode],[YardName],[RtnYardCode],[RtnYardName],[DstArea],[DetiNation],[FactoryAddr] ";
sql1 = sql1 + " ,[LinkTel],[LinkMan],[RatedMil],[RatedFuel],[FuelQty],[RealMil],[RealFuel],[AroundTon], "; //[Ton],
sql1 = sql1 + " case [OverLoadMil] when 0 then '' else convert(varchar(50),OverLoadMil) end as OverLoadMil, ";
sql1 = sql1 + " case [NoLoadMil] when 0 then '' else convert(varchar(50),[NoLoadMil]) end as [NoLoadMil],";
sql1 = sql1 + " case [loadcount] when 0 then '' else convert(varchar(50),[loadcount]) end as [loadcount],";
sql1 = sql1 + " case [Ton] when 0 then '' else convert(varchar(50),[Ton]) end as [Ton]";
sql1 = sql1+ " ,[ArriveDate],[DdCode],[DdName],[ReturnDate],[RefBillNo],[Remark],[IsDouble],[RefBillNoSe],[ContainerTypeSe],[ContainerQtySe],[MblNoSe] ";
sql1 = sql1+ " ,[VoyVegSe],[EtDateSe],[EndPortDateSe],[YardCodeSe],[YardNameSe],[DstAreaSe],[FactoryAddrSe],[DetiNationSe],[LinkManSe],[LinkTelSe] ";
sql1 = sql1+ " ,[RtnYardCodeSe],[RtnYardNameSe],[BillStatus],[FeeStatus],[GId],[TotalMil],[TimeMark],[PcBillType],[LoadPlace],[LoadFuel],[NoLoadFuel] ";
sql1 = sql1+ " ,[RptDate],[BsType],[NeadLoadDate],[NeedArriveDate],[ArriveTime],[ReturnTime],[CustLikeManCode],[CustLikeManName],[CustTel],[CustCode] ";
sql1 = sql1+ " ,[CustName],[SalesCode],[SalesName],[DispatchCode],[DispatchName],[SendYardCode],[SendYardName],[DrvCode],[BillRises1],[ChangedMil] ";
sql1 = sql1+ " ,[ChangedFuel],[ChangedReson],[FeeOpStatus],[RunTimes],[ContainerNo],[SealNo],[ContainerNoSe],[SealNoSe],[OilLrDate],[OilUser],[OilticketNO] ";
sql1 = sql1 + " FROM [tMsWlPcHead] WHERE BillNo = '" + billNo + "'";
var sql2 = "SELECT [BillNo],[SerialNo],[BulkBillNo],[GId],[CustCode],[CustName],[ClsName],[PackSpec],[DepartureDate],[LoadPlace],[UnLoadPlace] ";
sql2 = sql2 + " ,[PlanOverLoadMil],[PlanNoLoadMil],[PayCustCode],[PayCustName],[PlanLoadCount], "; //[LoadCount],[Weight],
sql2 = sql2 + " case [OverLoadMil] when 0 then '' else convert(varchar(50),OverLoadMil) end as OverLoadMil, ";
sql2 = sql2 + " case [NoLoadMil] when 0 then '' else convert(varchar(50),[NoLoadMil]) end as [NoLoadMil] ";
//sql2 = sql2 + " ,case [PlanLoadCount] when 0 then '' else convert(varchar(50),[PlanLoadCount]) end as [PlanLoadCount] ";
sql2 = sql2 + " ,[TransPrice],[TransTotal],[TruckNo],[DrvName],[WorkTime],[UnloadCount],[RatedFuel],[heapweight],[DepartureTime] ";
sql2 = sql2 + " ,[OneMil],[WorkType],[RealTransPrice],[RealTransTotal], ";
sql2 = sql2 + " case [TonMil] when 0 then '' else convert(varchar(50),[TonMil]) end as [TonMil], ";
sql2 = sql2 + " case [loadcount] when 0 then '' else convert(varchar(50),[loadcount]) end as [loadcount],";
sql2 = sql2 + " case [Weight] when 0 then '' else convert(varchar(50),[Weight]) end as [Weight]";
sql2 = sql2 + " FROM [tMsWlBulkPound] WHERE BillNo = '" + billNo + "'";
var sql3 = "";
var sql4 = "";
var sql5 = "";
var sql6 = "";
PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6);
}
});