jhwxapp/miniprogram/pageage/project_checkDetection/edit/index.js

682 lines
20 KiB
JavaScript
Raw Normal View History

2023-09-24 23:17:05 +08:00
// pageage/safetyManagement/addSafetyInspect/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-05-03 10:37:27 +08:00
id: "",
maxDate: new Date(2088, 1, 1).getTime(),
deptId: "",
projectId: "",
projectName: "",
loginName: "",
rectifierData: [],
loadShow: false,
checkTypeList: [],
checkType: "1",
materialName: "",
usePosition: "",
sampleNum: "",
qualifiedFlag: "Y",
witnessUser: "",
witnessUserName: "",
checkTime: "",
laboratoryName: "",
infoData: {},
detectionFiles: "",
fileUrls: "",
fileUrlArray: [],
activeName: "",
flowRecordList: [],
qualifiedFlagList: [{
id: 'Y',
text: "是"
}, {
id: 'N',
text: "否"
}],
detectionFileData: [],
fileType: ["pdf", "png", "jpg", "jpeg"],
request: app.globalData.reqUrl,
flowNodes: [{
text: '开始'
}, {
text: '提交申请'
}, {
text: '检测报告'
}, {
text: '监理审批'
}, {
text: '结束'
}],
active: 1,
trustDeed: [],
attachments: [],
fileType: ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "png", "jpg", "jpeg"]
2023-09-24 23:17:05 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-05-03 10:37:27 +08:00
let {
id
} = options
2023-09-24 23:17:05 +08:00
//获取缓存数据
wx.getStorage({
2024-05-03 10:37:27 +08:00
key: 'userinfo',
success: res => {
this.setData({
id,
projectId: app.globalData.projectId,
projectName: app.globalData.projectName,
deptId: res.data.deptId,
loginName: res.data.loginName,
})
this.getProjectUserData();
this.getTypeList();
this.getInfo();
this.getAuditinfo();
}
})
2023-09-24 23:17:05 +08:00
},
//查询项目人员数据
2024-05-03 10:37:27 +08:00
getProjectUserData() {
2023-09-24 23:17:05 +08:00
let that = this
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectuserinfo/selectProjectUnitUser',
method: "get",
data: {
unitType: "4",
projectId: that.data.projectId
2023-09-24 23:17:05 +08:00
},
2024-05-03 10:37:27 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-09-24 23:17:05 +08:00
},
2024-05-03 10:37:27 +08:00
success(res) {
2023-09-24 23:17:05 +08:00
res = res.data
2024-05-03 10:37:27 +08:00
if (res.code == 200) {
2023-09-24 23:17:05 +08:00
that.setData({
2024-05-03 10:37:27 +08:00
rectifierData: res.data
2023-09-24 23:17:05 +08:00
})
}
}
})
},
2024-05-03 10:37:27 +08:00
getTypeList() {
2023-09-24 23:17:05 +08:00
let that = this
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectDetection/queryType',
method: "get",
data: {},
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-09-24 23:17:05 +08:00
},
2024-05-03 10:37:27 +08:00
success(res) {
2023-09-24 23:17:05 +08:00
res = res.data
2024-05-03 10:37:27 +08:00
if (res.code == 200) {
let list = [];
res.data.forEach(it => {
list.push({
"id": it.dictValue,
"text": it.dictLabel
});
2023-09-24 23:17:05 +08:00
})
that.setData({
2024-05-03 10:37:27 +08:00
checkTypeList: list
2023-09-24 23:17:05 +08:00
})
}
}
})
},
/**
* 获取安全检查详情信息
*
*/
2024-05-03 10:37:27 +08:00
getInfo() {
let {
id
} = this.data
2023-09-24 23:17:05 +08:00
let that = this
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectDetection/info',
method: "get",
data: {
id: id
},
success(res) {
res = res.data
if (res.code == 200) {
let fileUrls = [];
let fileNames = [];
let fileUrlArray = [];
//判断附件
if (res.data.detectionFile) {
res.data.detectionFile.split(',').forEach(element => {
let it = element.split('/');
fileNames.push(it[it.length - 1]);
fileUrls.push(element);
fileUrlArray.push({
name: it[it.length - 1],
path: element
});
});
}
let trustDeed = [];
if (res.data.trustDeed != null) {
res.data.trustDeed.split(',').forEach(item => {
trustDeed.push(that.data.request + item + '.min.jpg');
});
}
let attachments = [];
if (res.data.attachment) {
let files = JSON.parse(res.data.attachment);
if (files && files.length > 0) {
files.forEach(item => {
let it = item.split('/');
attachments.push({
'name': it[it.length - 1],
path: item
});
});
}
}
that.setData({
infoData: res.data,
trustDeed,
attachments,
detectionFiles: fileNames,
fileUrlArray,
fileUrls,
detectionFileData: fileUrlArray,
checkType: res.data.checkType,
materialName: res.data.materialName,
usePosition: res.data.usePosition,
sampleNum: res.data.sampleNum,
qualifiedFlag: res.data.qualifiedFlag,
witnessUser: res.data.witnessUser,
witnessUserName: res.data.witnessUserName,
checkTime: res.data.checkTime,
laboratoryName: res.data.laboratoryName,
loadShow: false
})
}
2023-09-24 23:17:05 +08:00
}
})
},
/**
* 查询流程日志
*/
2024-05-03 10:37:27 +08:00
getAuditinfo() {
let that = this
wx.request({
url: app.globalData.reqUrl + '/wechat/projectAuditinfo/selectProjectAuditinfo',
method: "get",
data: {
fromType: "1",
fromId: this.data.id
},
success(res) {
res = res.data
if (res.code == 200) {
that.setData({
flowRecordList: res.data
})
}
}
})
},
fileUpload(options) {
let file = options.detail;
this.setData({
detectionFileData: file
});
},
// 手风琴
onChange(event) {
this.setData({
activeName: event.detail,
});
},
2023-09-24 23:17:05 +08:00
//材料名称
2024-05-03 10:37:27 +08:00
onInputMaterialNameValue(e) {
2023-09-24 23:17:05 +08:00
let materialName = e.detail.value
this.setData({
materialName
})
},
//使用部位
2024-05-03 10:37:27 +08:00
onInputUsePositionValue(e) {
2023-09-24 23:17:05 +08:00
let usePosition = e.detail.value
this.setData({
usePosition
})
},
//取样数量
2024-05-03 10:37:27 +08:00
onInputSampleNumValue(e) {
2023-09-24 23:17:05 +08:00
let sampleNum = e.detail.value
this.setData({
sampleNum
})
},
//送检实验室名称
2024-05-03 10:37:27 +08:00
onInputLaboratoryNameValue(e) {
2023-09-24 23:17:05 +08:00
let laboratoryName = e.detail.value
this.setData({
laboratoryName
})
},
2024-05-03 10:37:27 +08:00
2023-09-24 23:17:05 +08:00
//验收时间
2024-05-03 10:37:27 +08:00
onInputTime(e) {
2023-09-24 23:17:05 +08:00
let checkTime = e.detail
this.setData({
checkTime
})
},
//添加监理专员
2024-05-03 10:37:27 +08:00
onAddSend(e) {
if (e.detail.length > 0) {
let phoneNumbers = "";
let userNames = "";
e.detail.forEach(it => {
phoneNumbers += "," + it.phoneNumber;
userNames += "," + it.userName;
2023-09-24 23:17:05 +08:00
});
this.setData({
2024-05-03 10:37:27 +08:00
witnessUserName: userNames.substring(1),
witnessUser: phoneNumbers.substring(1)
2023-09-24 23:17:05 +08:00
})
2024-05-03 10:37:27 +08:00
} else {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
witnessUser: "",
witnessUserName: ""
2023-09-24 23:17:05 +08:00
})
}
},
2024-05-03 10:37:27 +08:00
2023-09-24 23:17:05 +08:00
//取消页面
2024-05-03 10:37:27 +08:00
cancelSaveView() {
2023-09-24 23:17:05 +08:00
this.returnToPage()
},
//保存
2024-05-03 10:37:27 +08:00
onSubmitSave() {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
loadShow: true
2023-09-24 23:17:05 +08:00
})
let that = this
2024-05-03 10:37:27 +08:00
let {
id,
checkType,
materialName,
usePosition,
sampleNum,
qualifiedFlag,
witnessUser,
witnessUserName,
checkTime,
laboratoryName,
loginName,
detectionFileData,
trustDeed,
attachments
} = that.data;
2023-09-24 23:17:05 +08:00
//数据效验
2024-05-03 10:37:27 +08:00
if (id == "") {
2023-09-24 23:17:05 +08:00
app.toast("数据异常,请刷新页面重试!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (checkType == "") {
2023-09-24 23:17:05 +08:00
app.toast("请选择送检类型!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (materialName == "") {
2023-09-24 23:17:05 +08:00
app.toast("请填写材料名称!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (sampleNum == "") {
2023-09-24 23:17:05 +08:00
app.toast("请填写取样数量!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (usePosition == "") {
2023-09-24 23:17:05 +08:00
app.toast("请填写使用部位!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (qualifiedFlag == "") {
2023-09-24 23:17:05 +08:00
app.toast("请选择是否提供合格证!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (qualifiedFlag == "") {
2023-09-24 23:17:05 +08:00
app.toast("请选择是否提供合格证!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (witnessUser == "" || witnessUserName == "") {
2023-09-24 23:17:05 +08:00
app.toast("请选择见证人!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (checkTime == "") {
2023-09-24 23:17:05 +08:00
app.toast("请选择送检时间!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (laboratoryName == "") {
2023-09-24 23:17:05 +08:00
app.toast("请填写送检实验室名称!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
})
return;
}
if (trustDeed.length == 0) {
app.toast("请上传送检委托单!")
that.setData({
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (attachments.length > 0) {
for (let i = 0; i < attachments.length; i++) {
let _fileType = attachments[i].path.split('.');
_fileType = _fileType[_fileType.length - 1].toLowerCase();
//判断附件类型,如果是图片直接展示,非图片则显示附件
if (this.data.fileType.indexOf(_fileType) == -1) {
app.toast("当前 [ " + _fileType + " ] 文件不支持上传!")
that.setData({
loadShow: false
});
return;
}
}
}
if (this.data.infoData.detectionFile != null && detectionFileData.length == 0) {
2023-09-24 23:17:05 +08:00
app.toast("请上传检测报告!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
let path = "";
if (detectionFileData.length > 0) {
2023-09-24 23:17:05 +08:00
let _fileType = detectionFileData[0].path.split('.');
2024-05-03 10:37:27 +08:00
_fileType = _fileType[_fileType.length - 1].toLowerCase();
2023-09-24 23:17:05 +08:00
//判断附件类型,如果是图片直接展示,非图片则显示附件
2024-05-03 10:37:27 +08:00
if (this.data.fileType.indexOf(_fileType) == -1) {
app.toast("检测报告不支持 [ " + _fileType + " ] 格式!")
2023-09-24 23:17:05 +08:00
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2023-09-24 23:17:05 +08:00
});
return;
}
}
2024-05-03 10:37:27 +08:00
//检验委托单
let trustDeedImages = [];
//其它附件
let attachmentFiles = [];
//检测报告
let detectionFiles = [];
let params = {
id,
checkType,
materialName,
usePosition,
sampleNum,
qualifiedFlag,
witnessUser,
witnessUserName,
checkTime: checkTime,
laboratoryName,
updateBy: loginName,
approveStatus: that.data.approveStatus == null ? null : "1"
}
let uploadUrl = app.globalData.uploadUrl + '/common/upload';
let uploadName = "file";
trustDeed.forEach(async (item) => {
if (item.indexOf("/profile/") > -1) {
trustDeedImages.push(item.replace(that.data.request, "").replace(".min.jpg", ""));
} else {
let obj = await that.syncUploadImage(uploadUrl, item, uploadName);
trustDeedImages.push(obj.data.fileName)
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
if (trustDeedImages.length == trustDeed.length) {
params.trustDeed = trustDeedImages.toString();
if (attachments.length > 0) {
attachments.forEach(async (file) => {
if (file.path.indexOf("/profile/") > -1) {
attachmentFiles.push(file.path);
} else {
let fObj = await that.syncUploadImage(uploadUrl, file.path, uploadName);
attachmentFiles.push(fObj.data.fileName)
}
if (attachmentFiles.length == attachments.length) {
params.attachment = JSON.stringify(attachmentFiles);
if (detectionFileData.length > 0) {
detectionFileData.forEach(async (df) => {
if (df.path.indexOf("/profile/") > -1) {
detectionFiles.push(df.path);
} else {
let dfObj = await that.syncUploadImage(uploadUrl, df.path, uploadName);
detectionFiles.push(dfObj.data.fileName)
}
if (detectionFileData.length == detectionFiles.length) {
params.detectionFile = detectionFiles.toString();
this.submitForm(params);
}
});
} else {
this.submitForm(params);
}
}
});
} else {
if (detectionFileData.length > 0) {
detectionFileData.forEach(async (df) => {
if (df.path.indexOf("/profile/") > -1) {
detectionFiles.push(df.path);
} else {
let dfObj = await that.syncUploadImage(uploadUrl, df.path, uploadName);
detectionFiles.push(dfObj.data.fileName)
}
if (detectionFileData.length == detectionFiles.length) {
params.detectionFile = detectionFiles.toString();
this.submitForm(params);
}
});
} else {
this.submitForm(params);
}
}
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
});
},
/**
* 提交表单
* @param {*} params
*/
submitForm(params) {
let that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/projectDetection/edit',
method: "POST",
data: params,
header: {
"Username": that.data.loginName,
"Content-Type": "application/json"
},
success(res) {
that.setData({
loadShow: false
})
res = res.data
if (res.code == 200) {
app.toast("修改成功!")
setTimeout(() => {
2023-09-24 23:17:05 +08:00
wx.redirectTo({
url: '../list/index',
})
2024-05-03 10:37:27 +08:00
}, 200)
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
}
})
2023-09-24 23:17:05 +08:00
},
/**
* 这里考虑上传图片异步问题封装为同步
*/
2024-05-03 10:37:27 +08:00
syncUploadImage(url, uploadFile, name) {
2023-09-24 23:17:05 +08:00
return new Promise((resolve, reject) => {
wx.uploadFile({
2024-05-03 10:37:27 +08:00
url, // 上传的服务器接口地址
filePath: uploadFile,
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
name, //上传的所需字段,后端提供
formData: {
user: 'test'
},
success: (res) => {
// 上传完成操作
const data = JSON.parse(res.data)
resolve({
data: data
})
},
fail: (err) => {
//上传失败修改pedding为reject
console.log("访问接口失败", err);
wx.showToast({
title: "网络出错,上传失败",
icon: 'none',
duration: 1000
});
reject(err)
}
2023-09-24 23:17:05 +08:00
});
})
},
//选择检测类型
2024-05-03 10:37:27 +08:00
onSelectCheckType(e) {
this.setData({
checkType: e.detail.id
})
},
//选择是否提供合格证
onSelectQualifiedFlag(e) {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
qualified: e.detail.id
2023-09-24 23:17:05 +08:00
})
2024-05-03 10:37:27 +08:00
},
// list 上传图片
onImagesArr(e) {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
trustDeed: e.detail
2023-09-24 23:17:05 +08:00
})
2024-05-03 10:37:27 +08:00
},
/**
* 相关附件上传
* @param {*} options
*/
otherFileUpload(options) {
let file = options.detail;
this.setData({
attachments: file
});
},
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
wx.redirectTo({
url: '../list/index',
})
},
2023-09-24 23:17:05 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})