jhwxapp/miniprogram/pageage/dangerousProject/index.js

267 lines
6.2 KiB
JavaScript

// pages/dangerousProject/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
stateNav:1,
timeline:[],
dangerNameList:[],
show: false,
loadShow:false,
loginName:'',
userName:'',
deptId:'',
projectName:'',
projectId:'',
allPoint:0,
outPoint:0,
comPoint:0,
fileList: [],
id:'',
initData:{}
},
//项目切换 返回值
onProjectSelect(e){
this.onClickShow();
let projectId = e.detail.id;
let projectName = e.detail.text;
app.globalData.projectId = projectId;
app.globalData.projectName = projectName;
this.setData({
projectId:projectId,
projectName:projectName,
dangerNameList:[],
dangerName:'',
timeline:[],
allPoint:0,
outPoint:0,
comPoint:0
})
this.onLoad();
},
onImagesArr(e){
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
//图片上传地址
url: app.globalData.reqUrl+'/weixin/security/fileUpload',
filePath: e.detail[0],
name: 'file',
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
formData: { user: 'test' },
success:res => {
// 上传完成需要更新 fileList
let data = JSON.parse(res.data);
let fileList = this.data.fileList
fileList.push({url: data.url});
this.setData({ fileList:fileList});
this.updateDanger(res.data,e.currentTarget.dataset.id)
},
});
},
showPopup() {
this.setData({ show: true });
},
onClose() {
this.setData({ show: false });
},
onClickShow() {
this.setData({ loadShow: true });
},
onClickHide() {
this.setData({ loadShow: false });
},
onSelectDangerName(e){
this.getProjectDanger(e.detail.id);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
var that = this;
//加载蒙版
that.onClickShow();
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success:function(res){
that.setData({
loginName:res.data.loginName,
userName:res.data.userName,
deptId:res.data.deptId,
projectName: app.globalData.projectName,
projectId:app.globalData.projectId,
initData:{text:app.globalData.projectName,id:app.globalData.projectId}
})
that.getProjectDangerPlan();
}
})
},
/**
* 危大工程计划
*/
getProjectDangerPlan(){
var that = this;
wx.request({
url: app.globalData.reqUrl+'/weixin/security/getProjectDangerPlan',
method: 'get',
data: {
deptId:this.data.deptId,
projectId:this.data.projectId
},
success: resData => {
this.onClickHide();
if(resData.data.code == 200){
let array = [];
for(let i = 0;i<resData.data.data.length;i++){
array.push({text:resData.data.data[i].danger_name,id:resData.data.data[i].id});
}
that.setData({
dangerNameList:array,
dangerName:array[0].text
})
that.getProjectDanger(resData.data.data[0].id);
}else{
that.setData({
dangerNameList:[],
dangerName:''
})
}
}
})
},
/**
* 危大工程列表
*/
getProjectDanger:function(danger_id){
wx.request({
url: app.globalData.reqUrl+'/weixin/security/getProjectDanger',
method: 'get',
data: {
deptId:this.data.deptId,
projectId:this.data.projectId,
danger_id:danger_id
},
success: resData => {
this.onClickHide();
if(resData.data.code == 200){
let timeline = resData.data.data.dangerList;
var flag = false;
timeline.map(x => {
if(x.fileUrl.length > 0){
x.type = 0;
}else{
if(!flag){
x.type = 1
flag = true;
}else{
x.type = 2;
}
}
let fileUrl = x.fileUrl;
for(let i = 0;i<fileUrl.length;i++){
if(fileUrl[i].url.substring(fileUrl[i].url.length-4,fileUrl[i].url.length) == '.pdf'){
fileUrl[i].suffix = "pdf";
}else{
fileUrl[i].suffix = "png";
}
}
})
this.setData({
timeline:timeline,
allPoint:resData.data.data.allPoint,
outPoint:resData.data.data.outPoint,
comPoint:resData.data.data.comPoint
})
}else{
this.setData({
timeline:[],
allPoint:0,
outPoint:0,
comPoint:0
})
}
}
})
},
/**
* 图片上传
*/
updateDanger:function(fileUrl,id){
wx.request({
header: {
'content-type': 'application/x-www-form-urlencoded'
},
url:app.globalData.reqUrl+'/weixin/security/updateDanger',
data:{
"deptId":this.data.deptId,
"projectId":this.data.projectId,
"id":id,
"fileUrl":fileUrl,
"subName":this.data.loginName,
},
method:"POST",
success:function(res){
console.log("======"+res.data.code);
}
})
},
/**
* 文件信息查看
* @param {*} e
*/
previewImg(e){
let suffix = e.currentTarget.dataset.suffix;
let url = e.currentTarget.dataset.url;
let images = [url];
if(suffix == 'pdf'){
wx.downloadFile({
url: url,
success: function (res) {
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
}
})
}
})
}else{
wx.previewImage({
current: url, //当前图片地址
urls: images, //所有要预览的图片的地址集合 数组形式
success: function(res) {},
fail: function(res) {},
complete: function(res) {},
})
}
},
/**
* 返回到技术管理
*/
goGCLB:function(){
wx.redirectTo({
url: '../../pages/technical-management/index'
})
},
})