import React, { useEffect, useState } from 'react'; import { makeStyles, Theme } from '@material-ui/core/styles'; import AppBar from '@material-ui/core/AppBar'; import Tabs from '@material-ui/core/Tabs'; import { PageHeader, Button, message, Steps, Space, Card, Dropdown, Menu } from 'antd'; import { Link, history } from 'umi'; import './index.less'; import { getReadInfo, menuList, updateReadStatus } from './service/service'; import { getProName, getSessionRoleData, getProTypeCode, getDefId, getPurchaseCanOperate, getReturnURL, getProId, getProMethod } from '@/utils/session'; import { Step, StepButton, StepLabel, Stepper, Toolbar, Popover, Typography } from '@material-ui/core'; import { isEmpty } from '@/utils/CommonUtils'; import { CustomerServiceTwoTone } from '@ant-design/icons'; const useStyles = makeStyles((theme: Theme) => ({ root: { flexGrow: 1, width: '100%', backgroundColor: theme.palette.background.paper, }, popover: { pointerEvents: 'none', }, paper: { padding: theme.spacing(1), }, })); function getUrlRelativePath() { let url = document.location.toString(); let arrUrl = url.split("//"); let start = arrUrl[1].indexOf("/"); let relUrl = arrUrl[1].substring(start); return relUrl; } const Promenu: React.FC<{}> = () => { //获取采购方式 const MethodDict = getProMethod(); const classes = useStyles(); //流程数据 const [data, setData] = React.useState([]); //角色 const randerRole = getSessionRoleData().roleCode; //总步骤条数 const [progress, setProgress] = useState(); //当前步骤条数 const [current, setCurrent] = useState(); const [buttonValue, setButtonValue] = useState(); const url = getUrlRelativePath(); const projectId = getProId(); const defId = getDefId(); //项目名称 const [proName, setProName] = useState(""); //收藏状态 0-已收藏 d-未收藏 const [subStatus, setSubStatus] = useState(null); //收藏数据 const [subData, setSubData] = useState(); //收藏loading const [subLoading, setSubLoading] = useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const [anchorName, setAnchorName] = useState(""); const scrollButtonsDesktop = document.getElementsByClassName("MuiTabs-scrollButtonsDesktop").length; const open = Boolean(anchorEl); useEffect(() => { menuList({ defId: defId, projectId: projectId }).then(res => { if (res.code === 200) { let data = res.data; setData(data); setProgress(data.length); setCurrent(getCurrentLinks(data) + 1); setButtonValue(stepButtonClick(findURL(data))); } }) getReadInfo({ projectId: projectId }).then(res => { if (res?.code == 200) { const data = res?.data; if (data) { setSubStatus(data.status); setSubData(data); } else { setSubStatus(""); } } }) setProName(getProName()); }, []); /** * 获取当前环节 */ const getCurrentLinks = (data: any) => { let num = -1; for (let i = 0; i < data.length; i++) { //1、已进行;2、当前环节;3、未开启 if (data[i].taskStatus === 1) { num = i; } } return num; } /** * 变更收藏状态 * @param status * @returns */ const changeSubStatus = (data: any, status: string) => { const params = { id: data ? data?.id : null, projectId: projectId, status } setSubLoading(true); updateReadStatus(params).then(res => { if (res?.code == 200) { setSubStatus(status); message.success(status == '0' ? '添加收藏成功' : '移除收藏成功') } }).finally(() => { setSubLoading(false); }) } const stepButtonClick = (data: any) => { if (isEmpty(data) || isEmpty(data.funcList)) { return null; } const funcList = data.funcList; return loadFuncList(funcList); } /** * 生成button数据 * @param funcList * @returns */ const loadFuncList = (funcList: any[]) => { let arr: JSX.Element[] = []; if (isEmpty(funcList)) { return arr; } const url = getUrlRelativePath(); arr = funcList.map((item: any, index: number) => ); return arr; } /** * 进入页面 * @param funcList * @param funcUrl */ const clickEnter = (funcList: any[], funcUrl: string) => { history.push(funcUrl); setButtonValue(loadFuncList(funcList)); } /** * 查找跟当前页面匹配的值(url) * @param data * @returns */ const findURL = (data: any[]) => { if (isEmpty(data)) { return null; } for (const item of data) { for (const i of item.funcList) { if (i.funcUrl === url) { return item; } } } return null; } const getFuncName = (data: any) => { const funcList = data.funcList; if (isEmpty(funcList)) { return ""; } const names = funcList.map((item: any) => item.funcName); return names.join(" | "); } const handlePopoverOpen = (event: React.MouseEvent, data: any) => { setAnchorName(getFuncName(data)); setAnchorEl(event.currentTarget); }; const handlePopoverClose = () => { setAnchorEl(null); }; const initChatUI = () => { //智慧客服 if(MethodDict!='procurement_mode_6' && MethodDict!='procurement_mode_7' && window.location.pathname.indexOf('BidEvaluation')!=-1){ message.warn('非谈判类项目【评标】阶段禁止沟通') }else{ var tempForm = document.getElementById('tempForm_CustomerService') as HTMLFormElement if(tempForm){ var hideInput = document.getElementById('tempInput_CustomerService') as HTMLInputElement if(hideInput){ hideInput.value= window.location.pathname }else{ hideInput = document.createElement("input") hideInput.id = 'tempInput_CustomerService' hideInput.type="hidden" hideInput.name= 'sceneUrl' hideInput.value= window.location.pathname tempForm.appendChild(hideInput) } tempForm.submit(); } } } return (
changeSubStatus(subData, "d")}>移除收藏 : null, (randerRole == 'ebtp-supervision' && (subStatus == "d" || subStatus == "")) ? : null, (randerRole == 'ebtp-agency-project-manager' || randerRole == 'ebtp-purchase' || randerRole == 'ebtp-supervision') ? : null, (randerRole == 'ebtp-agency-project-manager' || randerRole == 'ebtp-purchase' || randerRole == 'ebtp-supervision') && defId != 'inquiry' ? : null, , ((randerRole == 'ebtp-agency-project-manager' || randerRole == 'ebtp-purchase' || randerRole == 'ebtp-supervision') && MethodDict != "procurement_mode_7") ? : null, (randerRole == 'ebtp-supplier' && MethodDict != "procurement_mode_7") ? : null, // randerRole == 'ebtp-agency-project-manager' ? : null, // randerRole == 'ebtp-purchase' ? (getPurchaseCanOperate() != null && getPurchaseCanOperate() != undefined ? // : ) : null, // randerRole == 'ebtp-supplier' ? : null, // randerRole == 'ebtp-auction-manager' ? : null ]} >
10 ? "" : '100%', marginLeft: scrollButtonsDesktop === 0 ? '24px' : void 0, // paddingTop: '34px' }} > {data.map((item: any, index: number) => handlePopoverOpen(e, item)} onMouseLeave={handlePopoverClose} > setButtonValue(stepButtonClick(item))} > {item.taskName} )} {buttonValue} {anchorName}
); } export default Promenu;