493 lines
13 KiB
TypeScript
493 lines
13 KiB
TypeScript
// pages/vehicleMaintenance/operation/offer/offer.ts
|
|
import { getAction, postAction } from '../../../../api/base';
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
showMore: true, // 展示/收起明细
|
|
classifyOptions: [] as any, // 保养分类数据
|
|
filterClassifyOptions: [] as any, // 过滤保养分类数据
|
|
repairDetailList: [] as any, // 保养明细
|
|
materialCost: '' as any, // 总计材料费
|
|
totalWorkHours: '' as any, // 总计工时
|
|
totalWorkHoursCost: '' as any, // 总计工时费用
|
|
totaCost: '' as any, // 总计
|
|
offerContent: '', // 内容说明
|
|
attachmentUpkeepList: [], // 单据附件
|
|
beforeUpkeepImgUrl: [], // 保养前图片
|
|
inUpkeepImgUrl: [], // 保养中图片
|
|
afterUpkeepImgUrl: [], // 保养后图片
|
|
paramsInfo: {} as any, // 保养单数据
|
|
uploadUrl: 'api/vehicles/repair/fileUpload', // 上传图片地址
|
|
classifySearchVal: '', // 保养分类过滤查询
|
|
currentIndex: null // 当前选中的保养明细
|
|
},
|
|
showDetail() {
|
|
this.setData({
|
|
showMore: !this.data.showMore
|
|
});
|
|
},
|
|
// 明细相关值修改-------------------
|
|
addOffer() {
|
|
let tmpArr = this.data.repairDetailList;
|
|
tmpArr.push({
|
|
repairClass: '',
|
|
repairClass_dictText: '',
|
|
repairContent: '',
|
|
quantity: '',
|
|
unitPrice: '',
|
|
workHours: '',
|
|
workHoursCost: '',
|
|
totalCost: 0
|
|
});
|
|
this.setData({
|
|
repairDetailList: tmpArr
|
|
});
|
|
},
|
|
changeOfferVal(e: any) {
|
|
let tmpArr = this.data.repairDetailList;
|
|
let index = e.currentTarget.dataset.index;
|
|
let { key, fixed } = e.currentTarget.dataset;
|
|
if (key != 'repairContent') {
|
|
if (e.detail.value > 99999999) {
|
|
wx.showToast({
|
|
title: '输入值不能大于99999999',
|
|
icon: 'none'
|
|
});
|
|
e.detail.value = 99999999;
|
|
} else if (e.detail.value < 0) {
|
|
wx.showToast({
|
|
title: '输入值不能小于0',
|
|
icon: 'none'
|
|
});
|
|
e.detail.value = 0;
|
|
}
|
|
tmpArr[index][key] = Number(Number(e.detail.value).toFixed(fixed));
|
|
} else tmpArr[index][key] = e.detail.value;
|
|
this.setData({
|
|
repairDetailList: tmpArr
|
|
});
|
|
if (key == 'repairContent') {
|
|
this.checkString(tmpArr[index][key]);
|
|
// 保养内容不用计算
|
|
return;
|
|
}
|
|
// 调用计算总金额
|
|
this.calculateTotal();
|
|
},
|
|
// 校验字符串
|
|
checkString(str: string) {
|
|
let res = true;
|
|
const spaceRegex = new RegExp(/\s+/g);
|
|
if (str && spaceRegex.test(str)) {
|
|
wx.showToast({
|
|
title: '保养内容不支持含有空格',
|
|
icon: 'none'
|
|
});
|
|
res = false;
|
|
}
|
|
|
|
const regex = /['"{};<>!@#$%^&*|\\]/;
|
|
if (str && regex.test(str)) {
|
|
wx.showToast({
|
|
title: '保养内容不支持特殊字符',
|
|
icon: 'none'
|
|
});
|
|
res = false;
|
|
}
|
|
const tooLong = str.length > 100;
|
|
if (str && tooLong) {
|
|
wx.showToast({
|
|
title: '保养内容输入长度不得超过100个字符',
|
|
icon: 'none'
|
|
});
|
|
res = false;
|
|
}
|
|
return res;
|
|
},
|
|
changeNum(e: any) {
|
|
console.log(e);
|
|
let tmpArr = this.data.repairDetailList;
|
|
let index = e.currentTarget.dataset.index;
|
|
if (tmpArr[index].quantity == '') {
|
|
tmpArr[index].quantity = 0;
|
|
}
|
|
if (e.currentTarget.dataset.type == 'up') {
|
|
tmpArr[index].quantity += 1;
|
|
tmpArr[index].quantity = Number(
|
|
Number(tmpArr[index].quantity).toFixed(0)
|
|
);
|
|
} else {
|
|
if (tmpArr[index].quantity == 0) {
|
|
wx.showToast({
|
|
title: '数量不能为负数',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
tmpArr[index].quantity -= 1;
|
|
tmpArr[index].quantity = Number(
|
|
Number(tmpArr[index].quantity).toFixed(0)
|
|
);
|
|
}
|
|
this.setData({
|
|
repairDetailList: tmpArr
|
|
});
|
|
// 调用计算总金额
|
|
this.calculateTotal();
|
|
},
|
|
delOffer(e: any) {
|
|
console.log(e.currentTarget.dataset.index);
|
|
let tmpArr = this.data.repairDetailList.filter(
|
|
(x: any, i: number) => i != e.currentTarget.dataset.index
|
|
);
|
|
this.setData({
|
|
repairDetailList: tmpArr
|
|
});
|
|
// 调用计算总金额
|
|
this.calculateTotal();
|
|
},
|
|
calculateTotal() {
|
|
let tmpArr = this.data.repairDetailList;
|
|
let materialCost = 0;
|
|
let totalWorkHours = 0;
|
|
let totalWorkHoursCost = 0;
|
|
let totaCost = 0;
|
|
tmpArr.forEach((item: any) => {
|
|
let quantity = item.quantity ? Number(item.quantity) : 0;
|
|
let unitPrice = item.unitPrice ? Number(item.unitPrice) : 0;
|
|
let workHours = item.workHours ? Number(item.workHours) : 0;
|
|
let workHoursCost = item.workHoursCost ? Number(item.workHoursCost) : 0;
|
|
item.totalCost = Number(
|
|
(quantity * unitPrice + workHours * workHoursCost).toFixed(2)
|
|
);
|
|
materialCost += Number((quantity * unitPrice).toFixed(2));
|
|
totalWorkHours += workHours;
|
|
totalWorkHoursCost += Number((workHours * workHoursCost).toFixed(2));
|
|
totaCost += item.totalCost;
|
|
});
|
|
this.setData({
|
|
repairDetailList: tmpArr,
|
|
materialCost: materialCost,
|
|
totalWorkHours: totalWorkHours,
|
|
totalWorkHoursCost: totalWorkHoursCost,
|
|
totaCost: totaCost
|
|
});
|
|
},
|
|
// 明细相关值修改-------------------
|
|
getMarker(e: any) {
|
|
console.log(e);
|
|
this.setData({
|
|
offerContent: e.detail.value
|
|
});
|
|
},
|
|
// 上一步
|
|
goBack() {
|
|
wx.navigateBack();
|
|
},
|
|
// 提交报价
|
|
bindSend() {
|
|
// 校验是否新增了保养明细
|
|
if (this.data.repairDetailList.length == 0) {
|
|
wx.showToast({
|
|
title: '请先新建保养明细',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
// 校验保养明细
|
|
let res = true;
|
|
let result = true;
|
|
this.data.repairDetailList.forEach((item: any) => {
|
|
let key = Object.keys(item);
|
|
key.forEach(el => {
|
|
if (item[el] === '') res = false;
|
|
if (el == 'repairContent') {
|
|
let check = this.checkString(item[el]);
|
|
if (!check) result = false;
|
|
}
|
|
});
|
|
});
|
|
if (!res) {
|
|
wx.showToast({
|
|
title: '请完成保养明细的填写',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
// 保养内容不符合校验
|
|
if (!result) {
|
|
return;
|
|
}
|
|
if (!this.data.offerContent) {
|
|
wx.showToast({
|
|
title: '请输入内容说明',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (this.data.attachmentUpkeepList.length == 0) {
|
|
wx.showToast({
|
|
title: '请上传单据附件',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (this.data.beforeUpkeepImgUrl.length == 0) {
|
|
wx.showToast({
|
|
title: '请上传保养前图片',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (this.data.inUpkeepImgUrl.length == 0) {
|
|
wx.showToast({
|
|
title: '请上传保养中图片',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
if (this.data.afterUpkeepImgUrl.length == 0) {
|
|
wx.showToast({
|
|
title: '请上传保养后图片',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
|
|
let params = {
|
|
upkeepBill: this.data.paramsInfo.upkeepBill,
|
|
upkeepAssign: this.data.paramsInfo.upkeepAssign,
|
|
upkeepOffer: {
|
|
repairDetailList: this.data.repairDetailList,
|
|
materialCost: this.data.materialCost, //总计材料费
|
|
totalWorkHours: this.data.totalWorkHours, //总计工时
|
|
totalWorkHoursCost: this.data.totalWorkHoursCost, //工时费用总计
|
|
totaCost: this.data.totaCost, //总计
|
|
offerContent: this.data.offerContent, //内容说明
|
|
attachmentUpkeepList: this.data.attachmentUpkeepList, //单据附件
|
|
beforeUpkeepImgUrl:
|
|
this.data.beforeUpkeepImgUrl.length > 0
|
|
? this.data.beforeUpkeepImgUrl.join(',')
|
|
: '', //保养前图片
|
|
inUpkeepImgUrl:
|
|
this.data.inUpkeepImgUrl.length > 0
|
|
? this.data.inUpkeepImgUrl.join(',')
|
|
: '', //保养中图片
|
|
afterUpkeepImgUrl:
|
|
this.data.afterUpkeepImgUrl.length > 0
|
|
? this.data.afterUpkeepImgUrl.join(',')
|
|
: '' //保养后图片
|
|
}
|
|
};
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask: true
|
|
});
|
|
postAction('api/vehicles/upkeepBill/addDataEntry', params)
|
|
.then((res: any) => {
|
|
if (res.code == 200) {
|
|
wx.hideLoading();
|
|
wx.showToast({
|
|
title: '录入成功',
|
|
icon: 'none'
|
|
});
|
|
wx.setStorageSync('message', {
|
|
flowStatus: 100,
|
|
id: res.message
|
|
});
|
|
wx.redirectTo({
|
|
url: '../message/message',
|
|
fail: e => {
|
|
console.log(e);
|
|
}
|
|
});
|
|
} else {
|
|
wx.hideLoading();
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
});
|
|
}
|
|
})
|
|
.catch((err: any) => {
|
|
wx.hideLoading();
|
|
wx.showToast({
|
|
title: err.message,
|
|
icon: 'none'
|
|
});
|
|
});
|
|
},
|
|
// 单据附件上传回调
|
|
returnPicOne(e: any) {
|
|
this.setData({
|
|
attachmentUpkeepList: e.detail.photoList
|
|
});
|
|
},
|
|
// 保养中图片上传回调
|
|
returnPicTwo(e: any) {
|
|
let list = [] as any;
|
|
e.detail.photoList.forEach((item: any) => {
|
|
list.push(item.fileUrl);
|
|
});
|
|
this.setData({
|
|
inUpkeepImgUrl: list
|
|
});
|
|
},
|
|
// 保养后图片上传回调
|
|
returnPicThree(e: any) {
|
|
let list = [] as any;
|
|
e.detail.photoList.forEach((item: any) => {
|
|
list.push(item.fileUrl);
|
|
});
|
|
this.setData({
|
|
afterUpkeepImgUrl: list
|
|
});
|
|
},
|
|
// 保养前图片上传回调
|
|
returnPicFour(e: any) {
|
|
let list = [] as any;
|
|
e.detail.photoList.forEach((item: any) => {
|
|
list.push(item.fileUrl);
|
|
});
|
|
this.setData({
|
|
beforeUpkeepImgUrl: list
|
|
});
|
|
},
|
|
getInf() {
|
|
// 获取信息
|
|
let info = wx.getStorageSync('paramsInfo');
|
|
wx.removeStorage({ key: 'paramsInfo' });
|
|
this.setData({
|
|
paramsInfo: info
|
|
});
|
|
console.log('看看数据', this.data.paramsInfo);
|
|
},
|
|
// 获取报修分类
|
|
getRepairClass() {
|
|
getAction('api/vehicles/repair/getRepairClass')
|
|
.then((res: any) => {
|
|
if (res.code == 200) {
|
|
let data = [] as any;
|
|
res.result.forEach((el: any) => {
|
|
el.value = el.value;
|
|
el.text = el.text;
|
|
});
|
|
data = res.result;
|
|
this.setData({
|
|
classifyOptions: data,
|
|
filterClassifyOptions: data
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: res.message,
|
|
icon: 'none'
|
|
});
|
|
}
|
|
})
|
|
.catch((err: any) => {
|
|
wx.showToast({
|
|
title: err.message,
|
|
icon: 'none'
|
|
});
|
|
});
|
|
},
|
|
// 展示选择框
|
|
pickerChange(event: any) {
|
|
//下拉框切换是否展示
|
|
let { fieldname, index } = event.currentTarget.dataset;
|
|
let data: any = { ...this.data };
|
|
data[fieldname] = true;
|
|
this.setData(data);
|
|
this.setData({
|
|
currentIndex: index
|
|
});
|
|
},
|
|
// 隐藏展示框
|
|
hidePicker() {
|
|
this.setData({
|
|
classifyShow: false
|
|
});
|
|
},
|
|
// 选择器点击确认
|
|
pickerConfirm(event: any) {
|
|
let { fieldname } = event.currentTarget.dataset;
|
|
let detail = event.detail;
|
|
let data = this.data.repairDetailList;
|
|
let index = this.data.currentIndex;
|
|
if (index != null) {
|
|
data[index].repairClass = detail.value.value;
|
|
data[index].repairClass_dictText = detail.value.text;
|
|
// 选择报修分类
|
|
if (fieldname == 'classify') {
|
|
this.setData({
|
|
repairDetailList: data
|
|
});
|
|
}
|
|
}
|
|
this.hidePicker();
|
|
},
|
|
// 清空数据
|
|
resetData(event: any) {
|
|
let { fieldname, index } = event.currentTarget.dataset;
|
|
let data = this.data.repairDetailList;
|
|
if (fieldname == 'repairPeople') {
|
|
this.setData({
|
|
repairPeople: ''
|
|
});
|
|
} else if (fieldname == 'phone') {
|
|
this.setData({
|
|
phone: ''
|
|
});
|
|
} else if (fieldname == 'repairContent') {
|
|
data[index].repairContent = '';
|
|
this.setData({
|
|
repairDetailList: data
|
|
});
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
this.getInf();
|
|
this.getRepairClass();
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {}
|
|
});
|