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/KfCg/KfCgEdit.js

595 lines
20 KiB
JavaScript

2 years ago
Ext.namespace('DsTruck');
DsTruck.MsKfCgEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsKfCgEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.MsKfCgEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.bodyDel = [];
//#region 编辑form
//枚举参照相关(编辑form)
this.storePluType = Ext.create('DsExt.ux.RefEnumStore', {});
this.storePluType.load({ params: { enumTypeId: 99003} });
this.comboxPluType = Ext.create('DsExt.ux.RefEnumCombox', {
fieldLabel: '配件类型',
store: this.storePluType,
name: 'PluType'
});
//表参照相关(编辑form)
this.storeOrgCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsKfCgHeadMsTruckOrg',
proxy: { url: '/TruckMng/MsKfCg/GetOrgCodeList' }
});
this.storeOrgCode.load({ params: { condition: ""} });
this.comboxOrgCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '组织编码',
store: this.storeOrgCode,
name: 'OrgCode',
valueField: 'OrgCode',
displayField: 'CodeAndName'
});
this.storeCkCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsKfCgHeadMsTruckOrg',
proxy: { url: '/TruckMng/MsKfCg/GetCkCodeList' }
});
this.storeCkCode.load({ params: { condition: ""} });
this.comboxCkCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '仓库编码',
store: this.storeCkCode,
name: 'CkCode',
valueField: 'OrgCode',
displayField: 'CodeAndName'
});
this.storeCgyCode = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeCgyCode.load({ params: { condition: ""} });
this.comboxCgyCode = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '申领人编码',
store: this.storeCgyCode,
name: 'CgyCode',
valueField: 'UserCode',
displayField: 'CodeAndName'
});
//编辑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: '录入日期',
name: 'LrDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '记账日期',
name: 'JzDate', 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: 'TimeMark', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '组织名称',
name: 'OrgName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '仓库名称',
name: 'CkName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '申领人姓名',
name: 'CgyName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '申领金额',
name: 'CgTotal', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '实到数量',
name: 'SdCount', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '执行标志',
name: 'ZxFlag', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
disabled: true,
name: 'BillNo'
}, this.comboxOrgCode, this.comboxCkCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [this.comboxPluType, {
fieldLabel: '申领日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'CgDate'
}, this.comboxCgyCode
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '申领数量',
xtype: 'numberfield',
allowBlank: false,
name: 'CgCount'
}, {
fieldLabel: '备注',
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: "保存",
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.storePluCodeRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.PluRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetPluRefList' }
});
this.storePluCodeRef.load({ params: { condition: ""} });
this.comboxPluCodeRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storePluCodeRef,
name: 'PluCode',
valueField: 'PluCode',
displayField: 'CodeAndName'
});
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsKfCgBody',
remoteSort: true,
proxy: {
type: 'ajax',
url: '/TruckMng/MsKfCg/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,
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: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'SerialNo',
header: '序号',
width: 160
}, {
sortable: true,
dataIndex: 'PluCode',
header: '配件编码',
renderer: function (value, p, record) {
if (value == null || value == '')
return '';
else
return value + '-' + record.data.PluCode_Ref;
},
editor: this.comboxPluCodeRef,
width: 120
}, {
sortable: true,
dataIndex: 'PluName',
header: '配件名称',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Spec',
header: '规格',
width: 160
}, {
sortable: true,
dataIndex: 'Unit',
header: '单位',
width: 60
}, {
sortable: true,
dataIndex: 'Price',
header: '单价',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'CgCount',
header: '申领数量',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'CgTotal',
header: '申领金额',
width: 160
}, {
sortable: true,
dataIndex: 'SdCount',
header: '实到数量',
hidden: true,
width: 160
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 200
}
]
});
//#endregion 明细表
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 120,
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 = " 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/MsKfCg/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.storeBodyList.load({ params: { billno: billno} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
//判断表格数据是否合法
if (!validateEditorGridPanel(this.gridList)) {
return;
}
basicForm.findField('BillNo').setDisabled(false);
var data = basicForm.getValues();
basicForm.findField('BillNo').setDisabled(true);
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 jsonDelBody = ConvertRecordsToJsonAll(this.bodyDel);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsKfCg/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody,
delbody: jsonDelBody
},
callback: function (options, success, response) {
if (success) {
Ext.MessageBox.hide();
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) {
if (this.opStatus == 'add') {
var p = Ext.create('MsKfCgHead', data); // Ext.create('MsKfCgHead', data, NewGuid()); //或者new MsKfCgHead(data, NewGuid());
this.storeList.add(p);
this.editRecord = p;
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('MsKfCgHead', jsonresult.Data);
this.formEdit.getForm().reset();
this.formEdit.getForm().setValues(jsonresult.Data);
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.set("BillNo", this.editRecord.get('BillNo'));
memberbody.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) {
this.addDetail();
}, //end onAddDetailClick
onDelDetailClick: function (button, event) {
this.deleteDetail();
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
},
addDetail: function () {
var newSerialno = DsGetNewSerialNo(this.storeBodyList, this.serialNo);
this.serialNo = newSerialno;
var record = Ext.create('MsKfCgBody', {
BillNo: '*',
SerialNo: newSerialno,
PluCode: '',
PluCode_Ref: '',
PluName: '',
Spec: '',
Unit: '',
Price: 0,
CgCount: 0,
CgTotal: 0,
SdCount: 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]);
}
}
});