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

369 lines
10 KiB
JavaScript
Raw Normal View History

2023-10-16 00:00:50 +08:00
// pageage/safetyManagement/addSafetyInspect/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2024-07-01 23:58:39 +08:00
maxDate: new Date(2088, 1, 1).getTime(),
minDate: new Date().getTime() + (3600 * 48 * 1000),
projectId: "",
projectName: "",
loginName: "",
userName: "",
rectifierData: [],
loadShow: false,
showHis: false,
inspectInfoData: [{
image_upload: []
}],
lordSent: "",
lordSentUser: "",
flowNodes: [{
text: '开始'
}, {
text: '提交隐患'
}, {
text: '隐患整改'
}, {
text: '隐患复检'
}, {
text: '结束'
}],
active: 0,
problemType: "1",
problemTypeList: [{
id: 1,
text: '常规检查'
}, {
id: 2,
text: '专项检查'
}]
2023-10-16 00:00:50 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//获取缓存数据
wx.getStorage({
2024-07-01 23:58:39 +08:00
key: 'userinfo',
success: res => {
this.setData({
projectId: app.globalData.projectId,
projectName: app.globalData.projectName,
loginName: res.data.loginName,
userName: res.data.nickName
})
this.getAllProjectUserData();
this.getHisInfo();
}
})
2023-10-16 00:00:50 +08:00
},
//查询项目人员数据
2024-07-01 23:58:39 +08:00
getAllProjectUserData() {
2023-10-16 00:00:50 +08:00
let that = this
wx.request({
2024-07-01 23:58:39 +08:00
url: app.globalData.reqUrl + '/wechat/projectuserinfo/selectProjectUnitUser',
method: "get",
data: {
projectId: that.data.projectId,
loginName: that.data.loginName
2023-10-16 00:00:50 +08:00
},
2024-07-01 23:58:39 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-10-16 00:00:50 +08:00
},
2024-07-01 23:58:39 +08:00
success(res) {
2023-10-16 00:00:50 +08:00
res = res.data
2024-07-01 23:58:39 +08:00
if (res.code == 200) {
2023-10-16 00:00:50 +08:00
that.setData({
2024-07-01 23:58:39 +08:00
rectifierData: res.data
2023-10-16 00:00:50 +08:00
})
}
}
})
},
2024-07-01 23:58:39 +08:00
getHisInfo() {
2023-10-16 00:00:50 +08:00
//这里查询当前登录人上次提交隐患,自动填充整改人,复检人,抄送人
let that = this
wx.request({
2024-07-01 23:58:39 +08:00
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/findDraftLastDataByParams',
method: "get",
data: {
projectId: that.data.projectId,
createUser: that.data.loginName,
infoType: 1
2023-10-16 00:00:50 +08:00
},
2024-07-01 23:58:39 +08:00
header: {
'content-type': 'application/x-www-form-urlencoded'
2023-10-16 00:00:50 +08:00
},
2024-07-01 23:58:39 +08:00
success(res) {
2023-10-16 00:00:50 +08:00
res = res.data
2024-07-01 23:58:39 +08:00
if (res.code == 200 && res.data) {
2023-10-16 00:00:50 +08:00
that.setData({
2024-07-01 23:58:39 +08:00
showHis: true,
lordSent: res.data.lordSent,
lordSentUser: res.data.lordSentUser
2023-10-16 00:00:50 +08:00
})
}
}
})
},
// list 上传图片
2024-07-01 23:58:39 +08:00
onImagesArr(e) {
2023-10-16 00:00:50 +08:00
var index = e.currentTarget.dataset.index
var data = this.data.inspectInfoData
data[index].image_upload = e.detail
this.setData({
2024-07-01 23:58:39 +08:00
inspectInfoData: data
2023-10-16 00:00:50 +08:00
})
},
//添加整改人
2024-07-01 23:58:39 +08:00
onAddLordSent(e) {
if (e.detail.length > 0) {
2023-10-16 00:00:50 +08:00
this.setData({
2024-07-01 23:58:39 +08:00
lordSent: e.detail[0].userName,
lordSentUser: e.detail[0].phoneNumber
2023-10-16 00:00:50 +08:00
})
}
},
//取消页面
2024-07-01 23:58:39 +08:00
cancelSaveView() {
2023-10-16 00:00:50 +08:00
this.returnToPage()
},
//保存
2024-07-01 23:58:39 +08:00
onProblemSubmitSave() {
2023-10-16 00:00:50 +08:00
this.setData({
2024-07-01 23:58:39 +08:00
loadShow: true
2023-10-16 00:00:50 +08:00
})
let that = this
2024-07-01 23:58:39 +08:00
let {
projectId,
projectName,
problemType,
lordSent,
lordSentUser,
loginName,
inspectInfoData
} = that.data;
2023-10-16 00:00:50 +08:00
//数据效验
2024-07-01 23:58:39 +08:00
if (projectId == "" || loginName == "") {
2023-10-16 00:00:50 +08:00
app.toast("数据异常,请刷新页面重试!")
that.setData({
2024-07-01 23:58:39 +08:00
loadShow: false
})
return;
}
if (problemType == "") {
app.toast("请选择问题类型!")
that.setData({
loadShow: false
2023-10-16 00:00:50 +08:00
})
return;
}
2024-07-01 23:58:39 +08:00
if (lordSent == "" || lordSentUser == "") {
2023-10-16 00:00:50 +08:00
app.toast("请选择整改人!")
that.setData({
2024-07-01 23:58:39 +08:00
loadShow: false
2023-10-16 00:00:50 +08:00
})
return;
}
let fileUrls = [];
2024-07-01 23:58:39 +08:00
inspectInfoData.forEach(async (item) => {
let beforeCheckUrl = [];
item.image_upload.forEach(async (it) => {
let uploadUrl = app.globalData.uploadUrl + '/common/upload'
2023-10-16 00:00:50 +08:00
let name = "file";
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
2024-07-01 23:58:39 +08:00
let obj = await that.syncUploadImage(uploadUrl, it, name);
2023-10-16 00:00:50 +08:00
beforeCheckUrl.push(obj.data.fileName);
2024-07-01 23:58:39 +08:00
if (beforeCheckUrl.length >= item.image_upload.length) {
2023-10-16 00:00:50 +08:00
fileUrls.push(beforeCheckUrl);
}
2024-07-01 23:58:39 +08:00
//验证图片上传完毕
if (fileUrls.length >= inspectInfoData.length) {
2023-10-16 00:00:50 +08:00
let params = {
projectId,
2024-07-01 23:58:39 +08:00
infoType: "1",
problemArea: projectName,
problemType,
2023-10-16 00:00:50 +08:00
lordSent,
lordSentUser,
2024-07-01 23:58:39 +08:00
checkState: 0,
fileUrls: fileUrls,
createUser: loginName
2023-10-16 00:00:50 +08:00
}
wx.request({
url: app.globalData.reqUrl + '/wechat/projectProblemmodify/addQualityDraft',
2024-07-01 23:58:39 +08:00
method: "POST",
data: params,
2023-10-16 00:00:50 +08:00
header: {
"Username": loginName,
"Content-Type": "application/json"
},
2024-07-01 23:58:39 +08:00
success(res) {
2023-10-16 00:00:50 +08:00
that.setData({
2024-07-01 23:58:39 +08:00
loadShow: false
2023-10-16 00:00:50 +08:00
})
res = res.data
2024-07-01 23:58:39 +08:00
if (res.code == 200) {
2023-10-16 00:00:50 +08:00
app.toast("添加成功!")
2024-07-01 23:58:39 +08:00
setTimeout(() => {
if (wx.getStorageSync('nav-menu') == "list") {
2023-10-16 00:00:50 +08:00
wx.redirectTo({
url: '../list/index',
})
2024-07-01 23:58:39 +08:00
} else {
2023-10-16 00:00:50 +08:00
wx.redirectTo({
url: '../../../../pages/quality_manage/index',
})
}
2024-07-01 23:58:39 +08:00
}, 200);
2023-10-16 00:00:50 +08:00
}
}
})
}
});
})
},
/**
* 这里考虑上传图片异步问题封装为同步
*/
2024-07-01 23:58:39 +08:00
syncUploadImage(url, uploadFile, name) {
2023-10-16 00:00:50 +08:00
return new Promise((resolve, reject) => {
wx.uploadFile({
2024-07-01 23:58:39 +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-10-16 00:00:50 +08:00
});
})
},
2024-07-01 23:58:39 +08:00
/**
* 选择问题类型
* @param {*} e
*/
onSelectProblemType(e) {
this.setData({
problemType: e.detail.id,
2023-10-16 00:00:50 +08:00
})
2024-07-01 23:58:39 +08:00
},
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
if (wx.getStorageSync('nav-menu') == "list") {
wx.redirectTo({
url: '../list/index',
})
} else {
wx.redirectTo({
url: '../../../../pages/quality_manage/index',
})
}
},
2023-10-16 00:00:50 +08:00
//新增问题
2024-07-01 23:58:39 +08:00
onNewIssues() {
2023-10-16 00:00:50 +08:00
var data = this.data.inspectInfoData
2024-07-01 23:58:39 +08:00
if (data.length == 5) {
2023-10-16 00:00:50 +08:00
app.toast("一次最多只能提交5个问题!");
return false;
}
2024-07-01 23:58:39 +08:00
data.push({
image_upload: []
})
2023-10-16 00:00:50 +08:00
this.setData({
2024-07-01 23:58:39 +08:00
inspectInfoData: data
2023-10-16 00:00:50 +08:00
})
},
//删除
2024-07-01 23:58:39 +08:00
onNewIssuesDelete(e) {
2023-10-16 00:00:50 +08:00
var index = e.currentTarget.dataset.index
var data = this.data.inspectInfoData
2024-07-01 23:58:39 +08:00
data.splice(index, 1)
2023-10-16 00:00:50 +08:00
this.setData({
2024-07-01 23:58:39 +08:00
inspectInfoData: data
2023-10-16 00:00:50 +08:00
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})