import React, { useState, useEffect, useRef, Component,useMemo } from 'react'
import { connect } from 'dva'
import storage from '../utils/storage'
import { initFilter, addRuleAndGroups, guid, extendInclude, extendRule, extend } from "../utils/common"
import './home.less'
// 组件库
import { Table, Card,Modal,List,Avatar, Row,Collapse, Col, Icon, Button, Input, DatePicker, Form, Select, notification, Divider,Tabs,Tag, message } from 'antd';
import { Chart, Geom, Axis, Tooltip, Legend } from "bizcharts";
import FormPage from '../components/FormPage'
import backlog from '../assets/home/backlog.png';
import userPicture from '../assets/home/it.jpg';
import backlog_i from '../assets/home/backlog_icon.png';
import styles from './dashboard.css';
// import Slider from "react-slick";
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
import moment from 'moment';
import flow from '../assets/home/flow.png';
import flow_i from '../assets/home/flow_icon.png';
import finished from '../assets/home/finished.png';
import finished_i from '../assets/home/finished_icon.png';
import remind from '../assets/home/remind.png';
import remind_i from '../assets/home/remind_icon.png';
import noticeImg from '../assets/home/noticeImg.jpg';
import scoreImg from '../assets/home/score.jpg';
import echarts from 'echarts';
import config from '../config'
import { routerRedux } from 'dva/router'
const { TabPane } = Tabs;
const { Panel } = Collapse;
const Option = Select.Option;
const RangePicker = DatePicker.RangePicker
const FormItem = Form.Item
const formItemLayout = {
labelCol: { span: 6 },
wrapperCol: { span: 14 },
};
// window.location.href="http://47.122.43.22:9100"
const openNotification = placement => {
notification.info({
duration: null,
top: 43,
message: `签名照上传提示:`,
description:
'您还没上传自己的签名照片,请在我的资料中尽快上传您的签名照!',
placement,
});
};
const openNotificationMobile = placement => {
notification.info({
duration: 20,
message: `友情提示:`,
description:
'您当前用的是手机在访问,为有更好体验,建议使用电脑访问!',
placement,
});
};
class HomeMobileNew extends React.Component {
constructor(props) {
super(props);
// props.matchLogin=true;
this.state = {
visible: false,
btnDisplay:'block',
btnViewDisplay:'none',
btnTodayDisplay:'none',
noticeTitle: '',
tmpData: {},
tableKey: "1",
pagination: {},
retData: [],
chartData: [],
favorMenus:[],
tableData: [{//工作台四个展示模块
key: '1',
bgImg: backlog,
title: '待办事项',
total: '0',
iconImg: backlog_i,
iconDisplay: 'block',
},
{
key: '2',
bgImg: flow,
title: '已办事项',
total: '0',
iconImg: flow_i,
iconDisplay: 'none',
},
// {
// key: '4',
// bgImg: remind,
// title: '待办超时',
// total: '0',
// iconImg: remind_i,
// iconDisplay: 'none',
// },
{
key: '3',
bgImg: finished,
title: '今日提醒',
total: '0',
iconImg: finished_i,
iconDisplay: 'none',
}
,
],
querySearch: {},//搜索集合
isModalVisible: false,
isModalVisible6: false,
qty:5,
departmentName: "",
searchVisible: false, //弹窗显示
searchTodayVisible: false, //弹窗显示
};
this.activeMenu = null;
};
componentDidMount() {
// if (window.navigator.userAgent.indexOf("Windows") < 1) {
// openNotificationMobile('bottomRight');
// }
this.getBaseInfoData(1, "1", 5);
this.getMenuData();
this.getTeam();
//this.setMessageData();
// this.targetCheck();//个人指标考核(统计图)
//this.defectTreatment();//隐患整改(统计图)
//this.jobType();//岗位风险类别(统计图)
//this.mainJobPie();//主要工作分布(饼图)
//this.delayJobBar();// 超期事务(柱状图图)
//定时器功能,暂时不开启
//this.timerID = setInterval(() => this.reloadData(), 50000);
//this.showModalSign(); //验证是否有上传签名
this.riskLevel();//岗位风险等级(饼图)
};
getTeam = () => {
var userId = storage('lacal').getItem('userid')?.val; //登录后有存储登录信息
var orgId = storage('lacal').getItem('webOrgId')?.val; //登录后有存储登录信息
let json = initFilter(orgId)
extendRule(json, 'ID', 1, userId)
extendInclude(json, "Nav_Department")
this.props.dispatch({
type: 'app/getDataByPost',
payload: json,
url: 'FM/User/Get',
onComplete: (ret) => {
if (ret && ret.Nav_Department) {
this.setState({
departmentName: ret.Nav_Department.NAME
});
this.targetCheck();//班组作业情况(统计图)
}
}
});
};
getMenuData = () => {
let favorMenus = storage('lacal').getItem('favorMenus')?.val;
let storageDatas = favorMenus ?? [];
if(storageDatas.length > 0)
{
this.setState({
favorMenus: storageDatas,//data.Data,
})
storage('lacal').setItem('favorMenus', storageDatas)
}
else
{
let roles = this.props.login.roles;
let menus =[];
roles?.map(t=>{
t.Nav_MenuPermissions?.map(t1=>{
menus.push(t1.MENU_ID);
})
})
let userName=this.props.login.user?.NAME;
let json = initFilter(this.props.login.OrgId,"", "NUM", "asc");
extendRule(json, 'IS_MOBILE_MENU', 1, true)
this.props.dispatch({
type: 'app/getDataByPost',
url: "PF/Menu/OrderPaged",
payload: json,
onlyData: false,
onComplete: (data) => {
let datas=[];
// if(userName && userName.indexOf("管理员") !== -1)
// {
// datas=data.Data;
// }
// else
// {
// data.Data.map(t=>{
// if(menus.includes(t.ID))
// {
// datas.push(t)
// }
// })
// }
datas=data.Data;
this.setState({
favorMenus: datas,//data.Data,
})
storage('lacal').setItem('favorMenus', datas)
}
})
}
}
handleActiveMenu = (menu) => {
this.activeMenu=menu
this.props.history.push({ pathname: `/main/${menu.ID}` })
}
handleMore = () => {
let qtyTemp =this.state.qty + 5 ;
this.getBaseInfoData(1, this.state.tableKey, qtyTemp);
this.setState({
qty:qtyTemp
})
}
handleViewMore = () => {
this.getBaseInfoData(1,"2", 10000000);
this.setState({
searchVisible: true,
searchTodayVisible: false, //弹窗显示
querySearch: {}
})
}
handleTodayMore = () => {
this.getBaseInfoData(1,"3", 10000000);
this.setState({
searchVisible: false,
searchTodayVisible: true, //弹窗显示
querySearch: {}
})
}
//班组作业完成情况统计图
targetCheck = () => {
const { departmentName } = this.state;
const userInfo = storage('lacal').getItem('webUserInfo').val;
let json = initFilter(this.props.login.OrgId, "", "WAITTING_COUNT", "desc");
this.props.dispatch({
type: 'app/getDataByPost',
url: "FM/DepartmentCompletion/OrderEntities",
payload: json,
onlyData: false,
onComplete: (data) => {
if (data && data.IsSuccessful) {
// let enumsTemp = this.enums;
// let formTypeEnums = enumsTemp ?enumsTemp.find(item => item.EnumName === "BIFormType"):[];
let formName = [];
let wattingQty = [];
let finishQty = [];
let totalQty = [];
let WattingRate = [];
let finishRate = [];
let result = data.Data.filter(t => t.TEAM_NAME == departmentName);
if(result)
{
result.forEach(item => {
// let enums = formTypeEnums && formTypeEnums.options?formTypeEnums.options.find(t => t.value === item.FORM_TYPE):[];
// formName.push(enums?enums.label:item.FORM_TYPE);
formName.push(item.FORM_NAME);
wattingQty.push(item.WAITTING_COUNT);
finishQty.push(item.FINISH_COUNT);
totalQty.push(item.TOTAL_COUNT);
let finishRateTemp = (item.FINISH_COUNT / item.TOTAL_COUNT * 100).toFixed(2);
let WattingRateTemp = (item.WAITTING_COUNT / item.TOTAL_COUNT * 100).toFixed(2);
finishRate.push(finishRateTemp);
WattingRate.push(WattingRateTemp);
})
var teamPre=result.filter(t => t.FORM_NAME == "班前会议");
if(teamPre.length === 0)
{
formName.push("班前会议");
finishRate.push(0);
WattingRate.push(100);
}
var teamCur=result.filter(t => t.FORM_NAME == "岗位当班");
if(teamCur.length === 0)
{
formName.push("岗位当班");
finishRate.push(0);
WattingRate.push(100);
}
var teamAft=result.filter(t => t.FORM_NAME == "岗位交接班");
if(teamAft.length === 0)
{
formName.push("岗位交接班");
finishRate.push(0);
WattingRate.push(100);
}
}
let myChart = echarts.init(document.getElementById('targetCheck'));
myChart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
// formatter:function (params) {
// console.log(params); // 当我们想要自定义提示框内容时,可以先将鼠标悬浮的数据打印出来,然后根据需求提取出来即可
// let firstParams = params[0];
// let sndParams = params[1];
// let endParams = params[2];
// return firstParams.seriesName +' ' + firstParams.value +'
' +sndParams.seriesName +' ' + sndParams.value +'
' + endParams.seriesName +' ' + endParams.value;
// }
},
grid: {
left: '3%',
right: '4%',
top: '3%',
containLabel: true
},
xAxis: {
type: 'value',
splitLine: {
show: false,
lineStyle: {
color: '#172749'
}
},
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
show: true,
interval: 0,
formatter: '{value} %', // 给每个数值添加%
// fontSize: '22'
},
},
legend: {
data: ['完成率', '未完成'],
bottom: '35px'
},
yAxis: {
type: 'category',
axisTick: {
show: false
},
axisLine: {
show: false
},
splitLine: {
show: false,
lineStyle: {
color: '#172749'
}
},
data: formName,
},
series: [
// {
// name: '总数',
// type: 'bar',
// stack: '',
// label: {
// show: true,
// position: 'right',
// color: '#000',
// },
// data: totalQty,
// barGap: '-100%',
// z:-1,
// itemStyle: {
// normal: {
// color: 'rgba(128, 128, 128, 0.3)'
// }
// },
// },
// {
// name: '已办',
// type: 'bar',
// stack: '',
// label: {
// show: true,
// position: 'right',
// color: '#000',
// },
// data: finishQty,
// barGap: '-100%',
// z:-1,
// itemStyle: {
// normal: {
// color: '#5B9BD5',
// }
// },
// },
// {
// name: '待办',
// type: 'bar',
// stack: '',
// label: {
// show: true,
// position: 'right',
// color: '#000',
// },
// data: wattingQty,
// barGap: '-100%',
// z:-1,
// itemStyle: {
// normal: {
// color: 'rgba(192, 192, 192)',
// }
// },
// },
{
name: '完成率',
type: 'bar',
stack: '总量',
// color: '#ED7D31',//#ED7D31、008000、ED7D31
data: finishRate.map(item=>{
return {
value:item,
label: {
show: item> 0 ? true:false,
position: 'inside',
color: '#fff',
formatter: '{c}%',
fontSize: '16'
},
// 每一个条目的样式配置
itemStyle: {
// barBorderRadius: [0, 34, 34, 0], // 圆角
// 渐变色 1、指明颜色渐变的方向 2、指明不同百分比之下颜色的值
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: "rgba(187,162,227,0.6)" },
{ offset: 1, color: "rgba(102,140,218,0.6)" },
]),
},
}
}),//finishRate
show: false,
// 每一个条目的样式配置
itemStyle: {
// barBorderRadius: [0, 34, 34, 0], // 圆角
// 渐变色 1、指明颜色渐变的方向 2、指明不同百分比之下颜色的值
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: "rgba(187,162,227,0.6)" },
{ offset: 1, color: "rgba(102,140,218,0.6)" },
]),
},
},
{
name: '未完成',
type: 'bar',
stack: '总量',
// label: {
// show: true,
// position: 'inside',
// color: '#000',
// formatter:'{c}%',
// fontSize: '16'
// },
color: 'rgba(192, 192, 192)',//#5B9BD5、808080
data: WattingRate
},
],
});
}
}
});
// let data = { "IsSuccessful": true, "Data":
// [{ "FORM_NAME": "班前会议作业情况", "WATTING_COUNT": 0, "FINISH_COUNT": 20, "TOTAL_COUNT": 20},
// { "FORM_NAME": "岗位当班作业情况", "WATTING_COUNT": 3, "FINISH_COUNT": 10, "TOTAL_COUNT": 0},
// {"FORM_NAME": "岗位交接班作业情况", "WATTING_COUNT": 5, "FINISH_COUNT": 8, "TOTAL_COUNT": 0},
// {"FORM_NAME": "岗位交接2班作业情况", "WATTING_COUNT": 5, "FINISH_COUNT": 10, "TOTAL_COUNT": 0}
// ], "TotalCount": 0, "ErrorMessage": null }
}
//风险等级占比
riskLevel = () => {
const userInfo = storage('lacal').getItem('webUserInfo').val;
let json = initFilter(this.props.login.OrgId);
this.props.dispatch({
type: 'app/getDataByPost',
url: "FM/RiskLevelProportion/OrderPaged",
payload: json,
onlyData: false,
onComplete: (data) => {
if (data && data.IsSuccessful) {
let riskLevel = []
let showData = []
let color = []
data.Data.forEach(item => {
riskLevel.push(item.RISK_LEVEL)
color.push(item.COLOR)
showData.push({ value: item.COUNT, name: item.RISK_LEVEL })
})
let myChart = echarts.init(document.getElementById('riskLevel'));
myChart.setOption({
tooltip: {
trigger: 'item',
//formatter: '{a}
{b} : {c} ({d}%)'
formatter: '{b} : {c} ({d}%)'
},
legend: {
bottom: '30px',
data: riskLevel
},
series: [
{
name: '主要工作分布',
type: 'pie',
radius: '55%',
center: ['50%', '42%'],
label: {
formatter: '{b}:({d}%)',
},
data: showData,
color: color,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
});
}
}
});
}
//获取数据
getBaseInfoData = (pagination, key, limit) => {
const current = pagination ? pagination.current : 1
const json = initFilter(this.props.login.OrgId, "", "CODE", 1, current)
// extendRule(json, 'SOURCE_FORMCODE', 9, "FO003")
const querySearch = this.state.querySearch;
for (var item in querySearch) {
if (item == 'searchName') {
extendRule(json, 'NOTICE_TITLE', 9, querySearch[item])
}
// if (item == 'searchCode') {
// extendRule(json, 'CODE', 9, querySearch[item])
// }
if (item == 'startTime1') {
extendRule(json, 'TASK_STARTDT', 6, querySearch[item])
}
if (item == 'startTime2') {
extendRule(json, 'TASK_STARTDT', 4, querySearch[item])
}
if (item == 'searchStatus') {
extendRule(json, 'NOTICE_STATUS', 1, querySearch[item])
}
// if (item == 'endTime1') {
// extendRule(json, 'TASK_ENDDT', 6, querySearch[item])
// }
// if (item == 'endTime2') {
// extendRule(json, 'TASK_ENDDT', 4, querySearch[item])
// }
}
json.Limit = limit;
json.Parameter1 = key;//1待办事项2已办事项3今日新增4待办超时
this.props.dispatch({
type: 'app/getDataByPost',
url: 'FM/FMNotificationTask/HomeOrderPaged',
payload: json,
onlyData: false,
onComplete: (re) => {
if (re && re.IsSuccessful && re.Data.newData) {
this.state.tableData[0].total = re.Data.todoCount;
this.state.tableData[1].total = re.Data.doneCount;
// this.state.tableData[2].total = re.Data.timeOverCount;
this.state.tableData[2].total = re.Data.todayNewCount;
// if (limit != null || limit != undefined)
// {
this.setState({
retData: re.Data.newData,
})
}
}
})
};
clearData = () => {
let newtmpData = { ...this.state.tmpData }
newtmpData["data"].id = '';
newtmpData["data"].homeReload = true;
this.setState({
visible: false,
tmpData: [],
qty:5,
searchVisible: false,
searchTodayVisible: false, //弹窗显示
})
}
handleCancel = () => { // 退出弹窗
this.getBaseInfoData(1, this.state.tableKey, 5);
this.clearData();
}
closeModal = () => { // 退出弹窗
this.clearData();
}
closeqModal = () => { // 退出弹窗
this.getBaseInfoData(1, "2", 5);
this.setState({
searchVisible: false,
searchTodayVisible: false, //弹窗显示
})
}
showEditModal = (dataId, formCode, TaskID, title, taskCode,tableKey,taskStartdt,taskStatus) => {
this.props.dispatch({
type: 'app/getDataByPost',
url: 'BI/BIController/getVersion',
onComplete: (ret) => {
if (ret > config.version) {
window.localStorage.clear()
message.success('清除成功,即将重新加载页面', 2, () => {
setTimeout(() => window.location.reload(true), 500)
})
}
}
})
const newtmpData = {
data: { id: dataId, TaskID: TaskID, onCancel: this.handleCancel, taskCode: taskCode, tableKey: tableKey,noticeTitle:title,taskStartdt:taskStartdt,taskStatus:taskStatus,homeReload: true },
formCode: tableKey==="3"?"PF135":formCode,
}
this.setState({
noticeTitle: tableKey==="3"?"今日提醒":title,
taskCode: taskCode,
tmpData: newtmpData
}, () => this.setState({
visible: true
}));
}
setMessageData = (dataSource) => {
const data = dataSource ? dataSource : this.props.taskData;
}
//点击切换四个统计模块更改列表数据
totalModuleClick = (item) => {
const { tableData } = this.state;
tableData.map((_item, i) => {
if (_item.key == item.key) {
_item.iconDisplay = 'block';
this.setState({
tableKey: item.key,
qty:5,
})
if(item.key==="2")
{
this.setState({
btnDisplay: 'none',
btnViewDisplay:'block',
btnTodayDisplay:'none',
})
}
else if(item.key==="3")
{
this.setState({
btnDisplay: 'none',
btnViewDisplay:'none',
btnTodayDisplay:'block',
})
}
else
{
this.setState({
btnDisplay: 'block',
btnViewDisplay:'none',
btnTodayDisplay:'none',
})
}
this.getBaseInfoData(1, item.key, 5);
} else {
_item.iconDisplay = 'none';
}
});
};
ShowState(obj) {
if(this.state.tableKey!=="2")
{
if(this.state.tableKey==="3")
{
if (obj.NOTICE_STATUS !==0) {
return (