339 lines
7.3 KiB
JavaScript
339 lines
7.3 KiB
JavaScript
// 上报动态
|
||
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,
|
||
showTaskPop: false,
|
||
TypeData: [],
|
||
postData: {}
|
||
},
|
||
|
||
/**
|
||
* 时间
|
||
*/
|
||
bindDateChange: function (params) {
|
||
const name = params.currentTarget.dataset.name;
|
||
this.data.postData[name] = params.detail.value;
|
||
this.setData(this.data)
|
||
},
|
||
|
||
/**
|
||
* 显示/关闭任务弹窗
|
||
*/
|
||
popTaskModal: function (params) {
|
||
const type = params.currentTarget.dataset.type;
|
||
this.data[type] = !this.data[type];
|
||
this.setData(this.data)
|
||
},
|
||
|
||
/**
|
||
* 显示/关闭弹窗
|
||
*/
|
||
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.type = index + 1;
|
||
this.data.postData.typeId = this.data.TypeData[index].typeId;
|
||
this.data.showTypePop = false;
|
||
this.setData(this.data)
|
||
},
|
||
|
||
/**
|
||
* 输入内容
|
||
*/
|
||
inputContent: function (e) {
|
||
const name = e.currentTarget.dataset.name;
|
||
this.data.postData[name] = e.detail.value;
|
||
},
|
||
|
||
/**
|
||
* 选择文件
|
||
*/
|
||
chooseFile: function () {
|
||
wx.chooseImage({
|
||
count: 1,
|
||
type: 'all',
|
||
success: (res) => {
|
||
const tempFilePaths = res.tempFiles;
|
||
const path = tempFilePaths[0].path;
|
||
this.postImg(path)
|
||
}
|
||
})
|
||
},
|
||
chooseMessageFile() {
|
||
wx.chooseMessageFile({
|
||
count: 1, // 默认9,这里设置为1表示只选择一个文件
|
||
type: 'file', // 指定文件类型,这里设置为 'file' 表示可以选择所有类型的文件
|
||
success: (res) => {
|
||
// 用户成功选择文件后执行的回调
|
||
if (res.tempFiles.length > 0) {
|
||
// 获取用户选择的文件信息
|
||
const file = res.tempFiles[0];
|
||
const filePath = file.path; // 文件的本地路径
|
||
// 在这里可以对文件进行进一步的处理,例如上传到服务器等
|
||
this.postImg(filePath)
|
||
} else {
|
||
// 用户没有选择文件
|
||
wx.showToast({
|
||
title: '未选择文件',
|
||
icon: 'none',
|
||
duration: 1000
|
||
});
|
||
}
|
||
},
|
||
fail: function (err) {
|
||
// 选择文件失败的回调
|
||
wx.showToast({
|
||
title: '选择文件失败',
|
||
icon: 'none',
|
||
duration: 1000
|
||
});
|
||
}
|
||
});
|
||
},
|
||
/**
|
||
* 阅览文件
|
||
*/
|
||
openread: function (e) {
|
||
const item = e.currentTarget.dataset.item;
|
||
const extension = item.filepath.split('.').pop().toLowerCase();
|
||
if(extension == 'jpg' || extension == 'png' ){
|
||
wx.previewImage({
|
||
urls: [app.FILE_SERVER_URL + item.filepath] // 需要预览的图片http链接列表
|
||
})
|
||
return
|
||
}
|
||
if(extension == 'mp4'){
|
||
this.setData({
|
||
videoSrc:app.FILE_SERVER_URL + item.filepath,
|
||
video: true
|
||
});
|
||
return
|
||
}
|
||
wx.downloadFile({
|
||
url: app.FILE_SERVER_URL + item.filepath, //仅为示例,并非真实的资源
|
||
success(res) {
|
||
if (res.statusCode === 200) {
|
||
wx.openDocument({
|
||
filePath: res.tempFilePath,
|
||
fail: function (res) {
|
||
wx.showToast({
|
||
title: '不支持此格式',
|
||
icon: 'none',
|
||
duration: 1000
|
||
});
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
/**
|
||
* 获取工作类型
|
||
*/
|
||
getType: function () {
|
||
app.axios("GET", "app", "/work/wkTypes", {
|
||
classify: 2
|
||
}).then(res => {
|
||
if (res.code == 1) {
|
||
this.data.TypeData = res.data;
|
||
this.setData(this.data)
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 上传图片
|
||
*/
|
||
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.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();
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 发布
|
||
*/
|
||
push: function () {
|
||
this.data.postData.userId = app.globalData.userInfo.userId;
|
||
this.data.postData.dynamicsId = this.data.uuid;
|
||
if (!this.data.postData.title) {
|
||
wx.showToast({
|
||
title: '请输入工作标题',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
if (!this.data.postData.typeId) {
|
||
wx.showToast({
|
||
title: '请选择工作类型',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
if (!this.data.postData.detail) {
|
||
wx.showToast({
|
||
title: '请输入内容',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
if (!this.data.postData.startTime || !this.data.postData.endTime) {
|
||
wx.showToast({
|
||
title: '请设置时间',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
app.axios("POST", "app", "/work/wkDynamicsAdd", this.data.postData).then(res => {
|
||
if (res.code == 1) {
|
||
wx.showToast({
|
||
title: '发布成功',
|
||
icon: 'none'
|
||
})
|
||
setTimeout(() => {
|
||
wx.navigateBack()
|
||
}, 1500);
|
||
} else {
|
||
wx.showToast({
|
||
title: res.message,
|
||
icon: 'none'
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 预览文件
|
||
*/
|
||
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
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
this.data.isUserDetail = options.user;
|
||
this.data.uuid = Utils.uuid();
|
||
this.setData(this.data)
|
||
this.getType();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |