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

467 lines
13 KiB
JavaScript
Raw Normal View History

2023-08-21 18:55:48 +08:00
// pageage/safetyManagement/addSafetyInspect/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
maxDate:new Date(2088,1,1).getTime(),
currentDate:new Date().getTime(),
deptId:"",
projectId:"",
projectName:"",
loginName:"",
userName:"",
rectifierData:[],
2023-09-24 23:17:05 +08:00
rectifierData2:[],
2023-08-21 18:55:48 +08:00
imageInfoData:[],
2023-08-30 23:57:34 +08:00
checkingResult:"1",
2023-08-21 18:55:48 +08:00
//验收时间
checkTime:'',
loadShow:false,
qualityUser:"",
qualityUserName:"",
superviseUser:"",
superviseUserName:"",
checkWorkingPosition:"",
2023-08-25 00:03:39 +08:00
intro:"",
2024-02-17 14:01:45 +08:00
dataTypeLvl1:"1",
2024-01-21 20:09:42 +08:00
dataTypeLvl2:"",
dataTypeLvl1List:[],
dataTypeLvl2List:[],
dataTypeLvl2AllList:[],
2024-04-14 21:28:11 +08:00
list:[{id:1,text:"合格"},{id:2,text:"不合格"}],
flowNodes:[{text:'开始'},{text:'提交申请'},{text:'监理审批'},{text:'结束'}],
active: 0
2023-08-21 18:55:48 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let {projectId,projectName} = options
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success:res=>{
this.setData({
projectId,
projectName,
deptId:res.data.deptId,
loginName:res.data.loginName,
userName:res.data.nickName
})
2024-01-21 20:09:42 +08:00
this.getProjectUserData();
this.getDataTypeLvlList();
2023-08-21 18:55:48 +08:00
}
})
},
//查询项目人员数据
getProjectUserData(){
let that = this
wx.request({
2023-09-24 23:17:05 +08:00
url: app.globalData.reqUrl+'/wechat/projectuserinfo/selectProjectUnitUser',
2023-08-21 18:55:48 +08:00
method:"get",
data:{
2023-09-23 20:13:40 +08:00
unitType:"4",
2023-08-21 18:55:48 +08:00
projectId:that.data.projectId
},
header:{
'content-type': 'application/x-www-form-urlencoded'
},
success(res){
res = res.data
if(res.code == 200){
let tempData = []
that.setData({
rectifierData:res.data,
})
}
}
})
2023-09-24 23:17:05 +08:00
wx.request({
url: app.globalData.reqUrl+'/wechat/projectuserinfo/selectProjectUnitUser',
method:"get",
data:{
unitType:"2",
projectId:that.data.projectId
},
header:{
'content-type': 'application/x-www-form-urlencoded'
},
success(res){
res = res.data
if(res.code == 200){
let tempData = []
that.setData({
rectifierData2:res.data,
})
}
}
})
2023-08-21 18:55:48 +08:00
},
2024-01-21 20:09:42 +08:00
//查询验收类型数据
getDataTypeLvlList(){
let that = this
wx.request({
url: app.globalData.reqUrl+'/wechat/projectchecking/queryDictType',
method:"get",
data:{
type:"project_checking_data_type_lvl1"
},
header:{
'content-type': 'application/x-www-form-urlencoded'
},
success(res){
res = res.data
if(res.code == 200){
let list=[];
res.data.forEach(it =>{
list.push({"id":it.dictValue,"text":it.dictLabel});
})
that.setData({
dataTypeLvl1List:list,
})
}
}
})
wx.request({
url: app.globalData.reqUrl+'/wechat/projectchecking/queryDictType',
method:"get",
data:{
type:"project_checking_data_type_lvl2"
},
header:{
'content-type': 'application/x-www-form-urlencoded'
},
success(res){
res = res.data
if(res.code == 200){
let tempData = []
res.data.forEach(it =>{
2024-02-17 14:01:45 +08:00
if(it.remark=="1"){
2024-01-21 20:09:42 +08:00
tempData.push({"id":it.dictValue,"text":it.dictLabel});
}
})
that.setData({
dataTypeLvl2List:tempData,
dataTypeLvl2AllList:res.data,
dataTypeLvl2:tempData[0].id,
})
}
}
})
},
2023-08-21 18:55:48 +08:00
//切换验收结果
2023-08-25 00:03:39 +08:00
onSelectType(e){
2023-08-21 18:55:48 +08:00
this.setData({
2023-08-25 00:03:39 +08:00
checkingResult:e.detail.id
})
2024-01-21 20:09:42 +08:00
},
//验收类型
onSelectTypeLvl1(e){
this.setData({
dataTypeLvl1:e.detail.id
})
let tempData = []
2024-04-08 00:58:58 +08:00
this.data.dataTypeLvl2AllList.forEach(it =>{
2024-02-17 14:01:45 +08:00
if(it.remark==e.detail.id){
2024-01-21 20:09:42 +08:00
tempData.push({"id":it.dictValue,"text":it.dictLabel});
}
})
this.setData({
dataTypeLvl2List:tempData,
dataTypeLvl2:tempData[0].id,
})
},
//类型分类
onSelectTypeLvl2(e){
this.setData({
dataTypeLvl2:e.detail.id
})
},
2023-08-21 18:55:48 +08:00
//工序部位
onInputCheckWorkingPositionValue(e){
let checkWorkingPosition = e.detail.value
this.setData({
checkWorkingPosition
})
},
//验收描述
onInputIntroValue(e){
let intro = e.detail.value
this.setData({
intro
})
},
//验收时间
onInputTime(e){
let checkTime = e.detail
this.setData({
checkTime
})
},
// list 上传图片
onImagesArr(e){
var data = this.data.imageInfoData
data = e.detail
this.setData({
imageInfoData:data
})
},
//添加质量专员
onAddQualityUser(e){
if(e.detail.length>0){
this.setData({
qualityUser:e.detail[0].phoneNumber,
qualityUserName:e.detail[0].userName
})
}
},
//添加监理专员
onAddSuperviseUser(e){
if(e.detail.length>0){
this.setData({
superviseUser:e.detail[0].phoneNumber,
superviseUserName:e.detail[0].userName
})
}
},
//取消页面
cancelSaveView(){
2023-08-30 23:57:34 +08:00
this.returnToPage()
2023-08-21 18:55:48 +08:00
},
//保存
onProblemSubmitSave(){
this.setData({
loadShow:true
})
let that = this
2024-01-21 20:09:42 +08:00
let {projectId,deptId,qualityUser,qualityUserName,superviseUser,superviseUserName,checkWorkingPosition,intro,checkTime,checkingResult,imageInfoData,loginName,userName,dataTypeLvl1,dataTypeLvl2} = that.data;
2023-08-21 18:55:48 +08:00
//数据效验
if(projectId==""||deptId==""||loginName==""){
app.toast("数据异常,请刷新页面重试!")
that.setData({
loadShow:false
})
return;
}
2023-08-24 18:44:06 +08:00
if(imageInfoData.length==0){
app.toast("请上传举牌验收现场图片!")
that.setData({
loadShow:false
})
return;
}
2024-01-21 20:09:42 +08:00
if(dataTypeLvl1==""){
app.toast("请选择验收类型!")
that.setData({
loadShow:false
})
return;
}
if(dataTypeLvl2==""){
app.toast("请选择类型分类!")
that.setData({
loadShow:false
})
return;
}
2023-08-21 18:55:48 +08:00
if(qualityUser==""||qualityUserName==""){
app.toast("请选择质量专员!")
that.setData({
loadShow:false
})
return;
}
if(superviseUser==""||superviseUserName==""){
app.toast("请选择监理专员!")
that.setData({
loadShow:false
})
return;
}
if(checkWorkingPosition==""){
app.toast("请填写验收工序部位!")
that.setData({
loadShow:false
})
return;
}
if(intro==""){
app.toast("请填写验收结果描述!")
that.setData({
loadShow:false
})
return;
}
if(checkTime==""){
app.toast("请选择验收时间!")
that.setData({
loadShow:false
})
return;
}
2023-09-23 20:13:40 +08:00
// if(checkingResult==""){
// app.toast("请选择验收结果!")
// that.setData({
// loadShow:false
// })
// return;
// }
2023-08-21 18:55:48 +08:00
let fileUrls = [];
imageInfoData.forEach(async (item)=>{
2023-08-24 18:44:06 +08:00
let uploadUrl = app.globalData.uploadUrl+'/common/upload'
2023-08-21 18:55:48 +08:00
let name = "file"
//这里复杂的图片上传,改为同步上传,因为小程序只能上传一张图片
let obj = await that.syncUploadImage(uploadUrl,item,name);
fileUrls.push(obj.data.fileName);
//验证图片上传完毕
if(fileUrls.length == imageInfoData.length){
let params = {
projectId,
deptId:deptId,
qualityUser,
qualityUserName,
superviseUser,
superviseUserName,
checkWorkingPosition,
intro,
checkingDate:checkTime,
2023-09-23 20:13:40 +08:00
//checkResult:checkingResult,
approveStatus:"1",
2023-08-21 18:55:48 +08:00
createBy:loginName,
2024-01-21 20:09:42 +08:00
imageUrls:fileUrls.toString(),
dataTypeLvl1,
dataTypeLvl2,
2023-08-21 18:55:48 +08:00
}
wx.request({
2023-08-24 18:44:06 +08:00
url: app.globalData.reqUrl + '/wechat/projectchecking/add',
2023-08-21 18:55:48 +08:00
method:"POST",
data:params,
header: {
2023-08-24 18:44:06 +08:00
"Username": loginName,
2023-08-21 18:55:48 +08:00
"Content-Type": "application/json"
},
success(res){
that.setData({
loadShow:false
})
res =res.data
if(res.code == 200){
app.toast("添加成功!")
setTimeout(()=>{
2023-08-30 23:57:34 +08:00
wx.redirectTo({
2023-08-21 18:55:48 +08:00
url: '../list/index',
})
2023-08-24 18:44:06 +08:00
},200)
2023-08-21 18:55:48 +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-08-28 16:11:02 +08:00
returnToPage: function () {
/*关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面*/
2023-08-30 23:57:34 +08:00
wx.redirectTo({
2023-08-28 16:11:02 +08:00
url: '../list/index',
})
},
2023-08-21 18:55:48 +08:00
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})