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/Account/Viewsjs/Chfee_invoice/ChInvoiceBookEdit.js

700 lines
24 KiB
JavaScript

2 years ago
Ext.namespace('Shipping');
Shipping.MsInvoiceBookEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.Shipping.MsInvoiceBookEdit.superclass.constructor.call(this);
};
Ext.extend(Shipping.MsInvoiceBookEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.workSerialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
this.storeInvCategory = Ext.create('Ext.data.Store', {
fields: ['FSTATUS', 'NAME']
});
this.storeInvCategory.add({ "FSTATUS": "0", "NAME": "普通发票" });
this.storeInvCategory.add({ "FSTATUS": "1", "NAME": "专用发票" });
this.storeInvCategory.add({ "FSTATUS": "2", "NAME": "电子票" });
this.comboxInvCategory = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '发票类型',
store: this.storeInvCategory,
forceSelection: true,
name: 'TYPE',
valueField: 'FSTATUS',
displayField: 'NAME'
});
this.storeOpCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsShipping.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserLinkRefListRm' }
});
this.storeOpCode.load();
this.comboxOP = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '默认使用人', //'操 作',
store: this.storeOpCode,
forceSelection: true,
queryMode: 'remote',
minChars: 0,
queryParam: 'CODENAME',
name: 'DEFUSER',
valueField: 'GID',
displayField: 'CodeAndName'
});
//表参照相关(编辑form)
_this = this;
//编辑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: 'GID',
name: 'GID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: 'CREATEUSER',
name: 'CREATEUSER', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: 'COMPANYID',
name: 'COMPANYID', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '票册名称',
name: 'NAME'
}, {
fieldLabel: '票册描述',
name: 'DESCRIPTION'
}, this.comboxInvCategory, this.comboxOP
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '发票代码号',
name: 'INVOICECODE'
}, {
fieldLabel: '票册开始号',
name: 'INVOICENUMSTART'
}, {
fieldLabel: '票册结束号',
name: 'INVOICENUMEND',
listeners: {
change: function () {
var basicForm = _this.formEdit.getForm();
var STARTDATE = parseInt(basicForm.findField('INVOICENUMSTART').getValue());
var newValue = parseInt(basicForm.findField('INVOICENUMEND').getValue());
var chenum = newValue - STARTDATE + 1;
basicForm.findField('INVOICETOTAL').setValue(chenum);
}
}
}, {
fieldLabel: '发票总数',
readOnly: true,
name: 'INVOICETOTAL'
}]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '创建人',
readOnly: true,
name: 'CREATEUSERREF'
}, {
fieldLabel: '创建时间',
readOnly: true,
name: 'CREATETIME'
}, {
fieldLabel: '是否锁定',
readOnly: true,
name: 'ISLOCK'
}, {
fieldLabel: '是否作废',
readOnly: true,
name: 'ISDELETE'
}]
}
]//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: "保存",
id: 'btnsave',
iconCls: "btnsave",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
text: "保存并关闭",
id: 'btnsaveandclose',
handler: function (button, event) {
this.Save('1');
},
scope: this
},
'-',
{
text: "保存并新建",
id: 'btnsaveandnew',
handler: function (button, event) {
this.Save('2');
},
scope: this
}, '-',
{
text: "生成",
id: 'btncreateitems',
handler: function (button, event) {
this.Save('3');
// this.CreateItems();
},
scope: this
}
]
}); //end 按钮Toolbar
//#endregion
//#region 明细表
//明细表表格相关
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'ChInvoiceBookdetail',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/Account/Chfee_invoice/GetBookitemsDataList',
reader: {
id: 'GID',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridListCellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.GridCheckBoxModel = Ext.create('Ext.selection.CheckboxModel');
this.gridList = new Ext.grid.GridPanel({
store: this.storeBodyList,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridListCellEditing],
selModel: this.GridCheckBoxModel,
selType: 'cellmodel',
tbar: [
//
// {
// text: '增加明细',
// tooltip: '增加明细',
// iconCls: "btnadddetail",
// handler: function (button, event) {
// this.onAddDetailClick(button, event, 1);
// },
// scope: this
// }, '-',
{
text: '锁定',
tooltip: '锁定',
iconCls: "btndeletedetail",
handler: function (button, event) {
this.onLockDetailClick(button, event);
},
scope: this
}, {
text: '取消锁定',
tooltip: '取消锁定',
iconCls: "btnreset",
handler: function (button, event) {
this.CancelLockDetail();
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'GID',
header: 'GID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'BOOKID',
header: 'BOOKID',
hidden: true,
width: 100
}, {
sortable: true,
dataIndex: 'INVOICENUM',
header: '发票号',
width: 160
}, {
sortable: true,
dataIndex: 'ISMAKEOUT',
header: '是否开出',
width: 160
}, {
sortable: true,
dataIndex: 'ISLOCK',
header: '是否锁定',
width: 160
}, {
sortable: true,
dataIndex: 'ISDELETE',
header: '是否作废',
width: 160
}
]
});
this.panelService = new Ext.Panel({
title: '发票号明细',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridList]
});
//#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.panelService]
});
//#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 = " 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 = this;
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询明细数据...',
url: '/Account/Chfee_invoice/GetBookData',
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('GID');
}
var canedit = true;
this.storeBodyList.load({ params: { condition: " BOOKID='" + cargoid + "'" },
callback: function (r, options, success) {
if (success) {
if (r.length != 0) {
canedit = false;
} else { canedit = true; }
_this.setSaveBtnStatus(canedit);
}
}
});
}, // 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.GID = '*';
}
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/Account/Chfee_invoice/SaveBook',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data)
},
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('MsChInvoiceBook', 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);
} else if (type == '1') {
window.close();
} else if (type == '3') {
this.CreateItems();
} else {
this.LoadData('add', '');
basicForm.findField('GID').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
CreateItems: function () {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
basicForm.findField('GID').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('GID').setDisabled(true);
var GID = basicForm.findField('GID').getValue();
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/Account/Chfee_invoice/CreateBookitems',
scope: this,
params: {
data: Ext.JSON.encode(data)
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
this.storeBodyList.load({ params: { condition: " BOOKID='" + GID + "'"} });
} 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, type) {
this.addDetail(type);
}, //end onAddDetailClick
onLockDetailClick: function (button, event) {
this.LockDetail();
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
},
LockDetail: function () {
var selectedRecords = this.gridList.selModel.getSelection();
if (selectedRecords.length == 0) {
Ext.Msg.show({ title: '提示', msg: '没有选择要锁定的支票!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
return;
};
var bodyAddDatas = [];
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
if (rec.data.ISMAKEOUT != '是' && rec.data.ISDELETE != '是') {
bodyAddDatas.push(rec);
}
}
_this = this;
var jsonbodyAddDatas = ConvertRecordsToJsonAll(bodyAddDatas);
Ext.MessageBox.confirm('提示', '确定要锁定该记录吗?', function (btn) {
if (btn == 'yes') {
Ext.Msg.wait('正在锁定数据...');
Ext.Ajax.request({
waitMsg: '正在锁定数据...',
url: '/Account/Chfee_invoice/LockBookitems',
params: {
data: jsonbodyAddDatas
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var cargoid = this.editRecord.get('GID');
this.storeBodyList.load({ params: { condition: " BOOKID='" + cargoid + "'"} });
Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, 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.INFO, buttons: Ext.Msg.OK });
},
scope: this
}); //end Ext.Ajax.request
}
}, this);
},
CancelLockDetail: function () {
var selectedRecords = this.gridList.selModel.getSelection();
if (selectedRecords.length == 0) {
Ext.Msg.show({ title: '提示', msg: '没有选择要取消锁定的支票!', icon: Ext.Msg.INFO, buttons: Ext.Msg.OK });
return;
};
var bodyAddDatas = [];
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
if (rec.data.ISLOCK == '是') {
bodyAddDatas.push(rec);
}
}
_this = this;
var jsonbodyAddDatas = ConvertRecordsToJsonAll(bodyAddDatas);
Ext.MessageBox.confirm('提示', '确定要取消锁定该记录吗?', function (btn) {
if (btn == 'yes') {
Ext.Msg.wait('正在取消锁定数据...');
Ext.Ajax.request({
waitMsg: '正在取消锁定数据...',
url: '/Account/Chfee_invoice/CancelLockBookitems',
params: {
data: jsonbodyAddDatas
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
var cargoid = this.editRecord.get('GID');
this.storeBodyList.load({ params: { condition: " BOOKID='" + cargoid + "'"} });
Ext.Msg.show({ title: '提示', msg: jsonresult.Message, icon: Ext.Msg.INFO, 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.INFO, buttons: Ext.Msg.OK });
},
scope: this
}); //end Ext.Ajax.request
}
}, this);
},
setSaveBtnStatus: function (enable) {
var btnESave = Ext.getCmp('btnsave');
var btnESaveAndClose = Ext.getCmp('btnsaveandclose');
var btnESaveAndNew = Ext.getCmp('btnsaveandnew');
var btncreateitems = Ext.getCmp('btncreateitems');
var basicForm = this.formEdit.getForm();
basicForm.findField('INVOICENUMSTART').setReadOnly(true);
if (enable) {
basicForm.findField('INVOICENUMSTART').setReadOnly(false);
basicForm.findField('INVOICENUMEND').setReadOnly(false);
basicForm.findField('INVOICETOTAL').setReadOnly(false);
// btnESave.enable();
// btnESaveAndClose.enable();
// btnESaveAndNew.enable();
btncreateitems.enable();
} else {
basicForm.findField('INVOICENUMSTART').setReadOnly(true);
basicForm.findField('INVOICENUMEND').setReadOnly(true);
basicForm.findField('INVOICETOTAL').setReadOnly(true);
// btnESave.disable();
// btnESaveAndClose.disable();
// btnESaveAndNew.disable();
btncreateitems.disable();
}
}
});