daofu-applet/pages/risk-pool/add-pool/index.js

310 lines
6.0 KiB
JavaScript
Raw Normal View History

2024-06-06 17:11:58 +08:00
// 上报动态
import Utils from "../../../utils/util"
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
topBarH: app.globalData.CustomBar,
baseUrl: app.FILE_SERVER_URL,
dateFilter: Utils.formatTime(new Date(), '-'),
showTypePop: false,
showAdvicePop: false,
TypeData: [],
postData: {},
files: [],
userInfo:{},
targetId:'',
},
/**
* 显示/关闭弹窗
*/
popModal: function (params) {
const type = params.currentTarget.dataset.type;
this.data[type] = !this.data[type];
this.setData(this.data)
},
/**
* 类型
*/
typeChange: function (params) {
const index = params.currentTarget.dataset.index;
this.data.postData.typeId = params.currentTarget.dataset.item.typeId;
this.data.postData.type = index + 1;
this.data.showTypePop = false;
this.setData(this.data);
},
/**
* 输入框赋值
*/
inputContent: function (e) {
const name = e.currentTarget.dataset.name;
this.data.postData[name] = e.detail.value;
this.setData(this.data);
},
/**
* 发布
*/
push: function () {
if (!this.data.postData.title) {
wx.showToast({
title: '请输入标题',
icon: 'none'
})
return
}
if (!this.data.postData.startTime) {
wx.showToast({
title: '请选择开始时间',
icon: 'none'
})
return
}
if (!this.data.postData.endTime) {
wx.showToast({
title: '请选择结束时间',
icon: 'none'
})
return
}
if (!this.data.postData.detail) {
wx.showToast({
title: '请输入动态内容',
icon: 'none'
})
return
}
if (!this.data.postData.typeId) {
wx.showToast({
title: '请选择类型',
icon: 'none'
})
return
}
let data = {
...this.data.postData,
dynamicsId:this.data.uuid,
userId:this.data.userInfo.userId,
targetId:this.data.targetId
};
app.axios("POST", "app", `/work/wkDynamicsAdd`,data).then(res => {
if (res.code == 1) {
wx.showToast({
title: '发布成功',
icon: 'none'
})
setTimeout(() => {
wx.navigateBack()
}, 1500);
} else {
wx.showToast({
title: res.message,
icon: 'none'
})
}
})
},
/**
* 选择文件
*/
chooseFile: function () {
wx.chooseImage({
count: 1,
type: 'all',
success: (res) => {
const tempFilePaths = res.tempFiles;
const path = tempFilePaths[0].path;
this.postImg(path)
}
})
},
/**
* 上传图片
*/
postImg(filePath) {
wx.showLoading({
title: '文件上传中...',
})
app.uploadFile(this.data.uuid, app.FileType.resumptionAcs, filePath).then(res => {
wx.hideLoading();
this.getFiles();
})
},
/**
* 获取图片
*/
getFiles: function () {
app.axios("GET", "common", "/upload/getFile", {
otcid: this.data.postData.emerEventId || this.data.uuid,
otctype: app.FileType.resumptionAcs
}).then(res => {
if (res.code == 1) {
this.data.files = res.data;
this.setData(this.data)
}
})
},
/**
* 删除图片
* @param {*} params
*/
deleteFile: function (e) {
var id = e.currentTarget.dataset.id;
wx.showModal({
title: '删除提示',
content: '是否要删除该附件?',
success: (res) => {
if (res.confirm) {
app.axios("GET", 'common', "/upload/delFile", {
documentId: id,
}).then(res => {
if (res.code == 1) {
this.getFiles();
}
})
}
}
})
},
/**
* 预览文件
*/
filePre: function (params) {
const url = params.currentTarget.dataset.url;
const imgs = [];
this.data.files.forEach(item => {
imgs.push(this.data.baseUrl + item.filepath)
})
wx.previewImage({
urls: imgs,
current: this.data.baseUrl + url
})
},
/**
* 开始时间
*/
bindDateChange: function (params) {
this.data.postData.startTime = params.detail.value;
this.setData(this.data)
},
/**
* 结束时间
*/
bindendTimeChange: function (params) {
this.data.postData.endTime = params.detail.value;
this.setData(this.data)
},
/**
* 查询所有类型
*/
getEmerEventType: function () {
app.axios("GET", "app", "/work/wkTypes",{classify:2}).then(res => {
if (res.code == 1) {
this.data.TypeData = res.data;
this.setData(this.data);
}
})
},
/**
* 查看应急上报事件详情
*/
getEmerEventDetail: function (id) {
app.axios("GET", "app", `/emerEvent/emerEventDetail/${id}`).then(res => {
if (res.code == 1) {
this.data.postData = res.data;
this.data.postData.emerTypeName;
for (let index = 0; index < this.data.TypeData.length; index++) {
if (this.data.TypeData[index].emerTypeName == res.data.emerTypeName) {
this.data.postData.type = index+1;
}
};
this.setData(this.data);
this.getFiles();
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.data.uuid = Utils.uuid();
this.data.userInfo = app.globalData.userInfo;
this.data.targetId = options.id
this.setData(this.data);
this.getEmerEventType();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})