jhwxapp/miniprogram/pages/xiangmugaikuang/index.js

715 lines
16 KiB
JavaScript
Raw Normal View History

2023-08-10 01:21:29 +08:00
import * as echarts from '../../ec-canvas/echarts';
const app = getApp();
//加载视频监控饼图
2024-03-09 14:01:46 +08:00
let datas_1 = [];
let formatNumber_1 = function (num) {
let reg = /(?=(\B)(\d{3})+$)/g;
return num.toString().replace(reg, ',');
}
function arrayobj_1(array, key) {
var resObj = {}
for (var i = 0; i < array.length; i++) {
resObj[array[i][key]] = array[i]
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
return resObj
}
function initChart_1(chart_1, datas_1) {
//定义参数
let objData_1 = arrayobj_1(datas_1, 'name');
let total_1 = datas_1.reduce((a, b) => {
return a + b.value * 1
2023-08-10 01:21:29 +08:00
}, 0);
2024-03-09 14:01:46 +08:00
let title_1 = '接入数';
var option_1 = {
color: ["#ffac50", "#ed6942", "#9e40ec", "#1f8efa", "#06c985"],
title: [{
text: '{val|' + formatNumber_1(total_1) + '} \n {name|' + title_1 + '} ',
top: '31%',
left: '20%',
textStyle: {
rich: {
name: {
fontSize: 14,
fontWeight: 'normal',
color: '#fff',
padding: [10, 0]
},
val: {
fontSize: 25,
fontWeight: 'bold',
color: '#0ad7ec',
padding: [0, 10]
}
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
}
2023-08-10 01:21:29 +08:00
}],
2024-03-09 14:01:46 +08:00
tooltip: {
trigger: 'item',
},
legend: {
orient: 'vertical',
top: "center",
right: "5%",
icon: 'circle',
data: ['一工区'],
textStyle: {
color: "#fff",
fontSize: 10
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
formatter(name) {
return `${name} ${objData_1[name].value}`
}
},
series: [{
type: 'pie',
radius: ['65%', '90%'],
center: ['30%', '50%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
emphasis: {
label: {
show: true,
fontSize: '14'
}
},
labelLine: {
show: false
},
hoverAnimation: false,
data: datas_1
}]
};
chart_1.setOption(option_1);
}
2023-08-10 01:21:29 +08:00
//机械设备饼图
2024-03-09 14:01:46 +08:00
let formatNumber_2 = function (num) {
let reg = /(?=(\B)(\d{3})+$)/g;
return num.toString().replace(reg, ',');
}
function arrayobj_2(Array, key) {
var resObj = {}
for (var i = 0; i < Array.length; i++) {
resObj[Array[i][key]] = Array[i]
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
return resObj
}
function initChart_2(chart_2, datas_2, datas_name) {
2023-08-10 01:21:29 +08:00
//定义参数
let objData_2 = arrayobj_2(datas_2, 'name');
let total_2 = datas_2.reduce((a, b) => {
return a + b.value * 1
}, 0);
let title_2 = '接入数';
var option_2 = {
color: ["#ffac50", "#ed6942", "#9e40ec", "#1f8efa", "#06c985"],
title: [{
text: '{val|' + formatNumber_2(total_2) + '} \n {name|' + title_2 + '} ',
top: '31%',
left: '20%',
textStyle: {
2024-03-09 14:01:46 +08:00
rich: {
name: {
fontSize: 14,
fontWeight: 'normal',
color: '#fff',
padding: [10, 0]
},
val: {
fontSize: 25,
fontWeight: 'bold',
color: '#0ad7ec',
padding: [0, 10]
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
}
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
}],
2023-08-10 01:21:29 +08:00
tooltip: {
trigger: 'item',
},
legend: {
2024-03-09 14:01:46 +08:00
orient: 'vertical',
top: "center",
right: "5%",
icon: 'circle',
data: datas_name,
textStyle: {
color: "#fff",
fontSize: 10
},
formatter(name) {
return `${name} ${objData_2[name].value}`
}
2023-08-10 01:21:29 +08:00
},
series: [{
2024-03-09 14:01:46 +08:00
type: 'pie',
radius: ['65%', '90%'],
center: ['30%', '50%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: '14'
}
},
labelLine: {
show: false
},
hoverAnimation: false,
data: datas_2
}]
2023-08-10 01:21:29 +08:00
};
chart_2.setOption(option_2);
}
//劳务管理
function initChart_3(chart_3, xData_3, yData_3) {
var option_3 = {
color: ['#5a8df6'],
tooltip: {
2024-03-09 14:01:46 +08:00
trigger: 'axis'
2023-08-10 01:21:29 +08:00
},
grid: {
2024-03-09 14:01:46 +08:00
top: '22%',
left: '3%',
right: '1%',
bottom: '0%',
containLabel: true
2023-08-10 01:21:29 +08:00
},
xAxis: [{
2024-03-09 14:01:46 +08:00
type: 'category',
boundaryGap: false,
data: xData_3,
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: 'rgba(39,51,75,0.8)'
}
},
axisLabel: {
color: '#8aa3ec',
rotate: 45,
textStyle: {
fontSize: 10
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
},
2023-08-10 01:21:29 +08:00
}],
yAxis: {
2024-03-09 14:01:46 +08:00
type: 'value',
name: "单位:个",
nameTextStyle: {
color: "#008fe9",
fontSize: 11
},
axisLabel: {
show: true,
textStyle: {
color: "#008fe9",
fontSize: 10
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(39,51,75,0.5)'
}
},
axisLine: {
show: true,
lineStyle: {
color: 'rgba(39,51,75,0.8)'
}
},
},
series: [{
type: 'line',
data: yData_3,
symbol: 'circle',
smooth: true,
lineStyle: {
color: '#5a8df6',
width: 2
},
}]
2023-08-10 01:21:29 +08:00
}
chart_3.setOption(option_3);
return chart_3;
}
Page({
/**
* 页面的初始数据
*/
data: {
2024-03-09 14:01:46 +08:00
active: 0,
2023-08-10 01:21:29 +08:00
show: false,
2024-03-09 14:01:46 +08:00
activeNames: ["1"],
2023-08-10 01:21:29 +08:00
ec_1: {
lazyLoad: true //动态加载
},
ec_2: {
lazyLoad: true
},
ec_3: {
lazyLoad: true
},
//参数——————————————————————————————————————
//组织架构id
2024-03-09 14:01:46 +08:00
deptId: '',
2023-08-10 01:21:29 +08:00
//项目的id
2024-03-09 14:01:46 +08:00
projectId: '',
2023-08-10 01:21:29 +08:00
//项目名称参数
2024-03-09 14:01:46 +08:00
projectNameArgs: '',
2023-08-10 01:21:29 +08:00
//项目信息
2024-03-09 14:01:46 +08:00
projectInfo: {},
projectUnitsList: [],
2023-08-10 01:21:29 +08:00
//视频接入数
2024-03-09 14:01:46 +08:00
videoNum: '',
2023-08-10 01:21:29 +08:00
//正常视频数
2024-03-09 14:01:46 +08:00
videoOnline: '',
2023-08-10 01:21:29 +08:00
//机械接入数
2024-03-09 14:01:46 +08:00
machineryNum: '',
2023-08-10 01:21:29 +08:00
//正常机械运行数
2024-03-09 14:01:46 +08:00
machineryOnline: '',
monthEarlyNum: '0',
yangchenCount: '0',
weather: '',
weatherPic: '',
temperature: '',
2023-08-10 01:21:29 +08:00
//加载模板参数
2024-03-09 14:01:46 +08:00
loadShow: false,
initData: {},
todoDb: 0,
approveDb: 0,
aq:0,
2023-08-10 01:21:29 +08:00
},
//项目切换 返回值
2024-03-09 14:01:46 +08:00
onProjectSelect(e) {
2023-08-10 01:21:29 +08:00
this.onClickShow();
let projectId = e.detail.id;
let projectName = e.detail.text;
app.globalData.projectId = projectId;
2024-03-09 14:01:46 +08:00
app.globalData.projectName = projectName;
2023-08-10 01:21:29 +08:00
this.setData({
2024-03-09 14:01:46 +08:00
projectId: projectId,
projectName: projectName
2023-08-10 01:21:29 +08:00
})
this.onLoad();
},
// 手风琴
onChange1(event) {
this.setData({
activeName: event.detail,
});
},
2024-03-09 14:01:46 +08:00
onOpen(event) {},
onClose(event) {},
2023-08-10 01:21:29 +08:00
//初始化视频监控饼图数据
init_one: function (datas_1) {
2024-03-09 14:01:46 +08:00
this.oneComponent.init((canvas, width, height, dpr) => {
2023-08-10 01:21:29 +08:00
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr //解决小程序视图模糊的问题,必写
});
initChart_1(chart, datas_1);
this.chart = chart;
return chart;
});
},
//初始化机械设备饼图数据
2024-03-09 14:01:46 +08:00
init_two: function (datas_2, datas_name) {
this.twoComponent.init((canvas, width, height, dpr) => {
2023-08-10 01:21:29 +08:00
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr //解决小程序视图模糊的问题,必写
});
2024-03-09 14:01:46 +08:00
initChart_2(chart, datas_2, datas_name);
2023-08-10 01:21:29 +08:00
this.chart = chart;
return chart;
});
},
2024-03-09 14:01:46 +08:00
2023-08-10 01:21:29 +08:00
//初始化劳务管理
2024-03-09 14:01:46 +08:00
init_three: function (xData_1, yData_1) {
this.threeComponent.init((canvas, width, height, dpr) => {
2023-08-10 01:21:29 +08:00
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr //解决小程序视图模糊的问题,必写
});
2024-03-09 14:01:46 +08:00
initChart_3(chart, xData_1, yData_1);
2023-08-10 01:21:29 +08:00
this.chart = chart;
return chart;
});
},
onClickShow() {
2024-03-09 14:01:46 +08:00
this.setData({
loadShow: false
});
2023-08-10 01:21:29 +08:00
},
onClickHide() {
2024-03-09 14:01:46 +08:00
this.setData({
loadShow: false
});
2023-08-10 01:21:29 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.onClickShow();
this.setData({
activeName: ["1"],
});
var that = this;
2024-03-09 14:01:46 +08:00
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success: function (res) {
2024-04-14 21:28:11 +08:00
if (options && options.showUser) {
//这里重新查询用户消息是否已授权
2024-04-21 13:08:16 +08:00
that.reUserOpenMsgId();
2024-04-14 21:28:11 +08:00
}
2024-03-09 14:01:46 +08:00
that.setData({
loginName: res.data.loginName,
nickName: res.data.nickName,
deptName: res.data.deptName,
roleName: res.data.roleName.split(',')[0],
projectId: app.globalData.projectId,
projectNameArgs: app.globalData.projectName,
initData: {
text: app.globalData.projectName,
id: app.globalData.projectId
}
})
that.awaitTask(res.data.minRoleId, res.data.deptId, res.data.loginName, res.data.userId);
}
})
//根据id获取组件
this.oneComponent = this.selectComponent('#mychart-one');
this.twoComponent = this.selectComponent('#mychart-two');
this.threeComponent = this.selectComponent('#mychart-three');
this.fourComponent = this.selectComponent('#mychart-four');
//项目基本信息
this.getProjectBaseInfo(app.globalData.projectId);
//项目管理信息
this.getProjectUnitList(app.globalData.projectId);
//视频数量
//this.getProjectVideoAll(app.globalData.projectId);
//机械的数据
//this.getMachineryNum(app.globalData.projectId);
//机械列表
//this.getMachineryList(app.globalData.projectId);
//视频的数据
//this.getVideoList(app.globalData.projectId);
2023-08-10 01:21:29 +08:00
},
2024-04-14 21:28:11 +08:00
/**
* 查询公众号消息授权
*/
2024-04-21 13:08:16 +08:00
reUserOpenMsgId(){
let userInfos = this.selectComponent("#userInfos");
userInfos.loadUserInfo();
2024-04-14 21:28:11 +08:00
},
2024-03-09 14:01:46 +08:00
// 底部导航
onChange(event) {
2023-08-10 01:21:29 +08:00
// event.detail 的值为当前选中项的索引
2024-03-09 14:01:46 +08:00
this.setData({
active: event.detail
});
2023-08-10 01:21:29 +08:00
},
//获取项目的基本数据
2024-03-09 14:01:46 +08:00
getProjectBaseInfo: function (even) {
2023-08-10 01:21:29 +08:00
wx.request({
2024-03-09 14:01:46 +08:00
url: app.globalData.reqUrl + '/wechat/project/getProjectFoundation',
method: 'GET',
data: {
id: even
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
success: resData => {
this.onClickHide()
if (resData.data.planStartTime) {
resData.data.planStartTime = resData.data.planStartTime.split("T")[0];
}
if (resData.data.actualStartTime) {
resData.data.actualStartTime = resData.data.actualStartTime.split("T")[0];
}
if (resData.data.planCompletedTime) {
resData.data.planCompletedTime = resData.data.planCompletedTime.split("T")[0];
}
this.setData({
projectInfo: resData.data
})
//环境监测
//this.selectEnvirData(even);
//加载天气信息
//this.getWeatherData(resData.data.longitude,resData.data.latitude)
2023-08-10 01:21:29 +08:00
}
})
},
//加载天气数据
2024-03-09 14:01:46 +08:00
getWeatherData: function (even1, even2) {
var that = this;
wx.request({
url: app.globalData.reqUrl + '/weixin/applets/selectWeather',
method: "GET",
data: {
lng: even1,
lat: even2,
},
success: function (weatherRes) {
that.setData({
weather: weatherRes.data.weather,
weatherPic: weatherRes.data.weatherPic,
temperature: weatherRes.data.temperature
2023-08-10 01:21:29 +08:00
})
2024-03-09 14:01:46 +08:00
}
})
},
2023-08-10 01:21:29 +08:00
//获取项目的管理信息
2024-03-09 14:01:46 +08:00
getProjectUnitList: function (projectId) {
var that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/project/getProjectUnitList',
method: 'GET',
data: {
projectId: projectId
},
success: resData => {
that.onClickHide()
that.setData({
projectUnitsList: resData.data
})
}
})
2023-08-10 01:21:29 +08:00
},
// 获取项目下的视频数
2024-03-09 14:01:46 +08:00
getProjectVideoAll: function (even) {
2023-08-10 01:21:29 +08:00
wx.request({
2024-03-09 14:01:46 +08:00
url: app.globalData.reqUrl + '/weixin/video/getProjectVideoNum',
2023-08-10 01:21:29 +08:00
method: 'get',
data: {
2024-03-09 14:01:46 +08:00
projectName: even
2023-08-10 01:21:29 +08:00
},
success: resData => {
2024-03-09 14:01:46 +08:00
this.setData({
videoNum: resData.data.videoAll,
videoOnline: resData.data.videoOnline
})
2023-08-10 01:21:29 +08:00
}
})
},
// 获取机械的数据
2024-03-09 14:01:46 +08:00
getMachineryNum: function (event) {
wx.request({
url: app.globalData.reqUrl + '/mkl/machinery/getMachineryDataWest',
data: {
"projectId": event
},
method: 'get',
success: resData => {
this.setData({
machineryNum: resData.data.allNum,
machineryOnline: resData.data.onlineNum
})
}
})
2023-08-10 01:21:29 +08:00
},
//机械的列表,名称
2024-03-09 14:01:46 +08:00
getMachineryList: function (event) {
2023-08-10 01:21:29 +08:00
var that = this;
2024-03-09 14:01:46 +08:00
wx.request({
url: app.globalData.reqUrl + '/mkl/machinery/getMachineryListWest',
data: {
"projectId": event
},
method: 'GET',
success: resData => {
if (resData.data == '') {
that.init_two([{
"value": "0",
"name": ""
}]);
} else {
that.init_two(resData.data);
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
}
})
2023-08-10 01:21:29 +08:00
},
//获取视频的列表,名称
2024-03-09 14:01:46 +08:00
getVideoList: function (even) {
2023-08-10 01:21:29 +08:00
var that = this;
wx.request({
2024-03-09 14:01:46 +08:00
url: app.globalData.reqUrl + '/weixin/video/getProjectVideoListEc',
method: 'GET',
data: {
projectName: even
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
success: resData => {
2023-08-10 01:21:29 +08:00
that.onClickHide();
2024-03-09 14:01:46 +08:00
if (resData.data.length > 0) {
2023-08-10 01:21:29 +08:00
that.init_one(resData.data);
2024-03-09 14:01:46 +08:00
}
2023-08-10 01:21:29 +08:00
}
})
},
//查询劳务人员出勤数据
2024-03-09 14:01:46 +08:00
selectEnvirData: function (even) {
var that = this;
wx.request({
url: app.globalData.reqUrl + '/weixin/userinfo/selectAttendanceNum',
method: "GET",
data: {
projectId: even,
},
success: function (hjyj) {
that.setData({
monthEarlyNum: hjyj.data.userCount,
yangchenCount: hjyj.data.userCount
})
}
})
//查询出最近一周劳务人员考勤人数
wx.request({
url: app.globalData.reqUrl + '/weixin/userinfo/selectLabourDayByProjectId',
method: "GET",
data: {
projectId: even
},
success: function (sspm) {
var createTime = [];
var userCount = [];
for (var i = 0; i < sspm.data.length; i++) {
createTime.push(sspm.data[i].createTime);
userCount.push(sspm.data[i].userCount);
2023-08-10 01:21:29 +08:00
}
2024-03-09 14:01:46 +08:00
that.init_three(createTime, userCount);
}
})
2023-08-10 01:21:29 +08:00
},
/**
* 拨打电话
* @param {*} event
*/
2024-03-09 14:01:46 +08:00
calling: function (event) {
let callPhone = event.currentTarget.dataset.phone;
2023-08-10 01:21:29 +08:00
wx.makePhoneCall({
2024-03-09 14:01:46 +08:00
phoneNumber: callPhone,
success: function () {
2023-08-10 01:21:29 +08:00
console.log("拨打电话成功!")
},
2024-03-09 14:01:46 +08:00
fail: function () {
2023-08-10 01:21:29 +08:00
console.log("拨打电话失败!")
}
})
},
//跳转到安全管控
2024-03-09 14:01:46 +08:00
XMSP: function () {
wx.redirectTo({
url: '../safety_manage/index'
})
2023-08-10 01:21:29 +08:00
},
2024-03-09 14:01:46 +08:00
//跳转到质量管理
ZLGL: function () {
wx.redirectTo({
url: '../quality_manage/index'
})
2023-08-10 01:21:29 +08:00
},
2024-03-19 23:25:38 +08:00
2024-03-09 14:01:46 +08:00
//跳转到进度管理
JDGL2: function () {
//app.toast("敬请期待!");
wx.redirectTo({
url: '../../pageage/project_schedule/list/index'
})
2023-08-10 01:21:29 +08:00
},
//跳转到更多功能
2024-03-09 14:01:46 +08:00
GDGN: function () {
2023-08-10 01:21:29 +08:00
wx.redirectTo({
2024-03-19 23:25:38 +08:00
url: '../gengduogongneng/index'
2024-03-09 14:01:46 +08:00
})
},
2024-03-19 23:25:38 +08:00
2024-03-09 14:01:46 +08:00
//返回到地图页面
GOMAP: function () {
wx.redirectTo({
url: '../map/map',
})
2023-09-02 23:45:35 +08:00
},
2023-08-10 01:21:29 +08:00
2024-03-09 14:01:46 +08:00
//返回到工程列表页面
goGCLB: function () {
wx.redirectTo({
2024-03-19 23:25:38 +08:00
url: '../gongchengliebiao/index'
2024-03-09 14:01:46 +08:00
})
},
2023-08-10 01:21:29 +08:00
2023-09-17 15:28:13 +08:00
//查询当前登录人的代办任务
2024-03-09 14:01:46 +08:00
awaitTask(minRoleId, deptId, loginName, userId) {
2023-09-17 15:28:13 +08:00
let param = {
2024-03-09 14:01:46 +08:00
"businessKey": app.globalData.projectId,
"nowRole": minRoleId,
"nowDept": deptId,
"nowUserName": loginName,
"nowUser": userId,
"activeName": "await"
2023-09-17 15:28:13 +08:00
}
var that = this;
wx.request({
url: app.globalData.reqUrl + '/wechat/flowTask/myAwaitFlowTaskListCount',
2024-03-09 14:01:46 +08:00
data: param,
2023-09-17 15:28:13 +08:00
method: "post",
success: function (res) {
res = res.data;
2024-03-09 14:01:46 +08:00
if (res.code == "200") {
2023-09-17 15:28:13 +08:00
that.setData({
2024-04-21 13:08:16 +08:00
todoDb: res.data.todo+res.data.approveLZYJ,
2024-03-09 14:01:46 +08:00
approveDb: res.data.approve+res.data.zlCount,
aq:res.data.aqCount,
})
2023-09-17 15:28:13 +08:00
}
}
})
},
2024-03-09 14:01:46 +08:00
})