diff --git a/package.json b/package.json index fd49ce8..e1efb2d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "numeral": "^2.0.6", "qrcode": "^1.5.4", "qs": "^6.14.0", + "react-html-table-to-excel": "^2.0.0", "umi": "^4.3.24", "xlsx": "^0.18.5", "xlsx-style-fixed": "^0.0.4" diff --git a/src/pages/examine/errorRecord/index.tsx b/src/pages/examine/errorRecord/index.tsx index f2bba10..890380b 100644 --- a/src/pages/examine/errorRecord/index.tsx +++ b/src/pages/examine/errorRecord/index.tsx @@ -3,18 +3,21 @@ import { ActionType, FormInstance, ProTable } from "@ant-design/pro-components"; import { useRef, useState } from "react"; import { connect } from "umi"; import moment from "moment"; -import { Button, Drawer, Image, message, Popconfirm, Space } from "antd"; +import { Button, Drawer, Image, message, Popconfirm, Space, Spin } from "antd"; import { handleGetServerpartDDL } from "@/components/leftSelectTree/service"; import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree"; import RecordDetail from "../record/components/recordDetail"; import { handleDeleteRecord, handleGetRecordTreeList, handleUpdateExtend } from "../record/service"; +import ReactHTMLTableToExcel from "react-html-table-to-excel"; const ErrorRecord: React.FC<{ currentUser: any }> = (props) => { const { currentUser } = props - + const downloadBtnRef = useRef() const actionRef = useRef(); const formRef = useRef(); const recordDetailRef = useRef() + + const [reqDetailList, setReqDetailList] = useState(); // 合计项数据源 // 显示的附件数据 const [showImgList, setShowImgList] = useState([]) // 预览图片 @@ -33,6 +36,15 @@ const ErrorRecord: React.FC<{ currentUser: any }> = (props) => { score: { show: false } }) const [collapsible, setCollapsible] = useState(false) + // 显示详情抽屉 + const [showDetailStatus, setShowDetailStatus] = useState(false) + // 详情抽屉的点击行数据 + const [currentStatusRow, setCurrentStatusRow] = useState() + // 是否显示打印的表格 + const [showExportTable, setShowExportTable] = useState(false) + const [printIndex, setPrintIndex] = useState(new Date().getTime()) + // 导出的加载效果 + const [showLoading, setShowLoading] = useState(false) const columns: any = [ // { @@ -274,6 +286,42 @@ const ErrorRecord: React.FC<{ currentUser: any }> = (props) => { } ] + const exportTable = (e) => { + e.stopPropagation(); // 防止Collapse组件收起 + const main = document.getElementsByClassName(`saleReportHideBox${printIndex}`)[0] + const thead = main.querySelector('thead').cloneNode(true); // 深克隆DOM节点 + const tbody = main.querySelector('tbody').cloneNode(true); // 深克隆DOM节点 + const container = document.querySelector('#hiddenBox'); + + + // 加个标题 + const tableTop = document.createElement('div') + tableTop.innerText = `异常统计表` + tableTop.setAttribute('style', 'font-size:20px;font-weight:600;display:flex;width:100%;justify-content: center;text-align: center;'); + + // 加个时间 + const tableTime = document.createElement('div') + tableTime.innerText = `${moment().format('YYYY-MM-DD')}` + tableTop.setAttribute('style', 'font-size:14px;display:flex;width:100%;justify-content: flex-start;text-align: center;'); + + const tempTable = document.createElement('table'); + tempTable.appendChild(tableTop) + tempTable.appendChild(tableTime) + + tempTable.appendChild(thead); + tempTable.appendChild(tbody); + + tempTable.setAttribute('id', 'table-to-xls-saleRankReport'); // 给table添加id,值与按钮上的table字段对应 + + container.appendChild(tempTable); // 把创建的节点添加到页面容器中 + + setShowLoading(false) + + downloadBtnRef.current.handleDownload(); + setShowExportTable(false) + tempTable.remove() // 防止重复打印一个内容 + } + // 删除记录 const deleteRecord = async (id: any) => { const data = await handleDeleteRecord({ id: id }) @@ -283,220 +331,400 @@ const ErrorRecord: React.FC<{ currentUser: any }> = (props) => { } } + const exportColumns: any = [ + { + title: "片区", + dataIndex: "SPRegionTypeName", + align: 'center' + }, + { + title: "服务区", + dataIndex: "ServerPartName", + align: 'center' + }, + { + title: "巡查点位", + dataIndex: "placeName", + align: 'center' + }, + { + title: "考核子类", + dataIndex: "takeTheNuclearExam", + align: 'center' + }, + { + title: "考核结果", + dataIndex: "assessmentResults", + align: 'center' + }, + { + title: "巡查人员", + dataIndex: "userName", + align: 'center' + }, + { + title: "巡查时间", + dataIndex: "createdAt", + align: 'center' + }, + { + title: "巡查状态", + dataIndex: "errorStatus", + align: 'center' + }, + + ] + + return ( -
- - - -
- { - return `${record?.id}-${record?.code}-${record?.templateId}` - }} - scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} - headerTitle={考核异常记录} - search={{ span: 6 }} - request={async (params) => { - // selectedId - console.log('params', params); - console.log('selectedId', selectedId); - if (!(selectedId && selectedId.length > 0)) { - return - } - - const req: any = { - serverPartIds: selectedId && selectedId.length > 0 ? selectedId : [], - // startTime: params?.search_months ? `${moment(params?.search_months).startOf('M').format('YYYY-MM-DD')}` : "", - // endTime: params?.search_months ? `${moment(params?.search_months).endOf('M').format('YYYY-MM-DD')}` : "", - // serverPartId: params?.serverPartId ? params?.serverPartId : undefined, - extend: params?.errorStatus ? [{ - key: "situation", - value: '1' - }, - { - key: "errorStatus", - value: params?.errorStatus - } - ] : [{ - key: "situation", - value: '1' - }] - - } - console.log('req', req); - const data = await handleGetRecordTreeList(req) - console.log('data', data); - - if (data && data.length > 0) { - return { data, success: true } - } - return { data: [], success: true } - }} - toolbar={{ - - }} - columnsState={{ - value: columnsStateMap, - onChange: setColumnsStateMap, - }} - > - -
+
{ - showImgList && showImgList.length > 0 &&
- - { - setImagePreviewVisible(vis) - }, - current: previewIndex + showLoading ? +
+
- { - showImgList.map((n) => - - ) - } - - - -
+ + 数据导出中... +
+
: '' } - - { - setShowDetail(false) - setShowAbnormal(false) - }} - open={showDetail} - destroyOnClose - width={'60%'} - footer={showAbnormal && currentRow?.errorStatus !== 2 ?
- -
: false +
+ { + showExportTable && reqDetailList && reqDetailList.length > 0 ? + : '' } - > - - -
+
+
+ +
+ + +
+ { + return `${record?.id}-${record?.code}-${record?.templateId}` + }} + scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} + headerTitle={考核异常记录} + search={{ span: 6 }} + request={async (params) => { + // selectedId + console.log('params', params); + console.log('selectedId', selectedId); + if (!(selectedId && selectedId.length > 0)) { + return + } + + const req: any = { + serverPartIds: selectedId && selectedId.length > 0 ? selectedId : [], + // startTime: params?.search_months ? `${moment(params?.search_months).startOf('M').format('YYYY-MM-DD')}` : "", + // endTime: params?.search_months ? `${moment(params?.search_months).endOf('M').format('YYYY-MM-DD')}` : "", + // serverPartId: params?.serverPartId ? params?.serverPartId : undefined, + extend: params?.errorStatus ? [{ + key: "situation", + value: '1' + }, + { + key: "errorStatus", + value: params?.errorStatus + } + ] : [{ + key: "situation", + value: '1' + }] + + } + console.log('req', req); + const data = await handleGetRecordTreeList(req) + console.log('data', data); + + if (data && data.length > 0) { + // 处理数据 + let exportData: any[] = [] + data.forEach((item: any) => { + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + if (subItem.children && subItem.children.length > 0) { + subItem.children.forEach((child: any) => { + let childrenText: string = '' + let childrenRes: string = '' + + if (child.questionResponses && child.questionResponses.length > 0) { + child.questionResponses.forEach((questionItem: any) => { + if (questionItem.score === 0) { + if (childrenText) { + childrenText += `,${questionItem.question.title}` + } else { + childrenText = `${questionItem.question.title}` + } + + if (childrenRes) { + childrenRes += `,${questionItem.choiceResponse[0]}` + } else { + childrenRes = `${questionItem.choiceResponse[0]}` + } + } + }) + } + exportData.push({ + SPRegionTypeName: item.name, + ServerPartName: subItem.name, + placeName: child.template.title || '-', + takeTheNuclearExam: childrenText, // 考核子类 + assessmentResults: childrenRes,// 考核结果 + userName: child?.userName || "",// 巡查人员 + createdAt: moment(child?.createdAt).format('YYYY-MM-DD HH:mm:ss'), // 巡查时间 + errorStatus: child.errorStatus === 0 + ? "待处理" + : child.errorStatus === 1 + ? "处理中" + : child.errorStatus === 2 + ? "已处理" + : "-"// 处理状态 + + + }) + }) + } + }) + } + }) + setReqDetailList(exportData) + + return { data, success: true } + } + return { data: [], success: true } + }} + toolbar={{ + actions: [ + + + + + , + + ] + + }} + columnsState={{ + value: columnsStateMap, + onChange: setColumnsStateMap, + }} + > + +
+ + { + showImgList && showImgList.length > 0 &&
+ + { + setImagePreviewVisible(vis) + }, + current: previewIndex + }}> + { + showImgList.map((n) => + + ) + } + + + +
+ } + + + { + setShowDetail(false) + setShowAbnormal(false) + }} + open={showDetail} + destroyOnClose + width={'60%'} + footer={showAbnormal && currentRow?.errorStatus !== 2 ?
+ +
: false + } + > + +
+
+ +
+ + + + ) } diff --git a/src/pages/examine/recordSummary/index.tsx b/src/pages/examine/recordSummary/index.tsx index 0a820a2..ffad2ba 100644 --- a/src/pages/examine/recordSummary/index.tsx +++ b/src/pages/examine/recordSummary/index.tsx @@ -3,22 +3,26 @@ import { ActionType, FormInstance, ProTable } from "@ant-design/pro-components"; import { useRef, useState } from "react"; import { connect } from "umi"; import moment from "moment"; -import { Button, Drawer, Image, message, Popconfirm, Space } from "antd"; +import { Button, Drawer, Image, message, Popconfirm, Space, Spin } from "antd"; import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree"; import { handleGetRecordTreeList, handleGetResponsesSummary, handleNewSummaryList } from "../record/service"; import login from "@/pages/user/login"; import { LeftOutlined, RightOutlined } from "@ant-design/icons"; import RecordDetail from "../record/components/recordDetail"; +import ReactHTMLTableToExcel from "react-html-table-to-excel"; + const recordSummary: React.FC<{ currentUser: any }> = (props) => { const { currentUser } = props - + const downloadBtnRef = useRef() const actionRef = useRef(); const formRef = useRef(); const drawerActionRef = useRef(); const drawerFormRef = useRef(); const recordDetailRef = useRef() + + const [reqDetailList, setReqDetailList] = useState(); // 合计项数据源 // 显示的附件数据 const [showImgList, setShowImgList] = useState([]) // 预览图片 @@ -33,7 +37,8 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { const [showType, setShowType] = useState(0) // 外侧表格的搜索条件 const [searchParams, setSearchParams] = useState() - + // 导出的加载效果 + const [showLoading, setShowLoading] = useState(false) // 判断是否点了出现的是异常处理的抽屉 const [showAbnormal, setShowAbnormal] = useState(false) // 树相关的属性和方法 @@ -46,6 +51,9 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { const [showDetailStatus, setShowDetailStatus] = useState(false) // 详情抽屉的点击行数据 const [currentStatusRow, setCurrentStatusRow] = useState() + // 是否显示打印的表格 + const [showExportTable, setShowExportTable] = useState(false) + const [printIndex, setPrintIndex] = useState(new Date().getTime()) const columns: any = [ { @@ -370,421 +378,594 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { ] + const exportTable = (e) => { + e.stopPropagation(); // 防止Collapse组件收起 + const main = document.getElementsByClassName(`saleReportHideBox${printIndex}`)[0] + const thead = main.querySelector('thead').cloneNode(true); // 深克隆DOM节点 + const tbody = main.querySelector('tbody').cloneNode(true); // 深克隆DOM节点 + const container = document.querySelector('#hiddenBox'); + + + // 加个标题 + const tableTop = document.createElement('div') + tableTop.innerText = `考核记录报表` + tableTop.setAttribute('style', 'font-size:20px;font-weight:600;display:flex;width:100%;justify-content: center;text-align: center;'); + + // 加个时间 + const tableTime = document.createElement('div') + tableTime.innerText = `${moment().format('YYYY-MM-DD')}` + tableTop.setAttribute('style', 'font-size:14px;display:flex;width:100%;justify-content: flex-start;text-align: center;'); + + const tempTable = document.createElement('table'); + tempTable.appendChild(tableTop) + tempTable.appendChild(tableTime) + + tempTable.appendChild(thead); + tempTable.appendChild(tbody); + + tempTable.setAttribute('id', 'table-to-xls-saleRankReport'); // 给table添加id,值与按钮上的table字段对应 + + container.appendChild(tempTable); // 把创建的节点添加到页面容器中 + + setShowLoading(false) + + downloadBtnRef.current.handleDownload(); + setShowExportTable(false) + tempTable.remove() // 防止重复打印一个内容 + } + + const exportColumns: any = [ + { + title: "片区", + dataIndex: "SPRegionTypeName", + align: 'center' + }, + { + title: "服务区", + dataIndex: "ServerPartName", + align: 'center' + }, + { + title: "巡查点位", + dataIndex: "placeName", + align: 'center' + }, + { + title: "巡查天数", + dataIndex: "allDay", + align: 'center' + }, + { + title: "实际天数", + dataIndex: "actualDay", + align: 'center' + }, + { + title: "巡查完成率", + dataIndex: "inspectionRate", + align: 'center' + }, + { + title: "处理完成", + dataIndex: "processingCompleted", + align: 'center' + }, + { + title: "处理中", + dataIndex: "Processing", + align: 'center' + } + ] + return ( -
- - -
- { - return `${record?.id}-${record?.code}-${record?.templateId}` - }} - scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} - headerTitle={考核记录汇总} - search={{ span: 6 }} - request={async (params) => { - if (!(selectedId && selectedId.length > 0)) { - return - } - console.log('params', params); - - - const req: any = { - serverPartIds: selectedId && selectedId.length > 0 ? selectedId : [], - startTime: params?.startTime ? `${params?.startTime}` : "", - endTime: params?.endTime ? `${params?.endTime}` : "", - // serverPartId: params?.serverPartId ? params?.serverPartId : undefined, - extend: params?.inspectionType ? [{ - key: "situation", - value: params?.inspectionType - }] : undefined - } - - let allDay: number = moment(params?.endTime).diff(params?.startTime, 'd') + 1 - console.log('allDay', allDay); - - - setSearchParams(params) - - console.log('req', req); - // const data = await handleGetRecordTreeList(req) - const data = await handleGetResponsesSummary(req) - console.log('dat3a333', data); - - // 处理一下 根据第三层的实际巡查记录 汇总到第二层来 - if (data && data.length > 0) { - // data.forEach((item: any) => { - // if (item.children && item.children.length > 0) { - // item.children.forEach((subItem: any) => { - // if (subItem.children && subItem.children.length > 0) { - // // 点位的id数据 肯定要求不重复的 - // let templateIdList: number[] = [] - // // 遍历完之后 要替换的 - // let newChildren: any = [] - // // 因为一天时间内 多条记录 需要被计算为一条 那么这里就要加上时间的对象来筛选 - // let dateObj: any = {} - // subItem.children.forEach((thirdItem: any) => { - // let extendObj: any = {} - // if (thirdItem.extend) { - // extendObj = JSON.parse(thirdItem.extend) - // } - - // let oldDateList = dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] - - // if (!oldDateList || (oldDateList && oldDateList.indexOf(thirdItem.id) === -1)) { - // // templateIdList 是判断 newChildren 里面已经有几个点位id了 - // if (templateIdList.indexOf(thirdItem.id) === -1) { - // templateIdList.push(thirdItem.id) - // newChildren.push({ - // // template: thirdItem.template, - // templateId: thirdItem.Id, - // inspectionNumber: 1, - // normalNumber: extendObj?.situation === 0 ? 1 : 0, - // errorNumber: extendObj?.situation === 1 ? 1 : 0, - // pendingProcessNumber: extendObj?.errorStatus === 0 ? 1 : 0, - // processingNumber: extendObj?.errorStatus === 1 ? 1 : 0, - // processedNumber: extendObj?.errorStatus === 2 ? 1 : 0, - // }) - // } else { - // newChildren.forEach((fourthItem: any) => { - // if (fourthItem.id === thirdItem.id) { - - // fourthItem.inspectionNumber += 1 - // if (extendObj?.situation === 0) { - // fourthItem.normalNumber += 1 - // } else if (extendObj?.situation === 1) { - // fourthItem.errorNumber += 1 - // } - - // if (extendObj?.errorStatus === 0) { - // fourthItem.pendingProcessNumber += 1 - // } else if (extendObj?.errorStatus === 1) { - // fourthItem.processingNumber += 1 - // } else if (extendObj?.errorStatus === 2) { - // fourthItem.processedNumber += 1 - // } - // } - // }) - // } - - // if (oldDateList && oldDateList.length > 0) { - // oldDateList.push(thirdItem.id) - // } else { - // dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] = [thirdItem.id] - // } - // } - // console.log('dateObj', dateObj); - - // }) - // subItem.children = newChildren - // } - // }) - // } - // }) - - - data.forEach((item: any) => { - let inspectionNumberItemSum: number = 0 - let normalNumberItemSum: number = 0 - let errorNumberItemSum: number = 0 - let pendingProcessNumberItemSum: number = 0 - let processingNumberItemSum: number = 0 - let processedNumberItemSum: number = 0 - - let bigSuccessSum: number = 0 - // 这一次时间段应该查询的次数(天数) - let allItemDaySum: number = 0 - if (item.children && item.children.length > 0) { - item.children.forEach((subItem: any) => { - let inspectionNumberSum: number = 0 - let normalNumberSum: number = 0 - let errorNumberSum: number = 0 - let pendingProcessNumberSum: number = 0 - let processingNumberSum: number = 0 - let processedNumberSum: number = 0 - - // 巡查完成率合计 - let successSum: number = 0 - - - // 这一次时间段应该查询的次数(天数) - let allSubItemDaySum: number = 0 - if (subItem.children && subItem.children.length > 0) { - subItem.children.forEach((thirdItem: any) => { - thirdItem.allDay = thirdItem.template.patrolTotal - // allSubItemDaySum += thirdItem.allDay - // thirdItem.allDay = thirdItem.patrolTotal - // allSubItemDaySum += thirdItem.template.patrolTotal - - - - allSubItemDaySum = thirdItem.template.patrolTotal - - // inspectionNumberSum += thirdItem.inspectionNumber - if (thirdItem.template.patrolNumber > inspectionNumberSum) { - inspectionNumberSum = thirdItem.template.patrolNumber - } - // inspectionNumberSum += thirdItem.template.patrolNumber - // thirdItem.inspectionNumber = thirdItem.patrolNumber - - thirdItem.inspectionNumber = thirdItem.template.patrolNumber - thirdItem.inspectionRate = thirdItem.template.patrolRate - successSum += thirdItem.inspectionRate - - thirdItem.normalNumber = thirdItem.template.situation0 - thirdItem.errorNumber = thirdItem.template.situation1 - thirdItem.pendingProcessNumber = thirdItem.template.errorStatus0 - thirdItem.processingNumber = thirdItem.template.errorStatus1 - thirdItem.processedNumber = thirdItem.template.errorStatus2 - - normalNumberSum = allDay - errorNumberSum += thirdItem.template.situation1 - pendingProcessNumberSum += thirdItem.pendingProcessNumber - processingNumberSum += thirdItem.processingNumber - processedNumberSum += thirdItem.processedNumber - }) - } - subItem.inspectionRate = (successSum / subItem.children.length).toFixed(4) - subItem.allDay = allSubItemDaySum - subItem.inspectionNumber = inspectionNumberSum - subItem.normalNumber = normalNumberSum - subItem.errorNumber = errorNumberSum - subItem.pendingProcessNumber = pendingProcessNumberSum - subItem.processingNumber = processingNumberSum - subItem.processedNumber = processedNumberSum - - bigSuccessSum += Number(subItem.inspectionRate) - inspectionNumberItemSum += subItem.inspectionNumber - normalNumberItemSum = allDay - errorNumberItemSum += subItem.errorNumber - pendingProcessNumberItemSum += subItem.pendingProcessNumber - processingNumberItemSum += subItem.processingNumber - processedNumberItemSum += subItem.processedNumber - allItemDaySum += subItem.allDay - }) - // item.allDay = allItemDaySum - // item.inspectionNumber = inspectionNumberItemSum - item.normalNumber = normalNumberItemSum - item.errorNumber = errorNumberItemSum - item.pendingProcessNumber = pendingProcessNumberItemSum - item.processingNumber = processingNumberItemSum - item.processedNumber = processedNumberItemSum - item.inspectionRate = (bigSuccessSum / item.children.length).toFixed(4) - } - }) - } - console.log('resresres', data); - - - if (data && data.length > 0) { - return { data, success: true } - } - return { data: [], success: true } - }} - toolbar={{ - - }} - columnsState={{ - value: columnsStateMap, - onChange: setColumnsStateMap, - }} - - > - -
- +
{ - showImgList && showImgList.length > 0 &&
- - { - console.log('vis', vis); - - setImagePreviewVisible(vis) - } + showLoading ? +
+
- { - showImgList.map((n) => - - ) - } - - - -
+ + 数据导出中... +
+
: '' } - { - setCurrentRow(undefined) - setShowType(0) - setShowDetail(false) - setShowImgList([]) - setImagePreviewVisible(false) - }} - open={showDetail} - destroyOnClose - width={'60%'} - > - { - return `${record?.id}-${record?.code}` - }} - scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} - headerTitle={考核记录管理} - search={{ span: 6 }} - request={async (params) => { - if (!currentRow?.serverPartId) { - return - } +
+ { + showExportTable && reqDetailList && reqDetailList.length > 0 ? + : '' + } +
+
- // showType 1 巡查次数 2 正常 3 异常 4 待处理 5 处理中 6 已处理 - - - const req: any = { - serverPartIds: [currentRow?.serverPartId], - startTime: searchParams?.startTime ? `${searchParams?.startTime}` : "", - endTime: searchParams?.endTime ? `${searchParams?.endTime}` : "", - extend: params?.inspectionType ? [ - { +
+ +
+ { + return `${record?.id}-${record?.code}-${record?.templateId}` + }} + scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} + headerTitle={考核记录汇总} + search={{ span: 6 }} + request={async (params) => { + if (!(selectedId && selectedId.length > 0)) { + return + } + const req: any = { + serverPartIds: selectedId && selectedId.length > 0 ? selectedId : [], + startTime: params?.startTime ? `${params?.startTime}` : "", + endTime: params?.endTime ? `${params?.endTime}` : "", + // serverPartId: params?.serverPartId ? params?.serverPartId : undefined, + extend: params?.inspectionType ? [{ key: "situation", value: params?.inspectionType - }, - { + }] : undefined + } - key: "templateId", - value: currentRow?.template.id, - } - ] : [ - { + let allDay: number = moment(params?.endTime).diff(params?.startTime, 'd') + 1 + console.log('allDay', allDay); - key: "templateId", - value: currentRow?.template.id, - } + + setSearchParams(params) + + // const data = await handleGetRecordTreeList(req) + const data = await handleGetResponsesSummary(req) + // 处理一下 根据第三层的实际巡查记录 汇总到第二层来 + if (data && data.length > 0) { + // data.forEach((item: any) => { + // if (item.children && item.children.length > 0) { + // item.children.forEach((subItem: any) => { + // if (subItem.children && subItem.children.length > 0) { + // // 点位的id数据 肯定要求不重复的 + // let templateIdList: number[] = [] + // // 遍历完之后 要替换的 + // let newChildren: any = [] + // // 因为一天时间内 多条记录 需要被计算为一条 那么这里就要加上时间的对象来筛选 + // let dateObj: any = {} + // subItem.children.forEach((thirdItem: any) => { + // let extendObj: any = {} + // if (thirdItem.extend) { + // extendObj = JSON.parse(thirdItem.extend) + // } + + // let oldDateList = dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] + + // if (!oldDateList || (oldDateList && oldDateList.indexOf(thirdItem.id) === -1)) { + // // templateIdList 是判断 newChildren 里面已经有几个点位id了 + // if (templateIdList.indexOf(thirdItem.id) === -1) { + // templateIdList.push(thirdItem.id) + // newChildren.push({ + // // template: thirdItem.template, + // templateId: thirdItem.Id, + // inspectionNumber: 1, + // normalNumber: extendObj?.situation === 0 ? 1 : 0, + // errorNumber: extendObj?.situation === 1 ? 1 : 0, + // pendingProcessNumber: extendObj?.errorStatus === 0 ? 1 : 0, + // processingNumber: extendObj?.errorStatus === 1 ? 1 : 0, + // processedNumber: extendObj?.errorStatus === 2 ? 1 : 0, + // }) + // } else { + // newChildren.forEach((fourthItem: any) => { + // if (fourthItem.id === thirdItem.id) { + + // fourthItem.inspectionNumber += 1 + // if (extendObj?.situation === 0) { + // fourthItem.normalNumber += 1 + // } else if (extendObj?.situation === 1) { + // fourthItem.errorNumber += 1 + // } + + // if (extendObj?.errorStatus === 0) { + // fourthItem.pendingProcessNumber += 1 + // } else if (extendObj?.errorStatus === 1) { + // fourthItem.processingNumber += 1 + // } else if (extendObj?.errorStatus === 2) { + // fourthItem.processedNumber += 1 + // } + // } + // }) + // } + + // if (oldDateList && oldDateList.length > 0) { + // oldDateList.push(thirdItem.id) + // } else { + // dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] = [thirdItem.id] + // } + // } + // console.log('dateObj', dateObj); + + // }) + // subItem.children = newChildren + // } + // }) + // } + // }) + + + data.forEach((item: any) => { + let inspectionNumberItemSum: number = 0 + let normalNumberItemSum: number = 0 + let errorNumberItemSum: number = 0 + let pendingProcessNumberItemSum: number = 0 + let processingNumberItemSum: number = 0 + let processedNumberItemSum: number = 0 + + let bigSuccessSum: number = 0 + // 这一次时间段应该查询的次数(天数) + let allItemDaySum: number = 0 + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + let inspectionNumberSum: number = 0 + let normalNumberSum: number = 0 + let errorNumberSum: number = 0 + let pendingProcessNumberSum: number = 0 + let processingNumberSum: number = 0 + let processedNumberSum: number = 0 + + // 巡查完成率合计 + let successSum: number = 0 + + + // 这一次时间段应该查询的次数(天数) + let allSubItemDaySum: number = 0 + if (subItem.children && subItem.children.length > 0) { + subItem.children.forEach((thirdItem: any) => { + thirdItem.allDay = thirdItem.template.patrolTotal + // allSubItemDaySum += thirdItem.allDay + // thirdItem.allDay = thirdItem.patrolTotal + // allSubItemDaySum += thirdItem.template.patrolTotal + + + + allSubItemDaySum = thirdItem.template.patrolTotal + + // inspectionNumberSum += thirdItem.inspectionNumber + if (thirdItem.template.patrolNumber > inspectionNumberSum) { + inspectionNumberSum = thirdItem.template.patrolNumber + } + // inspectionNumberSum += thirdItem.template.patrolNumber + // thirdItem.inspectionNumber = thirdItem.patrolNumber + + thirdItem.inspectionNumber = thirdItem.template.patrolNumber + thirdItem.inspectionRate = thirdItem.template.patrolRate + successSum += thirdItem.inspectionRate + + thirdItem.normalNumber = thirdItem.template.situation0 + thirdItem.errorNumber = thirdItem.template.situation1 + thirdItem.pendingProcessNumber = thirdItem.template.errorStatus0 + thirdItem.processingNumber = thirdItem.template.errorStatus1 + thirdItem.processedNumber = thirdItem.template.errorStatus2 + + normalNumberSum = allDay + errorNumberSum += thirdItem.template.situation1 + pendingProcessNumberSum += thirdItem.pendingProcessNumber + processingNumberSum += thirdItem.processingNumber + processedNumberSum += thirdItem.processedNumber + }) + } + subItem.inspectionRate = (successSum / subItem.children.length).toFixed(4) + subItem.allDay = allSubItemDaySum + subItem.inspectionNumber = inspectionNumberSum + subItem.normalNumber = normalNumberSum + subItem.errorNumber = errorNumberSum + subItem.pendingProcessNumber = pendingProcessNumberSum + subItem.processingNumber = processingNumberSum + subItem.processedNumber = processedNumberSum + + bigSuccessSum += Number(subItem.inspectionRate) + inspectionNumberItemSum += subItem.inspectionNumber + normalNumberItemSum = allDay + errorNumberItemSum += subItem.errorNumber + pendingProcessNumberItemSum += subItem.pendingProcessNumber + processingNumberItemSum += subItem.processingNumber + processedNumberItemSum += subItem.processedNumber + allItemDaySum += subItem.allDay + }) + // item.allDay = allItemDaySum + // item.inspectionNumber = inspectionNumberItemSum + item.normalNumber = normalNumberItemSum + item.errorNumber = errorNumberItemSum + item.pendingProcessNumber = pendingProcessNumberItemSum + item.processingNumber = processingNumberItemSum + item.processedNumber = processedNumberItemSum + item.inspectionRate = (bigSuccessSum / item.children.length).toFixed(4) + } + }) + } + + if (data && data.length > 0) { + console.log('data', data); + let exportData: any[] = [] + data.forEach((item: any) => { + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + if (subItem.children && subItem.children.length > 0) { + subItem.children.forEach((child: any) => { + exportData.push({ + SPRegionTypeName: item.name, + ServerPartName: subItem.name, + placeName: child.template.title || '-', + // allDay: `${child.inspectionNumber}(巡查天数) / ${child.allDay || '-'}(实际天数)`, + allDay: `${child.inspectionNumber}`, + actualDay: child.allDay, + inspectionRate: child.inspectionRate ? (child.inspectionRate * 100).toFixed(2) + '%' : '-', + processingCompleted: child.inspectionNumber,// 处理完成 + Processing: child.template.errorStatus01,// 处理中 + }) + }) + } + }) + } + }) + console.log('exportDataexportData', exportData); + setReqDetailList(exportData) + + return { data, success: true } + } + return { data: [], success: true } + }} + toolbar={{ + actions: [ + + + + + , + ] - // showType === 1 ? [ - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : showType === 2 ? [ - // { - // key: "situation", - // value: 0, - // }, - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : showType === 3 ? [ - // { - // key: "situation", - // value: 1, - // }, - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : showType === 4 ? [ - // { - // key: "errorStatus", - // value: 0, - // }, - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : - // showType === 5 ? [ - // { - // key: "errorStatus01", - // value: 1, - // }, - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : - // showType === 6 ? [ - // { - // key: "errorStatus", - // value: 2, - // }, - // { - // key: "templateId", - // value: currentRow?.template.id, - // } - // ] : undefined - } - console.log('req', req); - const data = await handleNewSummaryList(req) - console.log('data', data); + }} + columnsState={{ + value: columnsStateMap, + onChange: setColumnsStateMap, + }} - if (data && data.length > 0) { + > + +
- // 最后结果直接输出第三层的数据 好看点 - let res: any = [] - data.forEach((item: any) => { - if (item.children && item.children.length > 0) { - item.children.forEach((subItem: any) => { - if (subItem.children && subItem.children.length > 0) { - subItem.children.forEach((thirdItem: any) => { - res.push(thirdItem) - }) - } - }) + { + showImgList && showImgList.length > 0 &&
+ + { + console.log('vis', vis); + + setImagePreviewVisible(vis) } - }) - return { data: res, success: true } - } - return { data: [], success: true } + }}> + { + showImgList.map((n) => + + ) + } + + + +
+ } + + { + setCurrentRow(undefined) + setShowType(0) + setShowDetail(false) + setShowImgList([]) + setImagePreviewVisible(false) }} + open={showDetail} + destroyOnClose + width={'60%'} > - - + { + return `${record?.id}-${record?.code}` + }} + scroll={{ x: "100%", y: 'calc(100vh - 400px)' }} + headerTitle={考核记录管理} + search={{ span: 6 }} + request={async (params) => { + if (!currentRow?.serverPartId) { + return + } + + // showType 1 巡查次数 2 正常 3 异常 4 待处理 5 处理中 6 已处理 - { - setCurrentStatusRow(undefined) - setShowDetailStatus(false) - }} - open={showDetailStatus} - destroyOnClose - width={'80%'} - > - - + const req: any = { + serverPartIds: [currentRow?.serverPartId], + startTime: searchParams?.startTime ? `${searchParams?.startTime}` : "", + endTime: searchParams?.endTime ? `${searchParams?.endTime}` : "", + extend: params?.inspectionType ? [ + { + key: "situation", + value: params?.inspectionType + }, + { + + key: "templateId", + value: currentRow?.template.id, + } + ] : [ + { + + key: "templateId", + value: currentRow?.template.id, + } + ] + + // showType === 1 ? [ + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 2 ? [ + // { + // key: "situation", + // value: 0, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 3 ? [ + // { + // key: "situation", + // value: 1, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 4 ? [ + // { + // key: "errorStatus", + // value: 0, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : + // showType === 5 ? [ + // { + // key: "errorStatus01", + // value: 1, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : + // showType === 6 ? [ + // { + // key: "errorStatus", + // value: 2, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : undefined + } + const data = await handleNewSummaryList(req) + + if (data && data.length > 0) { + + // 最后结果直接输出第三层的数据 好看点 + let res: any = [] + data.forEach((item: any) => { + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + if (subItem.children && subItem.children.length > 0) { + subItem.children.forEach((thirdItem: any) => { + res.push(thirdItem) + }) + } + }) + } + }) + + return { data: res, success: true } + } + return { data: [], success: true } + }} + > + + + + + { + setCurrentStatusRow(undefined) + setShowDetailStatus(false) + }} + open={showDetailStatus} + destroyOnClose + width={'80%'} + > + + +
) } diff --git a/yarn.lock b/yarn.lock index 8ea70ef..ad39622 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9548,6 +9548,13 @@ react-helmet-async@1.3.0: react-fast-compare "^3.2.0" shallowequal "^1.1.0" +react-html-table-to-excel@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/react-html-table-to-excel/-/react-html-table-to-excel-2.0.0.tgz#c5b183121e4a07b47ce936337150dabb60f6012e" + integrity sha512-afvcCtQWZPfen3D+UFu9YMHleQqpVm3manmiWaxr0wv76hx+BkQ0/nkOI1UyQs29pzAUWtZDiD9Eu/MqsDOEJw== + dependencies: + prop-types "^15.5.10" + react-intl@3.12.1: version "3.12.1" resolved "https://registry.npmmirror.com/react-intl/-/react-intl-3.12.1.tgz#e9a783ea20302e9da25e4eda59e5593a43d2ec80" @@ -10485,7 +10492,16 @@ string-convert@^0.2.0: resolved "https://registry.npmmirror.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97" integrity sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmmirror.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10583,7 +10599,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmmirror.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -11436,7 +11459,7 @@ word@~0.3.0: resolved "https://registry.npmmirror.com/word/-/word-0.3.0.tgz#8542157e4f8e849f4a363a288992d47612db9961" integrity sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11454,6 +11477,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.npmmirror.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"