jhwxapp/miniprogram/pageage/project_problemmodify/quality/add/index.js

537 lines
15 KiB
JavaScript
Raw Normal View History

2023-08-24 18:44:06 +08:00
// pageage/safetyManagement/addSafetyInspect/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-04-14 21:28:11 +08:00
maxDate: new Date(2088, 1, 1).getTime(),
minDate: new Date().getTime() + (3600 * 48 * 1000),
projectId: "",
projectName: "",
loginName: "",
userName: "",
rectifierData: [],
rectifierData2: [],
rectifierData3: [],
imageInfoData: [],
2023-08-24 18:44:06 +08:00
//验收时间
2024-04-14 21:28:11 +08:00
nickedTime: '',
loadShow: false,
lordSent: "",
lordSentUser: "",
copySend: "",
copySendUser: "",
recheckSend: "",
recheckSendUser: "",
workParts: "",
changeInfo: "",
dangerType: "1",
dangerTypeList: [],
selectValue: "",
selectIndex: "",
problemType: "1",
showHis: false,
problemTypeList: [{
id: "1",
text: "常规检查"
}, {
id: "2",
text: "专项检查"
}],
flowNodes:[{text:'开始'},{text:'提交隐患'},{text:'隐患整改'},{text:'隐患复检'},{text:'结束'}],
active: 0
2023-08-24 18:44:06 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2024-04-14 21:28:11 +08:00
let {
projectId,
projectName
} = options
2023-08-24 18:44:06 +08:00
//获取缓存数据
wx.getStorage({
2024-04-14 21:28:11 +08:00
key: 'userinfo',
success: res => {
this.setData({
projectId: app.globalData.projectId,
projectName: app.globalData.projectName,
loginName: res.data.loginName,
userName: res.data.nickName,
recheckSend: res.data.nickName,
recheckSendUser: res.data.loginName
})
this.getAllProjectUserData();
this.getDangerTypeList();
this.getHisInfo();
}
})
2023-08-24 18:44:06 +08:00
},
//查询项目人员数据
2024-04-14 21:28:11 +08:00
getAllProjectUserData() {
2023-08-24 18:44:06 +08:00
let that = this
wx.request({
2024-04-14 21:28:11 +08:00
url: app.globalData.reqUrl + '/wechat/projectuserinfo/queryAllProjectUserByParams',
method: "get",
data: {
projectId: that.data.projectId,
loginName: that.data.loginName
2023-08-24 18:44:06 +08:00
},
2024-04-14 21:28:11 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-08-24 18:44:06 +08:00
},
2024-04-14 21:28:11 +08:00
success(res) {
2023-08-24 18:44:06 +08:00
res = res.data
2024-04-14 21:28:11 +08:00
if (res.code == 200) {
2023-08-24 18:44:06 +08:00
that.setData({
2024-04-14 21:28:11 +08:00
rectifierData: res.data,
rectifierData3: res.data,
2023-08-24 18:44:06 +08:00
})
}
}
})
2023-12-18 00:43:12 +08:00
wx.request({
2024-04-14 21:28:11 +08:00
url: app.globalData.reqUrl + '/wechat/projectuserinfo/queryAllProjectUserByParams',
method: "get",
data: {
projectId: that.data.projectId,
loginName: that.data.loginName,
selectMy: 'Y'
2023-12-18 00:43:12 +08:00
},
2024-04-14 21:28:11 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-12-18 00:43:12 +08:00
},
2024-04-14 21:28:11 +08:00
success(res) {
res = res.data;
if (res.code == 200) {
let findMy = false;
res.data.forEach(it => {
if (it.userinfoList.length > 0) {
it.userinfoList.forEach(u => {
if (that.data.loginName == u.phonenumber) {
findMy = true;
}
});
}
});
if(!findMy){
res.data[0].userinfoList.push({state:false,nickName:that.data.userName,jobTypeName:'集团公司',phonenumber:that.data.loginName});
}
2023-12-18 00:43:12 +08:00
that.setData({
2024-04-14 21:28:11 +08:00
rectifierData2: res.data,
2023-12-18 00:43:12 +08:00
})
}
}
})
2023-08-24 18:44:06 +08:00
},
2024-04-14 21:28:11 +08:00
getHisInfo() {
2023-09-13 13:01:30 +08:00
//这里查询当前登录人上次提交隐患,自动填充整改人,复检人,抄送人
let that = this
wx.request({
2024-04-14 21:28:11 +08:00
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/findLastDataByParams',
method: "get",
data: {
projectId: that.data.projectId,
createUser: that.data.loginName,
infoType: 1
2023-09-13 13:01:30 +08:00
},
2024-04-14 21:28:11 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-09-13 13:01:30 +08:00
},
2024-04-14 21:28:11 +08:00
success(res) {
2023-09-13 13:01:30 +08:00
res = res.data
2024-04-14 21:28:11 +08:00
if (res.code == 200 && res.data) {
2023-09-13 13:01:30 +08:00
that.setData({
2024-04-14 21:28:11 +08:00
showHis: true,
lordSent: res.data.lordSent,
lordSentUser: res.data.lordSentUser,
recheckSend: res.data.recheckSend,
recheckSendUser: res.data.recheckSendUser,
copySend: res.data.copySend,
copySendUser: res.data.copySendUser
2023-09-13 13:01:30 +08:00
})
}
}
})
},
2024-04-14 21:28:11 +08:00
getDangerTypeList() {
2023-08-24 18:44:06 +08:00
let that = this
wx.request({
2024-04-14 21:28:11 +08:00
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/queryDangerType',
method: "get",
data: {
type: 'ssp_zlyhlx'
2023-08-24 18:44:06 +08:00
},
2024-04-14 21:28:11 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-08-24 18:44:06 +08:00
},
2024-04-14 21:28:11 +08:00
success(res) {
2023-08-24 18:44:06 +08:00
res = res.data
2024-04-14 21:28:11 +08:00
if (res.code == 200) {
let list = [];
res.data.forEach(it => {
list.push({
"id": it.dictValue,
"text": it.dictLabel
});
2023-08-24 18:44:06 +08:00
})
that.setData({
2024-04-14 21:28:11 +08:00
dangerTypeList: list
2023-08-24 18:44:06 +08:00
})
}
}
})
},
//隐患描述
2024-04-14 21:28:11 +08:00
onInputWorkParts(e) {
2023-08-24 18:44:06 +08:00
let workParts = e.detail.value
this.setData({
workParts
})
},
//整改要求
2024-04-14 21:28:11 +08:00
onInputChangeInfoValue(e) {
2023-08-24 18:44:06 +08:00
let changeInfo = e.detail.value
this.setData({
changeInfo
})
},
//验收时间
2024-04-14 21:28:11 +08:00
onInputTime(e) {
2023-08-24 18:44:06 +08:00
let nickedTime = e.detail
this.setData({
nickedTime
})
},
// list 上传图片
2024-04-14 21:28:11 +08:00
onImagesArr(e) {
2023-08-24 18:44:06 +08:00
var data = this.data.imageInfoData
data = e.detail
this.setData({
2024-04-14 21:28:11 +08:00
imageInfoData: data
2023-08-24 18:44:06 +08:00
})
},
//添加整改人
2024-04-14 21:28:11 +08:00
onAddLordSent(e) {
if (e.detail.length > 0) {
2023-08-24 18:44:06 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
lordSent: e.detail[0].userName,
lordSentUser: e.detail[0].phoneNumber
2023-08-24 18:44:06 +08:00
})
}
},
//添加抄送人
2024-04-14 21:28:11 +08:00
onAddCopySend(e) {
if (e.detail.length > 0) {
let phoneNumbers = "";
let userNames = "";
e.detail.forEach(it => {
phoneNumbers += "," + it.phoneNumber;
userNames += "," + it.userName;
2023-08-24 18:44:06 +08:00
});
this.setData({
2024-04-14 21:28:11 +08:00
copySend: userNames.substring(1),
copySendUser: phoneNumbers.substring(1)
2023-08-24 18:44:06 +08:00
})
2024-04-14 21:28:11 +08:00
} else {
2023-08-24 18:44:06 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
copySend: "",
copySendUser: ""
2023-08-24 18:44:06 +08:00
})
}
},
//添加复检人
2024-04-14 21:28:11 +08:00
onAddRecheckSend(e) {
if (e.detail.length > 0) {
2023-08-24 18:44:06 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
recheckSend: e.detail[0].userName,
recheckSendUser: e.detail[0].phoneNumber
2023-08-24 18:44:06 +08:00
})
}
},
2024-04-14 21:28:11 +08:00
2023-08-24 18:44:06 +08:00
//取消页面
2024-04-14 21:28:11 +08:00
cancelSaveView() {
2023-08-30 23:57:34 +08:00
this.returnToPage()
2023-08-24 18:44:06 +08:00
},
//保存
2024-04-14 21:28:11 +08:00
onProblemSubmitSave() {
2023-08-24 18:44:06 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
loadShow: true
2023-08-24 18:44:06 +08:00
})
let that = this
2024-04-14 21:28:11 +08:00
let {
projectId,
projectName,
dangerType,
lordSent,
lordSentUser,
copySend,
copySendUser,
workParts,
changeInfo,
nickedTime,
recheckSend,
recheckSendUser,
imageInfoData,
loginName,
problemType,
userName
} = that.data;
2023-08-24 18:44:06 +08:00
//数据效验
2024-04-14 21:28:11 +08:00
if (projectId == "" || loginName == "") {
2023-08-24 18:44:06 +08:00
app.toast("数据异常,请刷新页面重试!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (imageInfoData.length == 0) {
2023-08-24 18:44:06 +08:00
app.toast("请上传隐患现场图片!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (problemType == "") {
2023-12-18 00:43:12 +08:00
app.toast("请选择检查类型!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-12-18 00:43:12 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (dangerType == "") {
2023-08-24 18:44:06 +08:00
app.toast("请选择隐患类型!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (workParts == "") {
2023-08-24 18:44:06 +08:00
app.toast("请填写隐患描述!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (changeInfo == "") {
2023-08-24 18:44:06 +08:00
app.toast("请填写隐患整改要求!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (nickedTime == "") {
2023-08-24 18:44:06 +08:00
app.toast("请选择整改截至时间!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (lordSent == "" || lordSentUser == "") {
2023-08-24 18:44:06 +08:00
app.toast("请选择整改人!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (recheckSend == "" || recheckSendUser == "") {
2023-08-24 18:44:06 +08:00
app.toast("请选择复检人!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
2024-04-14 21:28:11 +08:00
if (copySend == "" || copySendUser == "") {
2023-08-24 18:44:06 +08:00
app.toast("请选择抄送人!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
let pos = copySend.split(",");
2024-04-14 21:28:11 +08:00
pos.forEach(it => {
if (it == lordSent) {
2023-08-24 18:44:06 +08:00
app.toast("抄送人中不能包含整改人!")
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
return;
}
});
let fileUrls = [];
2024-04-14 21:28:11 +08:00
imageInfoData.forEach(async (item) => {
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
let name = "file"
2023-08-24 18:44:06 +08:00
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
2024-04-14 21:28:11 +08:00
let obj = await that.syncUploadImage(uploadUrl, item, name);
2023-08-24 18:44:06 +08:00
fileUrls.push(obj.data.fileName);
//验证图片上传完毕
2024-04-14 21:28:11 +08:00
if (fileUrls.length == imageInfoData.length) {
2023-08-24 18:44:06 +08:00
let params = {
projectId,
2024-04-14 21:28:11 +08:00
infoType: "1",
problemArea: projectName,
2023-12-18 00:43:12 +08:00
problemType,
2023-08-24 18:44:06 +08:00
workParts,
changeInfo,
lordSent,
lordSentUser,
copySend,
copySendUser,
2024-04-14 21:28:11 +08:00
checkState: 0,
nickedTime: nickedTime + " 23:59:59",
smarkUrl: fileUrls.toString(),
createUser: loginName,
2023-08-24 18:44:06 +08:00
dangerType,
recheckSend,
recheckSendUser
}
wx.request({
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/addQuality',
2024-04-14 21:28:11 +08:00
method: "POST",
data: params,
2023-08-24 18:44:06 +08:00
header: {
"Username": loginName,
"Content-Type": "application/json"
},
2024-04-14 21:28:11 +08:00
success(res) {
2023-08-24 18:44:06 +08:00
that.setData({
2024-04-14 21:28:11 +08:00
loadShow: false
2023-08-24 18:44:06 +08:00
})
2024-04-14 21:28:11 +08:00
res = res.data
if (res.code == 200) {
2023-08-24 18:44:06 +08:00
app.toast("添加成功!")
2024-04-14 21:28:11 +08:00
setTimeout(() => {
wx.redirectTo({
url: '../list/index',
})
}, 200)
2023-08-24 18:44:06 +08:00
}
}
2024-04-14 21:28:11 +08:00
})
}
})
2023-08-24 18:44:06 +08:00
},
/**
* 这里考虑上传图片异步问题封装为同步
*/
2024-04-14 21:28:11 +08:00
syncUploadImage(url, uploadFile, name) {
2023-08-24 18:44:06 +08:00
return new Promise((resolve, reject) => {
wx.uploadFile({
2024-04-14 21:28:11 +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-08-24 18:44:06 +08:00
});
})
},
2023-09-02 23:45:35 +08:00
//选择检查类型
2024-04-14 21:28:11 +08:00
onSelectProblemType(e) {
2023-09-02 23:45:35 +08:00
this.setData({
2024-04-14 21:28:11 +08:00
problemType: e.detail.id
2023-09-02 23:45:35 +08:00
})
},
//选择隐患类型
2024-04-14 21:28:11 +08:00
onSelectDangerType(e) {
this.setData({
dangerType: e.detail.id
})
},
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
wx.redirectTo({
url: '../list/index',
})
},
2023-08-28 16:11:02 +08:00
2023-08-24 18:44:06 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})