YZProjectCloud/yanzhu-ui-app/miniprogram/pageage/project_checked/info/index.js

143 lines
3.3 KiB
JavaScript

// pageage/project_checked/info/index.js
import config from "../../../config";
import { getToken, getUserInfo } from "../../../utils/auth";
import { uploadFiles } from "../../utils/upload.js";
import { tryToJson } from '../../utils/tools'
import {
getProjectChecked,
updateProjectChecked,
} from "../../../api/project";
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
imageInfoData: [],
rowData: {},
projectUserInfo: {},
projectId: "",
projectName: "",
initData: {},
isApprove: false,
checkResult: null,
checkingFiles: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (!getToken()) {
wx.redirectTo({
url: "../../../pages/login/login",
});
}
const proUserInfo = getUserInfo();
this.setData({
projectUserInfo: proUserInfo.projectUserInfo,
projectId: app.globalData.useProjectId,
projectName: app.globalData.useProjectName,
initData: {
id: app.globalData.useProjectId,
text: app.globalData.useProjectName,
},
isApprove: options.type == "approve",
});
if (options.id) {
//加载数据
this.loadData(options.id);
} else {
app.toast("参数错误!");
this.doBack(false)
}
},
onCheckResultChange(e) {
this.setData({
checkResult: e.detail
})
},
// 上传图片
onImagesArr(e) {
this.setData({
imageInfoData: e.detail
})
},
doBack(isRefresh) {
/*返回列表页面并刷新*/
if (isRefresh) {
wx.navigateBack({
delta: 1
});
} else {
wx.redirectTo({
url: "../list/index",
})
}
},
//展示图片
showImg: function (e) {
let img = e.target.dataset.set;
wx.previewImage({
urls: img.split(','),
current: 0
})
},
/**
*加载数据
*/
loadData(id) {
wx.showLoading({
title: '加载中...',
})
getProjectChecked(id).then(res => {
let data = res.data || {};
let task = tryToJson(data.workingPosition, {});
let imgs = (data.imageUrls ? data.imageUrls.split(",") : []).map(img => config.baseImgUrl + img);
let checkImgs = (data.checkingFiles ? data.checkingFiles.split(",") : []).map(img => config.baseImgUrl + img);
data.images = imgs;
data.taskName = task.full;
data.checkImgs = checkImgs;
this.setData({
rowData: data,
imageInfoData: checkImgs,
})
wx.hideLoading()
});
},
returnToPage: function (isRefresh) {
this.doBack(false)
},
async submitSave(e) {
let approveStatus = e.target.dataset.set;
if (!this.data.checkResult) {
app.toast("请选择审批结果!");
return false;
}
if (this.data.imageInfoData.length == 0) {
app.toast("请上传图片!");
return;
}
let fileUrls = await uploadFiles(this.data.imageInfoData);
debugger
let postData = {
id: this.data.rowData.id,
approveStatus: approveStatus,
checkResult: this.data.checkResult,
checkingFiles: fileUrls.join(","),
};
try {
await updateProjectChecked(postData);
app.toast("保存成功!");
this.doBack(true);
} catch (error) {
console.error('保存失败:', error);
app.toast("保存失败,请重试");
}
}
})