404 lines
11 KiB
JavaScript
404 lines
11 KiB
JavaScript
// pages/workReport/workReport.js
|
||
const {API: $api} = require("../../utils/api");
|
||
import {base_url} from '../../utils/http';
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
searchForm:{
|
||
type:'',
|
||
target:'',
|
||
targetId:''
|
||
},
|
||
//搜索
|
||
typeOpt:[
|
||
{text:'请选择类型',value:''},
|
||
{text:'党务及意识形态',value:'党务及意识形态'},
|
||
{text:'党风廉政建设',value:'党风廉政建设'},
|
||
{text:'日常考核指标',value:'日常考核指标'},
|
||
{text:'季度考核指标',value:'季度考核指标'},
|
||
],
|
||
typeShow:false,
|
||
targetOpt:[],
|
||
targetShow:false,
|
||
mainActiveIndex:0,
|
||
activeId:null,
|
||
detailData:null,
|
||
fileList:[],
|
||
isRadio:false
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
if(options && JSON.stringify(options) !== '{}'){
|
||
this.setData({
|
||
"searchForm.type":options.type,
|
||
isRadio:options.isRadio?options.isRadio:false
|
||
})
|
||
if(this.data.isRadio){
|
||
this.loadDetailData({
|
||
pageNum:1,
|
||
pageSize:10,
|
||
type:options.type,
|
||
id:options.id
|
||
});
|
||
}else{
|
||
this.loadTargetData({type:options.type});
|
||
}
|
||
}
|
||
},
|
||
|
||
//类型搜索
|
||
handleTypeOpen(){
|
||
this.setData({
|
||
typeShow:true
|
||
})
|
||
},
|
||
handleTypeClose(){
|
||
this.setData({
|
||
typeShow:false
|
||
})
|
||
},
|
||
handleTypeChange(e){
|
||
this.setData({
|
||
"searchForm.type": e.detail,
|
||
typeShow:false,
|
||
targetOpt:[],
|
||
mainActiveIndex:0,
|
||
activeId:null,
|
||
detailData:null,
|
||
"searchForm.target":""
|
||
});
|
||
this.loadTargetData({type:this.data.searchForm.type});
|
||
},
|
||
handleTypeClick(event) {
|
||
const { name } = event.currentTarget.dataset;
|
||
this.setData({
|
||
"searchForm.type": name,
|
||
typeShow:false,
|
||
targetOpt:[],
|
||
mainActiveIndex:0,
|
||
activeId:null,
|
||
detailData:null,
|
||
"searchForm.target":""
|
||
});
|
||
this.loadTargetData({type:this.data.searchForm.type});
|
||
},
|
||
|
||
//指标搜索
|
||
handleTargetOpen(){
|
||
this.setData({
|
||
targetShow:true
|
||
})
|
||
},
|
||
handleTargetClose(){
|
||
this.setData({
|
||
targetShow:false
|
||
})
|
||
},
|
||
handleTargetNav(e){
|
||
this.setData({
|
||
mainActiveIndex:e.detail.index
|
||
})
|
||
},
|
||
handleTargettem(e){
|
||
this.setData({
|
||
"searchForm.target":e.detail.text,
|
||
"searchForm.targetId":e.detail.id,
|
||
"searchForm.shotName":e.detail.shotName,
|
||
activeId:e.detail.id,
|
||
targetShow:false,
|
||
})
|
||
this.loadDetailData({
|
||
pageNum:1,
|
||
pageSize:10,
|
||
type:this.data.searchForm.type,
|
||
id:this.data.searchForm.targetId
|
||
});
|
||
},
|
||
|
||
//上传之前
|
||
handleBeforeUpload(e){
|
||
const { file, callback } = e.detail;
|
||
if(file.url.indexOf('.jpg') > -1 || file.url.indexOf('.png') > -1 || file.url.indexOf('.pdf') > -1 ||
|
||
file.url.indexOf('.jpg') > -1 || file.url.indexOf(".doc")>-1 || file.url.indexOf(".docx")>-1 || file.url.indexOf(".xlsx")>-1 ||
|
||
file.url.indexOf(".xls")>-1){
|
||
callback(true);
|
||
}else{
|
||
wx.showToast({
|
||
title:'支持jpg,png,pdf,doc,docx,xlsx,xls格式的文件!',
|
||
duration:2000,
|
||
icon:'none'
|
||
})
|
||
callback(false);
|
||
}
|
||
},
|
||
//上传文件数据
|
||
handleUploadFile(e){
|
||
const { file } = e.detail;
|
||
let _fileList = this.data.fileList;
|
||
_fileList.push({
|
||
name:file.name,
|
||
url:file.url,
|
||
index:_fileList.length
|
||
});
|
||
this.setData({
|
||
fileList:_fileList
|
||
})
|
||
},
|
||
|
||
//上传图片数据
|
||
handleUploadImg(){
|
||
let _this = this;
|
||
wx.chooseMedia({
|
||
count:3,
|
||
mediaType:['image','video'],
|
||
sourceType:['album', 'camera'],
|
||
maxDuration:60, //视频拍摄时长,3s-60s
|
||
success(res){
|
||
let _isUpload = false;
|
||
res.tempFiles.forEach(item => {
|
||
if(item.size > 10485760){
|
||
_isUpload = true;
|
||
}
|
||
});
|
||
if(_isUpload){
|
||
wx.showToast({
|
||
title:'图片或视频不能大于10MB!',
|
||
icon:'none',
|
||
duration:1500
|
||
})
|
||
return false;
|
||
}
|
||
let _filesArr = res.tempFiles;
|
||
let _fileList = _this.data.fileList;
|
||
_filesArr.forEach(item => {
|
||
let _lastNum = item.tempFilePath.lastIndexOf('/')+1;
|
||
let _name =item.tempFilePath.substr(_lastNum,item.tempFilePath.length);
|
||
_fileList.push({
|
||
name:_name,
|
||
url:item.tempFilePath,
|
||
index:_fileList.length
|
||
})
|
||
})
|
||
_this.setData({
|
||
fileList:_fileList
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
//预览文件
|
||
handlePreView(e){
|
||
let _url = e.currentTarget.dataset.url;
|
||
if(_url.indexOf('.jpg') > -1 || _url.indexOf('.png') > -1){ //预览图片
|
||
wx.previewImage({
|
||
urls:[_url],
|
||
current:_url
|
||
})
|
||
}else{ //下载文件
|
||
wx.downloadFile({
|
||
url: _url, //仅为示例,并非真实的资源
|
||
success (res) {
|
||
if(res.statusCode === 200){
|
||
wx.openDocument({
|
||
filePath: res.tempFilePath,
|
||
success: function (res) {
|
||
console.log(res,'打开文档成功')
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
},
|
||
//删除文件
|
||
handleDelFile(e){
|
||
let _index = e.currentTarget.dataset.index;
|
||
let _fileList = this.data.fileList;
|
||
_fileList.forEach((val,idx) => {
|
||
if(val.index === _index){
|
||
_fileList.splice(idx,1);
|
||
}
|
||
});
|
||
_fileList.forEach((val,idx) => {
|
||
val.index = idx;
|
||
})
|
||
this.setData({
|
||
fileList:_fileList
|
||
})
|
||
},
|
||
//封装单个上传的方法
|
||
uploadFile(params){
|
||
return new Promise((resolve, reject) => {
|
||
wx.uploadFile({
|
||
url: base_url+"/common/upload",
|
||
filePath: params.url,
|
||
name: 'file',
|
||
success: function(data){
|
||
resolve(data);
|
||
},
|
||
fail(data) {
|
||
reject(data);
|
||
}
|
||
})
|
||
})
|
||
},
|
||
//批量上传多个文件的方法
|
||
uploadFiles(fileList){
|
||
let promises = fileList.map(item => this.uploadFile(item));
|
||
return Promise.all(promises);
|
||
},
|
||
//保存数据
|
||
handleSubmit(){
|
||
let _this = this;
|
||
if(!_this.data.detailData){
|
||
wx.showToast({
|
||
title:'请先查询上方汇报数据!',
|
||
duration:1500,
|
||
icon:'none'
|
||
})
|
||
return false;
|
||
}
|
||
if(_this.data.fileList.length === 0){
|
||
wx.showToast({
|
||
title:'请上传附件!',
|
||
duration:1500,
|
||
icon:'none'
|
||
})
|
||
return false;
|
||
}
|
||
let _data = _this.data.detailData;
|
||
let _files = [];
|
||
let _fileList = _this.data.fileList;
|
||
_this.uploadFiles(_fileList).then(obj => {
|
||
obj.forEach(item => {
|
||
let _data = JSON.parse(item.data);
|
||
_files.push(_data.fileName);
|
||
})
|
||
let _submitForm = {
|
||
header:_data.header,
|
||
deptName:_data.deptName,
|
||
shotName:_data.shotName,
|
||
remark:_data.remark,
|
||
id:_data.id,
|
||
files:_files.join(',')
|
||
};
|
||
$api.commit(_submitForm).then(res => {
|
||
if(res.code === 0){
|
||
wx.showToast({
|
||
title:'保存成功',
|
||
duration:1500
|
||
});
|
||
setTimeout(function () {
|
||
if(_this.data.isRadio){
|
||
wx.navigateBack();
|
||
}else{
|
||
_this.setData({
|
||
"searchForm.target":'',
|
||
"searchForm.targetId":'',
|
||
targetOpt:[],
|
||
mainActiveIndex:0,
|
||
activeId:null,
|
||
detailData:null,
|
||
fileList:[]
|
||
})
|
||
_this.loadTargetData({type:_this.data.searchForm.type});
|
||
}
|
||
},1500)
|
||
}else{
|
||
wx.showToast({
|
||
title:res.msg,
|
||
duration:1500,
|
||
icon:'none'
|
||
});
|
||
}
|
||
})
|
||
})
|
||
|
||
},
|
||
|
||
//加载指标
|
||
loadTargetData(param){
|
||
let _this = this;
|
||
$api.queryTree(param).then(res => {
|
||
if(res.code === 0){
|
||
res.data.forEach((item,index) => {
|
||
item.index = index;
|
||
})
|
||
_this.setData({
|
||
targetOpt:res.data
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
//加载详情数据
|
||
loadDetailData(param){
|
||
let _this = this;
|
||
$api.queryList(param).then(res => {
|
||
if(res.code === 0){
|
||
let _data = null;
|
||
if(res.rows.length>0){
|
||
_data = res.rows[0];
|
||
}
|
||
_this.setData({
|
||
detailData:_data
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
}) |