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/TruckMng/Viewsjs/WlBsCard/WlBsCardEdit.js

869 lines
28 KiB
JavaScript

2 years ago
Ext.namespace('DsTruck');
DsTruck.WlBsCardEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.WlBsCardEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.WlBsCardEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.ysSerialNo = 0;
this.ysBodyDel = [];
this.yfSerialNo = 0;
this.yfBodyDel = [];
//枚举参照相关
//表参照相关
this.storeOrgCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'BmOrg',
proxy: { url: '/TruckMng/WlBsCard/GetOrgCodeList' }
});
this.storeOrgCode.load();
this.comboxOrgCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '组织编码',
store: this.storeOrgCode,
name: 'OrgCode',
valueField: 'OrgCode',
displayField: 'OrgName'
});
this.storeCustName = Ext.create('DsExt.ux.RefTableStore', {
model: 'TruckClient',
proxy: { url: '/TruckMng/WlBsCard/GetCustNameList' }
});
this.storeCustName.load();
this.comboxCustName = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '委托单位',
store: this.storeCustName,
name: 'CustName',
valueField: 'CODENAME',
displayField: 'SHORTNAME'
});
this.storeSales = Ext.create('DsExt.ux.RefTableStore', {
model: 'TruckUser',
proxy: { url: '/TruckMng/WlBsCard/GetSalesList' }
});
this.storeSales.load();
this.comboxSales = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '揽货人',
store: this.storeSales,
name: 'Sales',
valueField: 'CODENAME',
displayField: 'SHOWNAME'
});
this.storeVoyVeg = Ext.create('DsExt.ux.RefTableStore', {
model: 'TruckVoyInfo',
proxy: { url: '/TruckMng/WlBsCard/GetVoyVegList' }
});
this.storeVoyVeg.load();
this.comboxVoyVeg = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '船名航次',
store: this.storeVoyVeg,
name: 'VoyVeg',
valueField: 'VOID',
displayField: 'VESSELVOYNO'
});
this.storeSendYard = Ext.create('DsExt.ux.RefTableStore', {
model: 'TruckClient',
proxy: { url: '/TruckMng/WlBsCard/GetSendYardList' }
});
this.storeSendYard.load();
this.comboxSendYard = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '拖箱场站',
store: this.storeSendYard,
name: 'SendYard',
valueField: 'CODENAME',
displayField: 'SHORTNAME'
});
this.storeRtnYard = Ext.create('DsExt.ux.RefTableStore', {
model: 'TruckClient',
proxy: { url: '/TruckMng/WlBsCard/GetRtnYardList' }
});
this.storeRtnYard.load();
this.comboxRtnYard = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '返箱场站',
store: this.storeRtnYard,
name: 'RtnYard',
valueField: 'CODENAME',
displayField: 'SHORTNAME'
});
//编辑form
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: [
{//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: 'LrTime',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '入账日期',
name: 'RzDate',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '入账时间',
name: 'RzTime',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '结账日期',
name: 'JzDate',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '用户姓名',
name: 'UserName',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '组织名称',
name: 'OrgName',
flex: 0,
hidden: true,
margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
name: 'BillNo'
}, {
fieldLabel: '用户编码',
name: 'UserCode'
}, this.comboxOrgCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '物流号',
name: 'LogisticsNo'
}, {
fieldLabel: '委托日期',
name: 'CustDate'
}, this.comboxCustName
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxSales, {
fieldLabel: '集装箱信息',
name: 'ContainerInfo'
}, {
fieldLabel: '箱号封号',
name: 'ContainerNa'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxVoyVeg, {
fieldLabel: '开船日期',
name: 'EtDate'
}, {
fieldLabel: '截港日期',
name: 'EndPortDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '提单号',
name: 'MblNo'
}, this.comboxSendYard, this.comboxRtnYard
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '目的地',
name: 'DstArea'
}, {
fieldLabel: '工厂地址',
name: 'DetiNation'
}, {
fieldLabel: '拖货地址',
name: 'FactoryAddr'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '联系电话',
name: 'LinkTel'
}, {
fieldLabel: '联系人',
name: 'LinkMan'
}, {
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: [
{
text: "保存",
iconCls: "btnsave",
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
}
]
}); //end 按钮Toolbar
this.storeFeeType = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.FeeTypeRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetFeeTypeRefList' }
});
this.storeFeeType.load();
//*****************************Renderer函数******************************************
var storeFeeType = this.storeFeeType;
function renderFeeType(value) {
var records = storeFeeType.queryBy(function (rec) {
if (rec.data.FeeCode == value) {
return true;
} else {
return false;
}
});
if (records.getCount() > 0) {
return records.getAt(0).data.CodeAndName;
} else {
return '';
}
}
//定义Grid
var cellEditingYs = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
//定义数据集
this.storeFeeYs = Ext.create('Ext.data.Store', {
model: 'WlBsCardFixed',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/WlBsCard/GetFeeBodyList',
reader: {
id: 'BillNo,CreditDebit,SerialNo',
root: 'data',
totalProperty: 'totalCount'
}
}
});
this.comboxFeeTypeYs = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeFeeType,
valueField: 'FeeCode',
displayField: 'CodeAndName'
});
this.gridFeeYs = new Ext.grid.GridPanel({
store: this.storeFeeYs,
enableHdMenu: false,
plugins: [cellEditingYs],
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
selType: 'cellmodel',
tbar: [{
text: '增加明细',
tooltip: '增加明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddDetailClick(button, event, this.storeFeeYs, '0', cellEditingYs);
},
scope: this
}, '-', {
text: '删除明细',
tooltip: '删除明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelDetailClick(button, event, '0');
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
dataIndex: "SerialNo",
header: "序号",
width: 40
}, {
sortable: true,
dataIndex: 'CreditDebit',
header: '费用类型',
hidden: true,
width: 20
}, {
sortable: true,
dataIndex: 'FeeTypeCode',
header: '费用编码',
editor: this.comboxFeeTypeYs,
renderer: renderFeeType,
width: 120
}, {
sortable: true,
dataIndex: 'DistCount',
header: '计费里程',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Price',
header: '费用单价',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'FsTotal',
header: '发生金额',
editor: {
xtype: 'numberfield',
allowBlank: false
},
width: 160
}, {
sortable: true,
dataIndex: 'JsTotal',
header: '实际金额',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
editor: {
xtype: 'textfield'
},
width: 200
}
]
});
//定义数据集
this.storeFeeYf = Ext.create('Ext.data.Store', {
model: 'WlBsCardFixed',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/WlBsCard/GetFeeBodyList',
reader: {
id: 'BillNo,CreditDebit,SerialNo',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//定义Grid
var cellEditingYf = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.gridFeeYf = new Ext.grid.GridPanel({
store: this.storeFeeYf,
plugins: [cellEditingYf],
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
tbar: [{
text: '增加明细',
tooltip: '增加明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddDetailClick(button, event, this.storeFeeYf, '1', cellEditingYs);
},
scope: this
}, '-', {
text: '删除明细',
tooltip: '删除明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelDetailClick(button, event, '1');
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
dataIndex: "SerialNo",
header: "序号",
width: 40
}, {
sortable: true,
dataIndex: 'CreditDebit',
header: '费用类型',
hidden: true,
width: 20
}, {
sortable: true,
dataIndex: 'FeeTypeCode',
header: '费用编码',
editor: this.comboxFeeTypeYs,
renderer: renderFeeType,
width: 120
}, {
sortable: true,
dataIndex: 'DistCount',
header: '计费里程',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Price',
header: '费用单价',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'FsTotal',
header: '发生金额',
editor: {
xtype: 'numberfield',
allowBlank: false
},
width: 160
}, {
sortable: true,
dataIndex: 'JsTotal',
header: '实际金额',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
width: 200
}
]
});
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 280,
items: [this.panelBtn, this.formEdit]
});
this.panelFeeYs = new Ext.Panel({
title: '应收费用',
layout: "border",
region: 'west',
width: 400,
margin: '5 10',
items: [this.gridFeeYs]
});
this.panelFeeYf = new Ext.Panel({
title: '应付费用',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridFeeYf]
});
this.panelFee = new Ext.Panel({
layout: "border",
region: "center",
items: [
this.panelFeeYs, this.panelFeeYf
]
});
Ext.apply(this, {
items: [this.panelTop, this.panelFee]
});
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.ysSerialNo = 0;
this.ysBodyDel = [];
this.yfSerialNo = 0;
this.yfBodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/WlBsCard/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
});
var billno = '*';
if (this.opStatus == 'edit') {
billno = this.editRecord.get('BillNo');
this.formEdit.getForm().findField('BillNo').setDisabled(false);
}
this.storeFeeYs.load({ params: { billno: billno, creditdebit: '0'} });
this.storeFeeYf.load({ params: { billno: billno, creditdebit: '1'} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
basicForm.findField('BillNo').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('BillNo').setDisabled(true);
var bodydatas = [];
for (var i = 0; i < this.storeFeeYs.getCount(); i += 1) {
var member = this.storeFeeYs.getAt(i);
bodydatas.push(member);
};
var jsonYsBody = ConvertRecordsToJson(bodydatas);
var jsonYsDelBody = ConvertRecordsToJsonAll(this.ysBodyDel);
var bodyyfdatas = [];
for (i = 0; i < this.storeFeeYf.getCount(); i += 1) {
var memberyf = this.storeFeeYf.getAt(i);
bodyyfdatas.push(memberyf);
};
var jsonYfBody = ConvertRecordsToJson(bodyyfdatas);
var jsonYfDelBody = ConvertRecordsToJsonAll(this.yfBodyDel);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/WlBsCard/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
ysbody: jsonYsBody,
ysdelbody: jsonYsDelBody,
yfbody: jsonYfBody,
yfdelbody: jsonYfDelBody
},
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 p = Ext.create('WlBsCardHead', returnData); // Ext.create('WlBsCardHead', data, NewGuid()); //或者new WlBsCardHead(data, NewGuid());
this.storeList.add(p);
this.editRecord = p;
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('WlBsCardHead', 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 i = 0; i < this.storeFeeYs.getCount(); i += 1) {
var member = this.storeFeeYs.getAt(i);
member.set("BillNo", this.editRecord.get('BillNo'));
member.commit();
};
for (var i = 0; i < this.storeFeeYf.getCount(); i += 1) {
var member = this.storeFeeYf.getAt(i);
member.set("BillNo", this.editRecord.get('BillNo'));
member.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, store, creditdebit, cellediting) {
var newSerialno = this.GetHandleSerialNo(store, creditdebit);
var record = Ext.create('WlBsCardFixed', {
BillNo: '*', SerialNo: newSerialno, CreditDebit: creditdebit, FeeTypeCode: '', DistCount: 0, Price: 0, FsTotal: 0, JsTotal: 0, Remark: ''
});
store.add(record);
var n = store.getCount();
cellediting.startEditByPosition({ row: n - 1, column: 0 });
},
GetHandleSerialNo: function (store, creditdebit) {
var result = 0;
if (creditdebit == '0') {
result = this.ysSerialNo;
} else {
result = this.yfSerialNo;
}
if (result == 0) {
for (var i = 0; i < store.getCount(); i += 1) {
var member = store.getAt(i);
if (member.data.SerialNo > result) {
result = member.data.SerialNo;
}
}
}
result = result + 1;
if (creditdebit == '0') {
this.ysSerialNo = result;
} else {
this.yfSerialNo = result;
}
return result;
},
onDelDetailClick: function (button, event, creditdebit) {
var store = null;
if (creditdebit == '0') {
store = this.storeFeeYs;
} else {
store = this.storeFeeYf;
}
var result = 0;
if (creditdebit == '0') {
result = this.ysSerialNo;
} else {
result = this.yfSerialNo;
}
if (result == 0) {
for (var i = 0; i < store.getCount(); i += 1) {
var member = store.getAt(i);
if (member.data.SerialNo > this.giSerialNo) {
result = member.data.SerialNo;
}
}
}
if (creditdebit == '0') {
this.ysSerialNo = result;
} else {
this.yfSerialNo = result;
}
var selectedRecords = [];
if (creditdebit == '0') {
selectedRecords = this.gridFeeYs.selModel.getSelection();
} else {
selectedRecords = this.gridFeeYf.selModel.getSelection();
}
if (selectedRecords.length > 0) {
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
if (rec.BillNo != "" || rec.BillNo != "*") //如果是新增但没有保存的数据,没有必要提交到后台
{
if (creditdebit == '0')
this.ysBodyDel.push(rec);
else {
this.yfBodyDel.push(rec);
}
}
if (creditdebit == '0') {
this.storeFeeYs.remove(selectedRecords[i]);
} else {
this.storeFeeYf.remove(selectedRecords[i]);
}
}
}
},
GetBillNo: function () {
if (this.editRecord == null)
return '*';
else {
return this.editRecord.get('BillNo');
}
}
});