DS7/DSWeb/Areas/TruckMng/Viewsjs/MsKfWx/MsKfWxEdit.js

1305 lines
46 KiB
JavaScript

Ext.namespace('DsTruck');
DsTruck.MsKfWxEdit = function (config) {
Ext.applyIf(this, config);
this.initUIComponents();
window.DsTruck.MsKfWxEdit.superclass.constructor.call(this);
};
Ext.extend(DsTruck.MsKfWxEdit, Ext.Panel, {
ParentWin: null,
OpStatus: 'add',
StoreList: null,
EditRecord: null,
initUIComponents: function () {
this.serialNo = 0;
this.bodyDel = [];
this.jxcount = 0;
this.serialNoPlu = 0;
this.bodyDelPlu = [];
//#region 编辑form
//枚举参照相关(编辑form)
//表参照相关(编辑form)
this.storeTruckNo = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsKfWxHeadRefMsWlTruck',
proxy: { url: '/TruckMng/MsKfWx/GetTruckNoList' }
});
this.storeTruckNo.load({ params: { condition: ""} });
this.comboxTruckNo = Ext.create('DsExt.ux.RefTableCombox', {
fieldLabel: '车牌号',
store: this.storeTruckNo,
name: 'TruckNo',
valueField: 'TruckNo',
displayField: 'TruckSpec'
});
//编辑form
this.formEdit = Ext.widget('form', {
region: 'center', id: "formEdit",
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: 'OrgCode', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '组织名称',
name: 'OrgName', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '计划完成日期',
name: 'PlanEndDate', flex: 0, hidden: true, margins: '0'
}, {
fieldLabel: '单据号',
allowBlank: false,
disabled: true,
name: 'BillNo'
}, this.comboxTruckNo, {
fieldLabel: '派工日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'PgDate'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '工作开始日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'GzBgnDate',
listeners: {
//添加日期选择事件
"change": function () {
var form = Ext.getCmp("formEdit");
if (form.getForm().findField('GzEndDate').getRawValue() != "") {
var startdate = form.getForm().findField('GzBgnDate').getRawValue();
var enddate = form.getForm().findField('GzEndDate').getRawValue();
var _e = Ext.util.Format.date(startdate); //格式化日期控件值
var _s = Ext.util.Format.date(enddate); //格式化日期控件值
var end = new Date(_s);
var start = new Date(_e);
var elapsed = Math.round((end.getTime() - start.getTime()) / (86400000)) + 1; // 计算间隔日数
//e.record.set('text',_s);
form.getForm().findField('REPAIRDAYS').setValue(elapsed);
}
}
}
}, {
fieldLabel: '工作完成日期',
format: 'Y-m-d',
xtype: 'datefield',
name: 'GzEndDate',
listeners: {
//添加日期选择事件
"change": function () {
var form = Ext.getCmp("formEdit");
if (form.getForm().findField('GzBgnDate').getRawValue() != "") {
var startdate = form.getForm().findField('GzBgnDate').getRawValue();
var enddate = form.getForm().findField('GzEndDate').getRawValue();
var _e = Ext.util.Format.date(startdate); //格式化日期控件值
var _s = Ext.util.Format.date(enddate); //格式化日期控件值
var end = new Date(_s);
var start = new Date(_e);
var elapsed = Math.round((end.getTime() - start.getTime()) / (86400000)) + 1; // 计算间隔日数
//e.record.set('text',_s);
form.getForm().findField('REPAIRDAYS').setValue(elapsed);
}
}
}
}, {
fieldLabel: '已行驶里程',
xtype: 'numberfield',
allowBlank: false,
disabled: true,
name: 'RealMil'
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [{
fieldLabel: '备注',
name: 'Remark'
}
]
}
, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [
{
sortable: true,
xtype: 'monthfield',
format: 'Y-m',
fieldLabel: '会计期间',
allowBlank: false,
name: 'ACCDATE', flex: 1
}, {
sortable: true,
xtype: 'numberfield',
minValue: 0,
fieldLabel: '修理车日',
allowBlank: false,
name: 'REPAIRDAYS', flex: 1
}, {
sortable: true,
xtype: 'numberfield',
minValue: 0,
fieldLabel: '总维修金额',
allowBlank: false, id: "REPAIRAMOUNT", readOnly: true,
name: 'REPAIRAMOUNT', flex: 1
}
]
}, {
xtype: 'container',
layout: 'hbox',
defaultType: 'textfield',
items: [
{
sortable: true,
xtype: 'numberfield',
minValue: 0,
fieldLabel: '工时费',
allowBlank: false, id: "WORKAMOUNT", readOnly: true,
name: 'WORKAMOUNT', flex: 1
}, {
sortable: true,
xtype: 'numberfield',
minValue: 0,
fieldLabel: '工料费',
allowBlank: false, id: "MATERIALAMOUNT", readOnly: true,
name: 'MATERIALAMOUNT', flex: 1
}, {
sortable: true,
xtype: 'numberfield',
minValue: 0,
fieldLabel: '轮胎费',
allowBlank: false, id: "TYREAMOUNT", readOnly: true,
name: 'TYREAMOUNT', flex: 1
}
]
}
]//end items(fieldset 1)
}//end fieldset 1
]//end root items
}); //end this.formEdit
//#endregion
//#region 按钮Toolbar
this.panelBtn = new Ext.Panel({
region: "north",
tbar: [
{
id: 'btnESave',
text: "保存",
iconCls: "btnsave",
handler: function (button, event) {
this.Save('0');
},
scope: this
},
{
id: 'btnESaveAndClose',
text: "保存并关闭",
handler: function (button, event) {
this.Save('1');
},
scope: this
},
'-',
{
id: 'btnESaveAndNew',
text: "保存并新建",
handler: function (button, event) {
this.Save('2');
},
scope: this
},
'-',
{
text: "关闭",
handler: function (button, event) {
window.close();
},
scope: this
},
{
text: "新建",
handler: function (button, event) {
this.LoadData('add', '');
var basicForm = this.formEdit.getForm();
basicForm.findField('BillNo').setDisabled(false);
},
scope: this
},
'-',
{
id: 'btnEAccount',
text: "记账",
handler: function (button, event) {
this.onAccountClick(button, event);
},
scope: this
},
'-',
{
text: "打印",
iconCls: "btnprint",
handler: function (button, event) {
this.Print();
},
scope: this
}
]
}); //end 按钮Toolbar
//#endregion
//#region 明细表
//明细表表格相关
this.storeWxLxCodeRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'MsKfWxBodyRefMsKfBzWx',
proxy: { url: '/TruckMng/MsKfWx/GetWxLxCodeList' }
});
this.storeWxLxCodeRef.load({ params: { condition: ""} });
this.comboxWxLxCodeRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeWxLxCodeRef,
name: 'WxLxCode',
valueField: 'WxLxCode',
displayField: 'WxLxName'
});
this.storeSkillUserRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeSkillUserRef.load({ params: { condition: ""} });
this.comboxSkillUserRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeSkillUserRef,
name: 'SkillUser',
valueField: 'UserCode',
displayField: 'CodeAndName'
});
this.storeKfWxUserRef = Ext.create('DsExt.ux.RefTableStore', {
model: 'DsTruckMng.ux.UserRefModel',
proxy: { url: '/CommMng/BasicDataRef/GetUserRefList' }
});
this.storeKfWxUserRef.load({ params: { condition: ""} });
this.comboxKfWxUserRef = Ext.create('DsExt.ux.RefTableCombox', {
store: this.storeKfWxUserRef,
name: 'KfWxUser',
valueField: 'UserCode',
displayField: 'CodeAndName'
});
//明细表-数据集
this.storeBodyList = Ext.create('Ext.data.Store', {
model: 'MsKfWxBody',
remoteSort: false,
proxy: {
type: 'ajax',
url: '/TruckMng/MsKfWx/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, '0');
},
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
}, {
sortable: true,
dataIndex: 'SerialNo',
header: '录入序号',
width: 80
}, {
sortable: true,
dataIndex: 'WxLxCode',
header: '维修类型',
renderer: function (value, p, record) {
if (value == null || value == '')
return '';
else
return value + '-' + record.data.WxLxCode_Ref;
},
editor: this.comboxWxLxCodeRef,
width: 80
}, {
sortable: true,
dataIndex: 'WxItem',
header: '维修项目',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'QuotaHours',
header: '定额工时',
editor: {
xtype: 'numberfield',
selectOnFocus: true
},
width: 80
}, {
sortable: true,
dataIndex: 'RealHours',
header: '实际工时',
editor: {
xtype: 'numberfield',
selectOnFocus: true
},
width: 80
}, {
sortable: true,
dataIndex: 'SkillUser',
header: '技术员',
renderer: function (value, p, record) {
if (value == null || value == '')
return '';
else
return record.data.SkillUser_Ref; // value + '-' +
},
editor: this.comboxSkillUserRef,
width: 80
}, {
sortable: true,
dataIndex: 'KfWxUser',
header: '承修人',
renderer: function (value, p, record) {
if (value == null || value == '')
return '';
else
return record.data.KfWxUser_Ref; //value + '-' +
},
editor: this.comboxKfWxUserRef,
width: 80
}, {
sortable: true,
dataIndex: 'WORKAMOUNT',
header: '工时费',
editor: {
xtype: 'numberfield',
selectOnFocus: true
},
width: 60
}, {
sortable: true,
dataIndex: 'MATERIALAMOUNT',
header: '工料费',
editor: {
xtype: 'numberfield',
selectOnFocus: true
},
width: 60
}, {
sortable: true,
dataIndex: 'TYREAMOUNT',
header: '轮胎费',
editor: {
xtype: 'numberfield',
selectOnFocus: true
},
width: 60
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 200
}
]
});
//#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.storeBodyPlu = Ext.create('Ext.data.Store', {
model: 'MsKfWxPlu',
remoteSort: false,
proxy: {
type: 'ajax',
url: '/TruckMng/MsKfWx/GetWxPluList',
reader: {
id: '',
root: 'data',
totalProperty: 'totalCount'
}
}
});
//明细表表格
this.gridListCellEditingPlu = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this.gridListPlu = new Ext.grid.GridPanel({
store: this.storeBodyPlu,
enableHdMenu: false,
region: 'center',
loadMask: { msg: "数据加载中,请稍等..." },
trackMouseOver: true,
disableSelection: false,
plugins: [this.gridListCellEditingPlu],
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.onDelDetailClick(button, event, '1');
},
scope: this
}],
columns: [{
sortable: true,
dataIndex: 'BillNo',
header: '单据号',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'SerialNo',
header: '录入序号',
width: 100
}, {
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: '配件名称',
width: 160
}, {
sortable: true,
dataIndex: 'Spec',
header: '规格',
width: 160
}, {
sortable: true,
dataIndex: 'PcNo',
header: '轮胎串号',
hidden: true,
width: 120
}, {
sortable: true,
dataIndex: 'TyreType',
header: '轮胎类型',
hidden: true,
width: 80
}, {
sortable: true,
dataIndex: 'TyrePos',
header: '轮胎位置',
hidden: true,
width: 80
}, {
sortable: true,
dataIndex: 'Unit',
header: '单位',
width: 60
}, {
sortable: true,
dataIndex: 'Price', hidden: true,
header: '单价',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'LyCount',
header: '领用数量',
editor: {
xtype: 'numberfield',
allowBlank: false,
selectOnFocus: true
},
width: 160
}, {
sortable: true,
dataIndex: 'Remark',
header: '备注',
editor: {
xtype: 'textfield',
selectOnFocus: true
},
width: 200
}, {
sortable: true,
dataIndex: 'PlanMil',
header: '计划里程',
hidden: true,
width: 160
}
]
});
//#endregion 明细表配件
//#region 布局
//控件布局
this.panelTop = new Ext.Panel({
layout: "border",
region: "north",
height: 210,
items: [this.panelBtn, this.formEdit]
});
this.panelBody = new Ext.Panel({
title: '维修项目',
layout: "border",
region: 'north',
height: 270,
margin: '5 10',
items: [this.gridList]
});
this.panelBodyPlu = new Ext.Panel({
title: '维修配件',
layout: "border",
region: 'center',
margin: '5 10',
items: [this.gridListPlu]
});
this.panelList = new Ext.Panel({
layout: "border",
region: "center",
items: [
this.panelBody, this.panelBodyPlu
]
});
Ext.apply(this, {
items: [this.panelTop, this.panelList]
});
//#endregion
//绑定查询窗体
this.ParentWin = window.parent.opener;
//初始化数据
this.InitData();
//绑定事件
this.gridList.on('edit', function (editor, e, eOpts) {
this.gridAfterEdit(editor, e, eOpts);
}, this);
//绑定事件配件
this.gridListPlu.on('edit', function (editor, e, eOpts) {
this.gridAfterEditPlu(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.serialNoPlu = 0;
this.bodyDelPlu = [];
this.opStatus = opstatus;
Ext.Ajax.request({
waitMsg: '正在查询主表数据...',
url: '/TruckMng/MsKfWx/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} });
this.storeBodyPlu.load({ params: { billno: billno} });
}, // end LoadDate
Save: function (type) {
var basicForm = this.formEdit.getForm();
if (!basicForm.isValid()) {
return;
}
//判断表格数据是否合法
if (!validateEditorGridPanel(this.gridList)) {
return;
}
//更新车辆的行驶里程
var rptdate = DateToStr(basicForm.findField('PgDate').getValue());
var truckNo = basicForm.findField('TruckNo').getValue();
var conditionnew = "RptDate<='" + rptdate + "' and TruckNo='" + truckNo + "'";
Ext.Ajax.request({
waitMsg: '正在查询车辆已行驶里程数据...',
url: '/TruckMng/MsMlieage/GetDataSum',
scope: this,
params: {
handle: this.opStatus,
condition: conditionnew
},
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 mlData = result.data;
if (mlData != null && mlData.TruckNo != '') {
basicForm.findField('RealMil').setValue(mlData.TotalMil);
}
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
}
});
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);
var bodydatasplu = [];
for (var i = 0; i < this.storeBodyPlu.getCount(); i += 1) {
var member = this.storeBodyPlu.getAt(i);
bodydatasplu.push(member);
}
var jsonBodyPlu = ConvertRecordsToJson(bodydatasplu);
var jsonDelBodyPlu = ConvertRecordsToJsonAll(this.bodyDelPlu);
Ext.Msg.wait('正在保存数据, 请稍侯..');
Ext.Ajax.request({
waitMsg: '正在保存数据...',
url: '/TruckMng/MsKfWx/Save',
scope: this,
params: {
opstatus: this.opStatus,
data: Ext.JSON.encode(data),
body: jsonBody,
delbody: jsonDelBody,
bodyplu: jsonBodyPlu,
delbodyplu: jsonDelBodyPlu
},
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('MsKfWxHead', returnData); // Ext.create('MsKfWxHead', data, NewGuid()); //或者new MsKfWxHead(data, NewGuid());
// this.StoreList.add(p);
// this.editRecord = p;
var arrNewRecords = this.StoreList.add(returnData);
this.editRecord = arrNewRecords[0];
}
else if (this.opStatus == 'edit') {
var editp = Ext.create('MsKfWxHead', 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 j = 0; j < this.storeBodyList.getCount(); j += 1) {
var memberbody = this.storeBodyList.getAt(j);
memberbody.set("BillNo", this.editRecord.get('BillNo'));
memberbody.commit();
};
for (var j = 0; j < this.storeBodyPlu.getCount(); j += 1) {
var memberbody = this.storeBodyPlu.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
//日期转化为字符串格式: yyyy-mm-dd
DateToStr: function (dt) {
var str = "";
if (dt.getFullYear) {
var y, m, d;
y = dt.getFullYear();
m = dt.getMonth() + 1; //1-12
d = dt.getDate();
str = "" + y + "-" + m + "-" + d;
}
return str;
},
onAddDetailClick: function (button, event, type) {
if (type == 0) {
this.addDetail();
} else {
this.addDetailPlu();
}
}, //end onAddDetailClick
onDelDetailClick: function (button, event, type) {
if (type == 0) {
this.deleteDetail();
} else {
this.deleteDetailPlu();
}
}, //onDelDetailClick
gridAfterEdit: function (editor, e, eOpts) {
//需要自己实现里面的事件
if (e.field == 'WxLxCode') {
var records = DsStoreQueryBy(this.storeWxLxCodeRef, 'WxLxCode', e.value);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
e.record.set('WxLxCode_Ref', data.WxLxName);
} else {
e.record.set('WxLxCode_Ref', '');
}
}
var WORKAMOUNT = 0;
var MATERIALAMOUNT = 0;
var TYREAMOUNT = 0;
var REPAIRAMOUNT = 0;
for (var i = 0; i < this.storeBodyList.getCount(); i += 1) {
WORKAMOUNT = Add(WORKAMOUNT, parseFloat(this.storeBodyList.getAt(i).get("WORKAMOUNT")));
MATERIALAMOUNT = Add(MATERIALAMOUNT, parseFloat(this.storeBodyList.getAt(i).get("MATERIALAMOUNT")));
TYREAMOUNT = Add(TYREAMOUNT, parseFloat(this.storeBodyList.getAt(i).get("TYREAMOUNT")));
}
Ext.getCmp("WORKAMOUNT").setValue(WORKAMOUNT);
Ext.getCmp("MATERIALAMOUNT").setValue(MATERIALAMOUNT);
Ext.getCmp("TYREAMOUNT").setValue(TYREAMOUNT);
Ext.getCmp("REPAIRAMOUNT").setValue(Add(Add(WORKAMOUNT, MATERIALAMOUNT), TYREAMOUNT));
},
gridAfterEditPlu: function (editor, e, eOpts) {
//需要自己实现里面的事件
if (e.field == 'PluCode') {
//判断配件库存是否>0
var opStatus = 'edit';
var plucode = e.value;
var basicForm = this.formEdit.getForm();
var orgcode = basicForm.findField('OrgCode').getValue();
var ckcode = '*';
var condition = "OrgCode='" + orgcode + "'and CkCode='" + ckcode + "' and PluCode='" + plucode + "' and JxCount > 0";
Ext.Ajax.request({
waitMsg: '正在查询配件库存数据...',
url: '/TruckMng/MsLsKc/GetData',
async: false,
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 pluData = result.data;
if (pluData == null || pluData.PluCode == '') {
Ext.Msg.show({
title: '提示',
msg: '组织:' + orgcode + '配件:' + plucode + '库存数量为0',
icon: Ext.MessageBox.INFO,
buttons: Ext.Msg.OK
});
e.record.set('PluCode_Ref', '');
e.record.set('PluName', '');
e.record.set('Unit', '');
e.record.set('Spec', '');
e.record.set('PcNo', '*');
e.record.set('TyreType', '*');
e.record.set('TyrePos', '*');
}
plucode = pluData.PluCode;
this.jxcount = pluData.JxCount;
} else {
Ext.MessageBox.alert('请求出现错误,请重试', response.responseText);
}
},
scope: this
});
if (plucode != null && plucode != '') {
var records = DsStoreQueryBy(this.storePluCodeRef, 'PluCode', plucode);
if (records.getCount() > 0) {
var data = records.getAt(0).data;
e.record.set('PluCode_Ref', data.PluName);
e.record.set('PluName', data.PluName);
e.record.set('Unit', data.Unit);
e.record.set('Spec', data.Spec);
e.record.set('PcNo', '*');
e.record.set('TyreType', '*');
e.record.set('TyrePos', '*');
} else {
e.record.set('PluCode_Ref', '');
e.record.set('PluName', '');
e.record.set('Unit', '');
e.record.set('Spec', '');
e.record.set('PcNo', '*');
e.record.set('TyreType', '*');
e.record.set('TyrePos', '*');
}
}
}
else if (e.field == 'LyCount') {
var lycount = e.value;
if (lycount > this.jxcount) {
Ext.Msg.show({
title: '提示',
msg: '配件领用数量大于库存数量,库存数量为' + this.jxcount + '',
icon: Ext.MessageBox.INFO,
buttons: Ext.Msg.OK
});
e.record.set('LyCount', 0);
}
}
},
addDetail: function () {
var newSerialno = DsGetNewSerialNo(this.storeBodyList, this.serialNo);
this.serialNo = newSerialno;
var record = Ext.create('MsKfWxBody', {
BillNo: '*',
SerialNo: newSerialno,
WxLxCode: '',
WxLxCode_Ref: '',
WxItem: '',
QuotaHours: 0,
RealHours: 0,
SkillUser: '',
SkillUser_Ref: '',
KfWxUser: '',
KfWxUser_Ref: '',
Remark: '',
WORKAMOUNT: 0,
MATERIALAMOUNT: 0,
TYREAMOUNT: 0
});
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]);
}
},
addDetailPlu: function () {
var newSerialno = DsGetNewSerialNo(this.storeBodyPlu, this.serialNoPlu);
this.serialNoPlu = newSerialno;
var record = Ext.create('MsKfWxPlu', {
BillNo: '*',
SerialNo: newSerialno,
PluCode: '',
PluCode_Ref: '',
PluName: '',
Spec: '',
PcNo: '',
TyreType: "0",
TyreType_Ref: "0",
TyrePos: '',
TyrePos_Ref: '',
Unit: '',
Price: 0,
LyCount: 0,
Remark: '',
PlanMil: 0
});
this.storeBodyPlu.add(record);
var n = this.storeBodyPlu.getCount();
this.gridListCellEditingPlu.startEditByPosition({ row: n - 1, column: 2 });
},
deleteDetailPlu: function () {
this.serialNoPlu = DsGetCurSerialNo(this.storeBodyPlu, this.serialNoPlu);
var selectedRecords = this.gridListPlu.selModel.getSelection();
for (var i = 0; i < selectedRecords.length; i++) {
var rec = selectedRecords[i];
if (rec.BillNo != "" || rec.BillNo != "*") //如果是新增但没有保存的数据,没有必要提交到后台
{
this.bodyDelPlu.push(rec);
}
this.storeBodyPlu.remove(selectedRecords[i]);
}
},
onAccountClick: function (button, event) {
Ext.MessageBox.confirm('提示', '记账后数据无法修改,确认记账吗?', function (btn) {
if (btn == 'yes') {
this.Account();
}
}, this);
},
Account: function () {
var basicForm = this.formEdit.getForm();
basicForm.findField('BillNo').setDisabled(false);
var headdata = basicForm.getValues();
basicForm.findField('BillNo').setDisabled(true);
Ext.MessageBox.wait("正在记账,请稍侯.");
Ext.Ajax.request({
waitMsg: '正在记账...',
scope: this,
url: '/CommMng/PubSys/Account',
params: {
billno: headdata.BillNo,
ywtype: '5'//headdata.YwType
},
callback: function (options, success, response) {
if (success) {
var jsonresult = Ext.JSON.decode(response.responseText);
if (jsonresult.Success) //成功
{
var returnData = jsonresult.Data;
this.formEdit.getForm().setValues(returnData);
var editp = Ext.create('MsKfWxHead', 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();
this.setSaveBtnStatus(false);
Ext.MessageBox.alert("提示", jsonresult.Message);
} else //记账失败失败
{
Ext.Msg.show({ title: '错误', msg: jsonresult.Message, icon: Ext.Msg.ERROR, 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.ERROR, buttons: Ext.Msg.OK });
}
}); //end Ext.Ajax.request
},
setSaveBtnStatus: function (enable) {
var btnESave = Ext.getCmp('btnESave');
var btnESaveAndClose = Ext.getCmp('btnESaveAndClose');
var btnESaveAndNew = Ext.getCmp('btnESaveAndNew');
var btnEbtnEAccount = Ext.getCmp('btnEAccount');
if (enable) {
btnESave.enable();
btnESaveAndClose.enable();
btnESaveAndNew.enable();
btnEbtnEAccount.enable();
} else {
btnESave.disable();
btnESaveAndClose.disable();
btnESaveAndNew.disable();
btnEbtnEAccount.disable();
}
},
Print: function () {
var basicForm = this.formEdit.getForm();
var billNo = basicForm.findField('BillNo').value;
if (billNo == '*' || billNo == '') {
Ext.Msg.show({ title: '错误', msg: '单据还没有保存,请保存后再打印', icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK });
return;
}
var printType = 'MsKfWx';
var sql1 = "SET LANGUAGE 'us_english' SELECT * FROM tMsKfWxHead WHERE BillNo = '" + billNo + "'";
var sql2 = "SET LANGUAGE 'us_english' SELECT * FROM tMsKfWxBody WHERE BillNo = '" + billNo + "'";
var sql3 = "SET LANGUAGE 'us_english' SELECT * FROM tMsKfWxPlu WHERE BillNo = '" + billNo + "'";
var sql4 = "";
var sql5 = "";
var sql6 = "";
PrintComm(printType, sql1, sql2, sql3, sql4, sql5, sql6);
}
});