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

655 lines
18 KiB
JavaScript
Raw Normal View History

2024-05-03 10:37:27 +08:00
import {
syncFileUpload
} from '../../../utils/request'
2023-09-24 23:17:05 +08:00
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-05-03 10:37:27 +08:00
maxDate: new Date(2088, 1, 1).getTime(),
deptId: "",
projectId: "",
projectName: "",
loginName: "",
userName: "",
rectifierData: [],
rectifierData2: [],
imageInfoData: [],
checkingResult: "1",
2023-09-24 23:17:05 +08:00
//验收时间
2024-05-03 10:37:27 +08:00
checkTime: '',
loadShow: false,
qualityUser: "",
qualityUserName: "",
superviseUser: "",
superviseUserName: "",
checkWorkingPosition: "",
intro: "",
infoData: {},
activeName: "",
flowRecordList: [],
minUrls: [],
dataTypeLvl1: "",
dataTypeLvl2: "",
dataTypeLvl1List: [],
dataTypeLvl2List: [],
dataTypeLvl2AllList: [],
list: [{
id: 1,
text: "合格"
}, {
id: 2,
text: "不合格"
}],
request: app.globalData.reqUrl,
flowNodes: [{
text: '开始'
}, {
text: '提交申请'
}, {
text: '监理审批'
}, {
text: '结束'
}],
active: 1,
checkingFiles: "",
fileType: ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf", "png", "jpg", "jpeg"],
fileUrlArray: []
2023-09-24 23:17:05 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-05-03 10:37:27 +08:00
let {
id,
dt1
} = 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,
dt1,
projectId: app.globalData.projectId,
projectName: app.globalData.projectName,
deptId: res.data.deptId,
loginName: res.data.loginName,
userName: res.data.nickName
})
this.getProjectUserData();
this.getDataTypeLvlList();
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
let tempData = []
that.setData({
2024-05-03 10:37:27 +08:00
rectifierData: res.data,
2023-09-24 23:17:05 +08:00
})
}
}
})
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectuserinfo/selectProjectUnitUser',
method: "get",
data: {
unitType: "2",
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
let tempData = []
that.setData({
2024-05-03 10:37:27 +08:00
rectifierData2: res.data,
2023-09-24 23:17:05 +08:00
})
}
}
})
},
2024-01-21 20:09:42 +08:00
//查询验收类型数据
2024-05-03 10:37:27 +08:00
getDataTypeLvlList() {
2024-01-21 20:09:42 +08:00
let that = this
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectchecking/queryDictType',
method: "get",
data: {
type: "project_checking_data_type_lvl1"
2024-01-21 20:09:42 +08:00
},
2024-05-03 10:37:27 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2024-01-21 20:09:42 +08:00
},
2024-05-03 10:37:27 +08:00
success(res) {
2024-01-21 20:09:42 +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
});
2024-01-21 20:09:42 +08:00
})
that.setData({
2024-05-03 10:37:27 +08:00
dataTypeLvl1List: list,
2024-01-21 20:09:42 +08:00
})
}
}
})
wx.request({
2024-05-03 10:37:27 +08:00
url: app.globalData.reqUrl + '/wechat/projectchecking/queryDictType',
method: "get",
data: {
type: "project_checking_data_type_lvl2"
2024-01-21 20:09:42 +08:00
},
2024-05-03 10:37:27 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2024-01-21 20:09:42 +08:00
},
2024-05-03 10:37:27 +08:00
success(res) {
2024-01-21 20:09:42 +08:00
res = res.data
2024-05-03 10:37:27 +08:00
if (res.code == 200) {
2024-01-21 20:09:42 +08:00
let tempData = []
2024-05-03 10:37:27 +08:00
res.data.forEach(it => {
console.log(that.data.dt1, "xxxxxxxxxxxxxxxx");
if (it.remark == that.data.dt1) {
tempData.push({
"id": it.dictValue,
"text": it.dictLabel
});
2024-01-21 20:09:42 +08:00
}
})
that.setData({
2024-05-03 10:37:27 +08:00
dataTypeLvl2List: tempData,
dataTypeLvl2AllList: res.data
2024-01-21 20:09:42 +08:00
})
}
}
})
},
2023-09-24 23:17:05 +08:00
//切换验收结果
2024-05-03 10:37:27 +08:00
onSelectType(e) {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
checkingResult: e.detail.id
2023-09-24 23:17:05 +08:00
})
2024-01-21 20:09:42 +08:00
},
//验收类型
2024-05-03 10:37:27 +08:00
onSelectTypeLvl1(e) {
2024-01-21 20:09:42 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
dataTypeLvl1: e.detail.id
2024-01-21 20:09:42 +08:00
})
let tempData = []
2024-05-03 10:37:27 +08:00
this.data.dataTypeLvl2AllList.forEach(it => {
if (it.remark == e.detail.id) {
tempData.push({
"id": it.dictValue,
"text": it.dictLabel
});
2024-01-21 20:09:42 +08:00
}
})
this.setData({
2024-05-03 10:37:27 +08:00
dataTypeLvl2List: tempData,
dataTypeLvl2: tempData[0].id,
2024-01-21 20:09:42 +08:00
})
2024-05-03 10:37:27 +08:00
},
2024-01-21 20:09:42 +08:00
//类型分类
2024-05-03 10:37:27 +08:00
onSelectTypeLvl2(e) {
2024-01-21 20:09:42 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
dataTypeLvl2: e.detail.id
2024-01-21 20:09:42 +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
onInputCheckWorkingPositionValue(e) {
2023-09-24 23:17:05 +08:00
let checkWorkingPosition = e.detail.value
this.setData({
checkWorkingPosition
})
},
//验收描述
2024-05-03 10:37:27 +08:00
onInputIntroValue(e) {
2023-09-24 23:17:05 +08:00
let intro = e.detail.value
this.setData({
intro
})
},
//验收时间
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
/**
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/projectchecking/info',
method: "get",
data: {
id: id
},
success(res) {
res = res.data
if (res.code == 200) {
let imageInfoData = [];
if (res.data.imageUrls) {
res.data.imageUrls.split(',').forEach(element => {
imageInfoData.push(that.data.request + element + '.min.jpg');
});
}
let checkingFiles = [];
if (res.data.checkingFiles) {
let files = JSON.parse(res.data.checkingFiles);
if (files && files.length > 0) {
files.forEach(item => {
let it = item.split('/');
checkingFiles.push({
'name': it[it.length - 1],
path: item
});
});
}
}
that.setData({
infoData: res.data,
fileUrlArray: checkingFiles,
dataTypeLvl1: res.data.dataTypeLvl1,
dataTypeLvl2: res.data.dataTypeLvl2,
qualityUser: res.data.qualityUser,
qualityUserName: res.data.qualityUserName,
superviseUser: res.data.superviseUser,
superviseUserName: res.data.superviseUserName,
checkWorkingPosition: res.data.checkWorkingPosition,
intro: res.data.intro,
checkTime: res.data.checkTime,
imageInfoData,
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: "3",
fromId: this.data.id
},
success(res) {
res = res.data
if (res.code == 200) {
that.setData({
flowRecordList: res.data
})
}
}
})
},
2023-09-24 23:17:05 +08:00
2024-05-03 10:37:27 +08:00
// 手风琴
onChange(event) {
this.setData({
activeName: event.detail,
});
},
2023-09-24 23:17:05 +08:00
// list 上传图片
2024-05-03 10:37:27 +08:00
onImagesArr(e) {
2023-09-24 23:17:05 +08:00
var data = this.data.imageInfoData
data = e.detail
this.setData({
2024-05-03 10:37:27 +08:00
imageInfoData: data
2023-09-24 23:17:05 +08:00
})
},
//添加质量专员
2024-05-03 10:37:27 +08:00
onAddQualityUser(e) {
if (e.detail.length > 0) {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
qualityUser: e.detail[0].phoneNumber,
qualityUserName: e.detail[0].userName
2023-09-24 23:17:05 +08:00
})
}
},
//添加监理专员
2024-05-03 10:37:27 +08:00
onAddSuperviseUser(e) {
if (e.detail.length > 0) {
2023-09-24 23:17:05 +08:00
this.setData({
2024-05-03 10:37:27 +08:00
superviseUser: e.detail[0].phoneNumber,
superviseUserName: e.detail[0].userName
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
onProblemSubmitSave() {
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,
qualityUser,
qualityUserName,
superviseUser,
superviseUserName,
checkWorkingPosition,
intro,
checkTime,
imageInfoData,
loginName,
dataTypeLvl1,
dataTypeLvl2,
checkingFiles
} = 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 (imageInfoData.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
if (dataTypeLvl1 == "") {
2024-01-21 20:09:42 +08:00
app.toast("请选择验收类型!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2024-01-21 20:09:42 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (dataTypeLvl2 == "") {
2024-01-21 20:09:42 +08:00
app.toast("请选择类型分类!")
that.setData({
2024-05-03 10:37:27 +08:00
loadShow: false
2024-01-21 20:09:42 +08:00
})
return;
}
2024-05-03 10:37:27 +08:00
if (qualityUser == "" || qualityUserName == "") {
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 (superviseUser == "" || superviseUserName == "") {
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 (checkWorkingPosition == "") {
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 (intro == "") {
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 (checkingFiles.length > 0) {
for (let i = 0; i < checkingFiles.length; i++) {
let _fileType = checkingFiles[i].path.split('.');
_fileType = _fileType[_fileType.length - 1].toLowerCase();
//判断附件类型,如果是图片直接展示,非图片则显示附件
if (that.data.fileType.indexOf(_fileType) == -1) {
app.toast("当前 [ " + _fileType + " ] 文件不支持上传!")
that.setData({
loadShow: false
});
return;
}
}
}
2023-09-24 23:17:05 +08:00
let fileUrls = [];
2024-05-03 10:37:27 +08:00
let _checkingFiles = [];
imageInfoData.forEach(async (item) => {
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
let name = "file"
2023-09-24 23:17:05 +08:00
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
2024-05-03 10:37:27 +08:00
if (item.indexOf(that.data.request) > -1) {
fileUrls.push(item.replace(that.data.request, "").replace(".min.jpg", ""));
} else {
let obj = await that.syncUploadImage(uploadUrl, item, name);
2023-09-24 23:17:05 +08:00
fileUrls.push(obj.data.fileName);
}
//验证图片上传完毕
2024-05-03 10:37:27 +08:00
if (fileUrls.length == imageInfoData.length) {
2023-09-24 23:17:05 +08:00
let params = {
id,
qualityUser,
qualityUserName,
superviseUser,
superviseUserName,
checkWorkingPosition,
intro,
2024-05-03 10:37:27 +08:00
checkingDate: checkTime,
approveStatus: "1",
updateBy: loginName,
imageUrls: fileUrls.toString(),
2024-01-21 20:09:42 +08:00
dataTypeLvl1,
dataTypeLvl2,
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
if (checkingFiles.length > 0) {
checkingFiles.forEach(async (file) => {
if (file.path.indexOf('/profile/') > -1) {
_checkingFiles.push(file.path);
} else {
let obj = await that.syncUploadImage(uploadUrl, file.path, name);
_checkingFiles.push(obj.data.fileName);
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
if (checkingFiles.length == _checkingFiles.length) {
params.checkingFiles = JSON.stringify(_checkingFiles);
this.submitForm(params);
}
});
} else {
this.submitForm(params);
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
* 提交表单
* @param {*} params
2023-09-24 23:17:05 +08:00
*/
2024-05-03 10:37:27 +08:00
submitForm(params){
let that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/projectchecking/edit',
method: "POST",
data: params,
2023-09-24 23:17:05 +08:00
header: {
2024-05-03 10:37:27 +08:00
"Username": that.data.loginName,
"Content-Type": "application/json"
2023-09-24 23:17:05 +08:00
},
2024-05-03 10:37:27 +08:00
success(res) {
that.setData({
loadShow: false
2023-09-24 23:17:05 +08:00
})
2024-05-03 10:37:27 +08:00
res = res.data
if (res.code == 200) {
app.toast("修改成功!")
setTimeout(() => {
wx.redirectTo({
url: '../list/index',
})
}, 200)
}
2023-09-24 23:17:05 +08:00
}
2024-05-03 10:37:27 +08:00
})
},
/**
* 这里考虑上传图片异步问题封装为同步
*/
syncUploadImage(url, uploadFile, name) {
return new Promise((resolve, reject) => {
wx.uploadFile({
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
});
})
},
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
wx.redirectTo({
url: '../list/index',
})
2024-05-03 10:37:27 +08:00
},
/**
* 相关附件上传
* @param {*} options
*/
otherFileUpload(options) {
let file = options.detail;
this.setData({
checkingFiles: file
});
},
2023-09-24 23:17:05 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})