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/MsWlBulk/MsWlBulkEdit.js

970 lines
35 KiB
JavaScript

3 years ago
Ext.namespace('DsTruck');
DsTruck.MsWlBulkEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsWlBulkEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.MsWlBulkEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.bodyDel = [];
//枚举参照相关
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('');
}
}
}
}
});
this.comboxPayCustCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '付款单位代码',
store: this.storeCustCode,
name: 'PayCustCode',
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('PayCustName');
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: '完成日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'WcDate', 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: '报表日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'RptDate', 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: '付款单位',
name: 'PayCustName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
readOnly: true,
name: 'BillNo'
}, this.comboxSalesCode, this.comboxCustCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '经手人',
name: 'CustLinkman'
}, {
fieldLabel: '工厂地址',
name: 'DetiNation'
}, {
fieldLabel: '联系电话',
name: 'LinkTel'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '发货单位',
name: 'Shipper'
}, {
fieldLabel: '收货单位',
name: 'Consignee'
}, {
fieldLabel: '托运时间',
format: 'Y-m-d',
xtype: 'datefield',
name: 'CustDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '起运时间',
format: 'Y-m-d',
xtype: 'datefield',
name: 'DepartureDate'
}, {
fieldLabel: '到达时间',
format: 'Y-m-d',
xtype: 'datefield',
name: 'ArrivalDate'
}, {
fieldLabel: '品名',
name: 'ClsName'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '包装规格',
name: 'PackSpec'
}, {
fieldLabel: '货物等级',
name: 'CargoLevel'
}, this.comboxBillStatus
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '船 名',
name: 'Vessel'
}, {
fieldLabel: '装卸项目',
name: 'LoadItem'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '总重量',
xtype: 'numberfield',
allowBlank: false,
name: 'Weight'
}, {
fieldLabel: '装货地点',
name: 'LoadPlace'
}, {
fieldLabel: '卸货地点',
name: 'UnLoadPlace'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '单次里程',
xtype: 'numberfield',
allowBlank: false,
name: 'OneMil'
}, this.comboxPayCustCode, {
fieldLabel: '付款时间',
format: 'Y-m-d',
xtype: 'datefield',
name: 'PayDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '实际运输重量',
xtype: 'numberfield',
allowBlank: false,
name: 'RealWeight'
}, {
fieldLabel: '运输费率',
xtype: 'numberfield',
allowBlank: false,
name: 'TransPrice'
}, {
fieldLabel: '自卸车费率',
xtype: 'numberfield',
allowBlank: false,
name: 'DumpPrice'
}, {
fieldLabel: '铲车费率',
xtype: 'numberfield',
allowBlank: false,
name: 'LoadPrice'
}
]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsWlBulkPound',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/MsWlBulk/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,
features: [{
ftype: 'summary'//Ext.grid.feature.Summary表格汇总特性
}],
plugins: [this.gridListCellEditing],
selType: 'cellmodel',
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
width: 150
}, {
sortable: true,
dataIndex: 'GId',
header: '惟一编号',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'TruckNo',
header: '车号',
width: 80
}, {
sortable: true,
dataIndex: 'DrvName',
header: '司机',
width: 80
}, {
sortable: true,
dataIndex: 'DepartureDate',
header: '起运日期',
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
width: 80
}, {
sortable: true,
dataIndex: 'DepartureTime',
header: '起运时间',
width: 60
}, {
sortable: true,
dataIndex: 'LoadPlace',
header: '装货地点',
width: 120
}, {
sortable: true,
dataIndex: 'UnLoadPlace',
header: '卸货地点',
width: 120
}, {
sortable: true,
dataIndex: 'OneMil',
header: '间隔距离',
summaryType: 'sum',
width: 80
}, {
sortable: true,
dataIndex: 'Weight',
header: '实际运输总重量',
summaryType: 'sum',
width: 100
}, {
sortable: true,
dataIndex: 'TonMil',
header: '吨公里',
summaryType: 'sum',
width: 100
}, {
sortable: true,
dataIndex: 'RealTransPrice',
header: '实际运输费率',
summaryType: 'sum',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 100
}, {
sortable: true,
dataIndex: 'RealTransTotal',
header: '实际运输运费',
summaryType: 'sum',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 120
}, {
sortable: true,
dataIndex: 'RatedFuel',
header: '额定油耗',
summaryType: 'sum',
width: 80
}, {
sortable: true,
dataIndex: 'OverLoadMil',
header: '实际重驶里程',
summaryType: 'sum',
width: 76
}, {
sortable: true,
dataIndex: 'NoLoadMil',
header: '实际空驶里程',
summaryType: 'sum',
width: 76
}, {
sortable: true,
dataIndex: 'LoadCount',
header: '实际运行次数',
summaryType: 'sum',
width: 100
}
]
});
//按钮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.panelBodyChFee = new Ext.Panel({
title: '运输明细',
layout: "border",
region: 'center',
margin: '5 10',
frame: true,
items: [this.gridList]
});
Ext.apply(this, {
items: [this.panelBtn, this.formEdit, this.panelBodyChFee]
});
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 (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.serialNo = 0;
this.bodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/MsWlBulk/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
});
var billno = '*';
var gid = '*';
if (this.opStatus == 'edit') {
billno = this.editRecord.get('BillNo');
gid = this.editRecord.get('GId');
}
this.storeBodyList.load({ params: { billno: billno} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
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 data = this.formEdit.getForm().getValues();
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsWlBulk/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody
},
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('MsWlBulkHead', 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.commit();
};
} 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
,
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
// if (e.field == 'CustCode' || e.field == 'PayCustCode') {
if (e.field == 'OneMil') {
var loadcount = e.record.data['LoadCount'];
var onemil = e.record.data['OneMil'];
var weight = e.record.data['Weight'];
e.record.set('TonMil', (onemil * weight).toFixed(2));
} else if (e.field == 'RealTransPrice') {
var transPrice = e.record.data['RealTransPrice'];
var weight = e.record.data['Weight'];
e.record.set('RealTransTotal', (transPrice * weight).toFixed(2));
}
},
addDetail: function () {
var newSerialno = DsGetNewSerialNo(this.storeBodyList, this.serialNo);
this.serialNo = newSerialno;
var record = Ext.create('MsWlBulkDetail', {
BillNo: '*',
SerialNo: newSerialno,
GId: NewGuid(),
LoadPlace: '',
UnLoadPlace: '',
OneMil: 0,
LoadCount: 0,
TransPrice: 0,
TransTotal: 0,
FeeStatus: 1,
FeeStatus_Ref: '录入状态',
AuditStatus: 0,
Remark: ''
});
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]);
}
},
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: '0113'//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('MsWlBulkHead', 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("提示", '托单已记账,正在进行路单记账,请等待操作完成,不要执行任何操作!');
//#region 路单记账
var msgBox = Ext.MessageBox.show({
title: '提示',
msg: '正在进行路单记账,请不要关闭页面!',
modal: true,
width: 300,
progress: true
})
var count = 1; //滚动条被刷新的次数
var percentage = 0; //进度百分比
var progressText = ''; //进度条信息
var lddata = this.storeBodyList.data.items; //托单下的路单集合
var inProgress = false;
var currbillno = '';
var successdata = '';
var failddata = '';
var task = {
run: function () {
//计算进度
percentage = (count / lddata.length).toFixed(2);
//生成进度条文字
progressText = '当前完成度:' + percentage * 100 + "%";
//更新信息提示对话框
msgBox.updateProgress(percentage, progressText, '当前正在进行路单【' + currbillno + '】的记账操作');
//操作完成
if (count >= lddata.length) {
Ext.TaskManager.stop(task);
msgBox.updateProgress(1, '当前完成度:100%', '操作完成!');
msgBox.hide();
Ext.MessageBox.alert("提示", '操作完成!');
}
if (!inProgress) {
//进行入账
inProgress = true;
var flag = true;
for (var i = 0; i < lddata.length; i++) {
//获取路单号
var billno = lddata[i].data.BillNo;
Ext.Ajax.request({
waitMsg: '正在记账...',
scope: this,
async: true,
url: '/CommMng/PubSys/Account',
params: {
billno: billno,
ywtype: '0115'//headdata.YwType
},
callback: function (options, success, response) {
flag = true;
if (success) {
currbillno = billno;
count++;
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) //成功
{
successdata += billno + ',';
} else //记账失败失败
{
failddata += billno + ',';
}
} else {
failddata += billno + ',';
}
},
failure: function (response, options) {
flag = true;
}
}); //end Ext.Ajax.request
}
}
},
interval: 200
}
Ext.TaskManager.start(task);
//#endregion
} 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 = 'MSWLBULKBS';
var sql1 = "SET LANGUAGE 'us_english' SELECT * FROM tMsWlBulkHead WHERE BillNo = '" + billNo + "'";
var sql2 = "";
var sql3 = "";
var sql4 = "";
var sql5 = "";
var sql6 = "";
PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6);
}
});
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime)
return;
}
}