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.

856 lines
29 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

Ext.namespace('Shipping');
Shipping.MsCodeFeeTemplateAgentEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsCodeFeeTemplateAgentEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.MsCodeFeeTemplateAgentEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
feeType: 0,
StoreFee: null,
//需求编号SR2017061200005-3
initUIComponents: function () {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
this.feeaddtemplate = getUrlParam('feeaddtemplate');
//#region 编辑form
//枚举参照相关(编辑form)
this.storeISPUBLIC = Ext.create('Ext.data.Store', {
fields: ['DC', 'NAME']
});
this.storeISPUBLIC.add({ "DC": "是", "NAME": "是" });
this.storeISPUBLIC.add({ "DC": "否", "NAME": "否" });
this.comboxISPUBLIC = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: Zi.LAN.ISPUBLIC, //'是否公共',
store: this.storeISPUBLIC,
valueField: 'DC',
displayField: 'NAME',
name: 'ISPUBLIC'
});
//表参照相关(编辑form)
//编辑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: Zi.LAN.GID, //'GID',
name: 'GID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: Zi.LAN.CORPID, //'CORPID',
name: 'CORPID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: Zi.LAN.CREATEUSER, //'CREATEUSER',
name: 'CREATEUSER', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: Zi.LAN.NAME, //'模板名称',
name: 'NAME',
allowBlank: false
}, {
fieldLabel: Zi.LAN.DESCRIPTION, //'模板说明',
flex: 2, name: 'DESCRIPTION'
}, this.comboxISPUBLIC,{
fieldLabel: Zi.LAN.CREATEUSERREF, //'录入人',
readOnly: true,
name: 'CREATEUSERREF'
}, {
fieldLabel: Zi.LAN.CREATETIME, //'录入日期',
readOnly: true,
name: 'CREATETIME'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: []
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: Zi.LAN.REMARK, //'备注',
name: 'REMARK'
}]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//#endregion
//#region 按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
text: Zi.LAN.btnSave, //"保存",
iconCls: "btnsave",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
text: Zi.LAN.btnSaveAndClose, //"保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
'-',
{
text: Zi.LAN.btnSaveAndNew, //"保存并新建",
handler: function (button, event) {
this.Save('2');
},
scope: this
},
'-',
{
text: Zi.LAN.btnCopyAndNew, //"复制新建",
handler: function (button, event) {
var basicForm = this.formEdit.getForm();
this.opStatus = 'add';
basicForm.findField('GID').setDisabled(false);
var field = basicForm.findField('GID');
field.setValue(NewGuid());
basicForm.findField('GID').setDisabled(true);
field = basicForm.findField('CREATEUSERREF');
field.setValue('');
field = basicForm.findField('NAME');
field.setValue('');
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("TEMPLATEID", '*');
memberbody.commit();
};
},
scope: this
}
]
}); //end 按钮Toolbar
//#endregion
//#region 明细表
//明细表表格相关
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsCodeFeeTemplateAgentDetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/MvcShipping/MsCodeFeeTemplateAgent/GetBodyList',
reader: {
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.storeFeeNameRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.FeeTypeRefModel',
proxy: { url: '/MvcShipping/MsChFee/GetFeeTypeRefList' }
});
this.storeFeeNameRef.load({ params: { condition: ""} });
this.comboxFeeNameRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeFeeNameRef,
forceSelection: true,
name: 'FEENAME',
valueField: 'Name',
displayField: 'CodeAndName'
});
this.StoreCurr = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsFeeCurr',
proxy: { url: '/MvcShipping/MsChFee/GetFeeCurrList' }
});
this.StoreCurr.load({ params: { condition: ""} });
this.comboxCurr = Ext.create('DsExt.ux.RefTableCombox', {
store: this.StoreCurr,
forceSelection: true,
name: 'CURRENCY',
valueField: 'CURR',
displayField: 'CURR'
});
this.storeFeeUnit = Ext.create('DsExt.ux.RefTableStore', {
fields: ['UNIT'],
proxy: { url: '/MvcShipping/MsCodeFeeTemplate/GetFeeUnit' }
});
this.storeFeeUnit.load({ params: { condition: ""} });
this.comboxFeeUnit = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeFeeUnit,
forceSelection: true,
name: 'UNIT',
valueField: 'UNIT',
displayField: 'UNIT'
});
this.storeIsExChange = Ext.create('Ext.data.Store', {
fields: ['DC', 'NAME']
});
this.storeIsExChange.add({ "DC": 0, "NAME": "根据汇率设置" });
this.comboxIsExChange = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeIsExChange,
valueField: 'DC',
displayField: 'NAME',
// forceSelection: true,
name: 'EXCHANGERATE'
});
this.gridList = new Ext.grid.GridPanel({
store: this.storeBodyList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: Zi.LAN.ShuJuJiaZaiZhong },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridListCellEditing],
selType: 'cellmodel',
tbar: [{
text: Zi.LAN.btnAddDetail, //'增加费用明细',
tooltip: Zi.LAN.btnAddDetail, //'增加费用明细',
iconCls: "btnadddetail",
handler: function (button, event) {
this.onAddDetailClick(button, event, 1);
},
scope: this
}, '-', {
text: Zi.LAN.btnDeleteDetail, //'删除费用明细',
tooltip: Zi.LAN.btnDeleteDetail, //'删除费用明细',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onDelDetailClick(button, event, 1);
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'GID',
header: Zi.LAN.GID, //'GID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'TEMPLATEID',
header: Zi.LAN.TEMPLATEID, //'TEMPLATEID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'FEENAME',
header: Zi.LAN.FEENAME, //'费用名称',
editor: this.comboxFeeNameRef,
width: 140
}, {
sortable: true,
dataIndex: 'FEEENAME',
header: '费用英文名', //'备注',
editor: {
xtype: 'textfield',
selectOnFocus: true,
enableKeyEvents: true
},
width: 150
}, {
sortable: true,
dataIndex: 'CURRENCY',
header: Zi.LAN.CURRENCY, //'币别',
editor: this.comboxCurr,
width: 100
}, {
sortable: true,
dataIndex: 'EXCHANGERATE',
header: Zi.LAN.EXCHANGERATE, //'汇率',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
selectOnFocus: true,
hideTrigger: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
align: 'right',
width: 180
}, {
dataIndex: 'DRPP',
header: '应收PP', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
dataIndex: 'DRCC',
header: '应收CC', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
dataIndex: 'CRPP',
header: '应付PP', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
dataIndex: 'CRCC',
header: '应付CC', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
dataIndex: 'AMOUNTDR',
header: '应收金额', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
dataIndex: 'AMOUNTCR',
header: '应付金额', //'箱量',
width: 100,
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
}
}, {
sortable: true,
dataIndex: 'UNIT',
header: Zi.LAN.UNIT, //'标准',
editor: this.comboxFeeUnit,
width: 80
}, {
sortable: true,
dataIndex: 'UNITPRICE',
header: Zi.LAN.UNITPRICE, //'单价',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
selectOnFocus: true,
hideTrigger: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
align: 'right',
width: 80
}, {
sortable: true,
dataIndex: 'QUANTITY',
header:'数量', //'单价',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
selectOnFocus: true,
hideTrigger: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
align: 'right',
width: 80
}, {
sortable: true,
dataIndex: 'SORT',
header: Zi.LAN.SORT, //'排序',
editor: {
xtype: 'numberfield',
keyNavEnabled: false,
selectOnFocus: true,
hideTrigger: true,
mouseWheelEnabled: false,
enableKeyEvents: true
},
align: 'right',
width: 80
}, {
sortable: true,
dataIndex: 'FEEDESCRIPTION',
header: Zi.LAN.FEEDESCRIPTION, //'备注',
editor: {
xtype: 'textfield',
selectOnFocus: true,
enableKeyEvents: true
},
width: 150
}
]
});
this.panelService = new Ext.Panel({
title: Zi.LAN.FeeField, //'费用字段',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridList]
});
this.paneldetail = new Ext.Panel({
layout: "border",
region: "center",
items: [
this.panelService
]
});
//#endregion 明细表
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 140,
items: [this.panelBtn, this.formEdit]
});
Ext.apply(this, {
items: [this.panelTop, this.paneldetail]
});
//#endregion
//绑定查询窗体
//初始化数据
if (this.feeaddtemplate == undefined) {
this.ParentWin = window.parent.opener;
this.InitData();
} else {
this.opStatus = 'add';
this.parentWin = window.parent.opener._thisfee;
if (this.parentWin) {
this.feeType = this.parentWin.feeType;
if (this.feeType == 1) {
this.StoreFee = this.parentWin.storeDrChFee;
} else if (this.feeType == 2) {
this.StoreFee = this.parentWin.storeCrChFee;
}
this.stroplb = this.parentWin.stroplb;
this.formEdit.getForm().findField('FEETYPE').setValue(this.feeType);
var myDate = new Date();
var mydatestr = Ext.util.Format.date(myDate, 'Y-m-d');
this.formEdit.getForm().findField('CREATETIME').setValue(mydatestr);
this.formEdit.getForm().findField('CREATEUSERREF').setValue(SHOWNAME);
var GID=NewGuid();
this.formEdit.getForm().findField('GID').setValue(GID);
this.formEdit.getForm().findField('ISPUBLIC').setValue('否');
if (this.stroplb == 'op_Seae') {
this.formEdit.getForm().findField('OPTYPE').setValue(1);
} else if (this.stroplb == 'op_Seai') {
this.formEdit.getForm().findField('OPTYPE').setValue(2);
} else if (this.stroplb == 'op_Aire') {
this.formEdit.getForm().findField('OPTYPE').setValue(3);
} else if (this.stroplb == 'op_Airi') {
this.formEdit.getForm().findField('OPTYPE').setValue(7);
} else if (this.stroplb == 'op_Apply') {
this.formEdit.getForm().findField('OPTYPE').setValue(4);
} else if (this.stroplb == 'op_Bulk') {
this.formEdit.getForm().findField('OPTYPE').setValue(5);
} else if (this.stroplb == 'op_other') {
this.formEdit.getForm().findField('OPTYPE').setValue(6);
}
for (i = 0; i < this.StoreFee.getCount(); i += 1) {
var memberyf = this.StoreFee.getAt(i);
var newSerialno = this.GetHandleSerialNo(this.storeBodyList);
var CustomerType = memberyf.data.CustomerType;
var records = DsStoreQueryBy(this.storeCustType, 'NAME', CustomerType);
var CLIENT = '';
if (records.getCount() > 0) {
var data = records.getAt(0).data;
CLIENT = data.CLIENT;
}
var Currency = memberyf.data.Currency;
var ExChangerate = 0;
if (Currency == 'RMB') ExChangerate = 1;
var record = Ext.create('MsCodeFeeTemplateDetail', {
GID: '',
TEMPLATEID: '',
FEENAME: memberyf.data.FeeName,
CUSTOMERNAME: memberyf.data.CustomerName,
CLIENT: CLIENT,
CLIENTREF: CustomerType,
UNIT: memberyf.data.Unit,
CURRENCY: memberyf.data.Currency,
UNITPRICE: memberyf.data.UnitPrice,
SORT: newSerialno,
EXCHANGERATE: ExChangerate,
CREATEUSER: "",
REMARK: memberyf.data.Remark,
FEEFRT: memberyf.data.FeeFrt,
SALECORP: memberyf.data.SALECORP,
TAXRATE: memberyf.data.TaxRate,
ISCTN: false,
ISCTNREF: "否"
});
this.storeBodyList.add(record);
}
}
}
//绑定事件
this.gridList.on('edit', function (editor, e, eOpts) {
this.gridAfterEdit(editor, e, eOpts);
}, this);
this.storeBodyList.on('beforeload', function (store) {
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
var sql = " TEMPLATEID='" + cargoid + "'";
Ext.apply(store.proxy.extraParams, { condition: sql });
}, 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 = " GID='" + this.editRecord.get('GID') + "'";
this.LoadData(this.opStatus, condition);
}, //end InitData
LoadData: function (opstatus, condition) {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: Zi.LAN.ZhengZaiChaXunShuJu, //'正在查询主表数据...',
url: '/MvcShipping/MsCodeFeeTemplateAgent/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: Zi.LAN.TiShi, //'提示',
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(Zi.LAN.FuWuQiXiangYingChuCuo, response.responseText);
}
},
scope: this
});
var billno = '*';
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('GID');
}
this.storeBodyList.load({ params: { condition: " TEMPLATEID='" + cargoid + "'"} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
//判断表格数据是否合法
if (!validateEditorGridPanel(this.gridList)) {
return;
}
basicForm.findField('GID').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('GID').setDisabled(true);
if (this.opStatus == 'add') {
data.DM_ID = NewGuid();
}
var bodydatas = [];
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
var member = this.storeBodyList.getAt(i);
bodydatas.push(member);
}
var jsonBody = ConvertRecordsToJsonAll(bodydatas);
Ext.Msg.wait(Zi.LAN.ZhengZaiCaoZuoShuJu);
Ext.Ajax.request({
waitMsg: Zi.LAN.ZhengZaiCaoZuoShuJu, //'正在保存数据...',
url: '/MvcShipping/MsCodeFeeTemplateAgent/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') {
if (this.feeaddtemplate == undefined) {
} else {
var arrNewRecords = this.StoreList.add(returnData);
this.editRecord = arrNewRecords[0];
}
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('MsCodeFeeTemplateAgent', 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('GID').setDisabled(true);
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("GID", this.editRecord.get('GID'));
memberbody.commit();
};
} else if (type == '1') {
window.close();
} else {
this.LoadData('add', '');
basicForm.findField('GID').setDisabled(false);
}
} else {
Ext.Msg.show({ title: Zi.LAN.CuoWu, msg: jsonresult.Message, icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
}
} else {
Ext.Msg.show({ title: Zi.LAN.TiShi,
msg: Zi.LAN.FuWuQiXiangYingChuCuo,
icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK
});
}
}
});
}, //end save
onAddDetailClick: function (button, event, type) {
this.addDetail(type);
}, //end onAddDetailClick
onDelDetailClick: function (button, event, type) {
this.deleteDetail(type);
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
if (e.value == e.originalValue) return;
else if (e.field == 'FEENAME') {
var records = DsStoreQueryBy(this.storeFeeNameRef, 'Name', e.value);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
var ENAME = data.Description;
e.record.set('FEEENAME', ENAME);
}
}
else if (e.field == 'UNITPRICE' || e.field == 'QUANTITY') {
var UNITPRICE = e.record.data['UNITPRICE'];
var QUANTITY = e.record.data['QUANTITY'];
var amount = Mul(UNITPRICE, QUANTITY);
e.record.set('AMOUNTDR', amount);
}
},
addDetail: function (type) {
var newSerialno = 0;
store = this.storeBodyList;
var newSerialno = this.GetHandleSerialNo(store);
var record = Ext.create('MsCodeFeeTemplateAgentDetail', {
GID: NewGuid(),
TEMPLATEID: '*',
FEENAME: "",
FEEENAME: "",
CURRENCY: "USD",
EXCHANGERATE: 1,
DRPP: 0,
DRCC: 0,
CRPP: 0,
CRCC: 0,
AMOUNTDR: 0,
AMOUNTCR: 0,
UNITPRICE: 0,
UNIT: "单票",
QUANTITY: 0,
SORT: newSerialno,
FEEDESCRIPTION: "",
CREATEUSER: "",
REMARK: ""
});
store.add(record);
this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 1 });
},
GetHandleSerialNo: function (store) {
var result = 0;
if (result == 0) {
for (var i = 0; i < store.getCount(); i += 1) {
var member = store.getAt(i);
if (parseInt(member.data.SORT) > parseInt(result)) {
result = member.data.SORT;
}
}
}
result = parseInt(result) + 1;
return result;
},
deleteDetail: function (type) {
var selectedRecords = this.gridList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
this.storeBodyList.remove(rec);
}
}
});