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/Import/Viewsjs/cargoinfo/cargoinfoEdit.js

470 lines
15 KiB
JavaScript

Ext.namespace('DsTruck');
DsTruck.CargoinfoEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.CargoinfoEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.CargoinfoEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑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: [ {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [
{
fieldLabel: 'ID',
name: 'ID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '商品HS编码',
allowBlank: false, flex: 1,
selectOnFocus: true,
name: 'Code'
}, {
fieldLabel: '商品HS名称',
allowBlank: false, flex: 2,
selectOnFocus: true,
name: 'Name'
}, {
fieldLabel: '管理方式',
allowBlank: false, flex: 1,
selectOnFocus: true,
name: 'JG'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [
{
fieldLabel: '最惠国税率(%)',
flex: 1,
xtype: 'numberfield',
allowBlank: false,
selectOnFocus:true,
name: 'Tax_Zhg'
}, {
fieldLabel: '普通税率(%)',
xtype: 'numberfield',
allowBlank: false,
allowDecimals: true,
decimalPrecision: 4,
selectOnFocus: true,
name: 'Tax_Pt'
}, {
fieldLabel: '增值税(%)',
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true,
name: 'Tax_Zz'
}, {
labelWidth: 100,
fieldLabel: '从量税率(分/kg)',
tooltip: '如从量税率不为零,则关税按照此标准(分/kg),而非关税税率进行计算',
xtype: 'numberfield',
allowBlank: false,
decimalPrecision: 2,
selectOnFocus: true,
name: 'Tax_Cl'
}
]
}
]//end items(fieldset 1)
}); //end this.formEdit
//#endregion
//#region 按钮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
//#endregion
//#region 明细表
//明细表表格相关
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'Import_cargociq',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/Import/cargoinfo/GetBodyList',
reader: {
id: 'ID,Code,CiqCode',
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: 'ID',
header: 'ID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'CargoinfoID',
header: '商品HS编码ID',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'CargoinfoCode',
header: '商品HS编码',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'CiqCode',
header: 'CIQ编码',
editor: {
xtype: 'textfield',
allowBlank: false,
selectOnFocus: true
},
width: 120
}, {
sortable: true,
dataIndex: 'CiqName',
header: 'CIQ名称',
editor: {
xtype: 'textfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}
]
});
//#endregion 明细表
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 100,
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 = " ID=" + this.editRecord.get('ID');
this.LoadData(this.opStatus, condition);
}, //end InitData
LoadData: function (opstatus, condition) {
this.serialNo = 0;
this.bodyDel = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/Import/cargoinfo/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 = '*';
var cargoid = 0;
if (this.opStatus == 'edit') {
cargoid = this.editRecord.get('ID');
//this.formEdit.getForm().findField('Code').setDisabled(true);
//this.formEdit.getForm().findField('Code').setReadOnly(true);
//this.formEdit.getForm().findField('Name').setDisabled(true);
//this.formEdit.getForm().findField('Name').setReadOnly(true);
}
this.storeBodyList.load({ params: { cargoid: cargoid} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
//basicForm.findField('Code').setDisabled(false);
var data = basicForm.getValues();
//basicForm.findField('Code').setDisabled(true);
var bodydatas = [];
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
var member = this.storeBodyList.getAt(i);
bodydatas.push(member);
}
var CIQBody = ConvertRecordsToJsonAll(bodydatas);
var CIQDELbody = ConvertRecordsToJsonAll(this.bodyDel);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/Import/cargoinfo/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
CIQbody: CIQBody,
CIQDELbody: CIQDELbody
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
this.storeBodyList.commitChanges();
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('Import_cargoinfo', 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('ID').setDisabled(true);
for (var j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("CargoinfoID", this.editRecord.get('ID'));
memberbody.commit();
};
} else if (type == '1') {
window.close();
} else {
this.LoadData('add', '');
//basicForm.findField('ID').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) {
//需要自己实现里面的事件
},
addDetail: function () {
var code = this.editRecord.get('Code');
var record = Ext.create('Import_cargociq', {
ID: "",
CargoinfoID: "",
CargoinfoCode: code,
CiqCode: "",
CiqName: ""
});
this.storeBodyList.add(record);
var n = this.storeBodyList.getCount();
this.gridListCellEditing.startEditByPosition({ row: n - 1, column: 2 });
},
deleteDetail: function () {
var selectedRecords = this.gridList.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
this.storeBodyList.remove(rec);
}
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
// alert(rec.ContractNo);
if (rec.CargoinfoID != "" || rec.CargoinfoID != "*") //如果是新增但没有保存的数据,没有必要提交到后台
{
this.bodyDel.push(rec);
}
//alert(i);
this.storeBodyList.remove(selectedRecords[i]);
}
}
});