From f3966ac2c96fcba6df4f92a87130ee39c45f7905 Mon Sep 17 00:00:00 2001 From: cclu <1106109051@qq.com> Date: Fri, 11 Apr 2025 14:10:12 +0800 Subject: [PATCH] =?UTF-8?q?=20feat(=E6=A8=A1=E5=9D=97):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=AA=E5=BE=88=E6=A3=92=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/examine/modal/index.tsx | 185 +++++++++++++++++++++- src/pages/examine/question/index.tsx | 92 ++++++++--- src/pages/examine/recordSummary/index.tsx | 164 ++++++++++++++++--- 3 files changed, 388 insertions(+), 53 deletions(-) diff --git a/src/pages/examine/modal/index.tsx b/src/pages/examine/modal/index.tsx index 2b46ade..685399b 100644 --- a/src/pages/examine/modal/index.tsx +++ b/src/pages/examine/modal/index.tsx @@ -18,10 +18,12 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { const { currentUser } = props const actionRef = useRef(); + const cloneActionRef = useRef(); const formRef = useRef(); const modalActionRef = useRef(); const modalFormRef = useRef(); + const cloneFormRef = useRef(); // 弹出框的表单实例 @@ -38,6 +40,8 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { const [currentRow, setCurrentRow] = useState() // 服务区的枚举 const [serviceObj, setServiceObj] = useState() + // 服务区的全部数据 + const [allServiceList, setAllServiceList] = useState() // 生成的二维码的初始 const [qrCodeUrl, setQrCodeUrl] = useState() // 选择问题的悬浮框 @@ -64,6 +68,16 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { const [openAddQuestion, setOpenAddQuestion] = useState(false) // 拿到protable的问题分类 const [bigTypeList, setBigTypeList] = useState() + // 显示克隆悬浮框 + const [showCloneModal, handleShowCloneModal] = useState(false) + // 克隆的选择内容 + const [selectedCloneId, setSelectedCloneId] = useState() + const [selectedCloneDetail, setSelectedCloneDetail] = useState() + // 默认展开行的id + const [defaultExpandRow, setDefaultExpandRow] = useState() + + + const columns: any = [ // { @@ -81,7 +95,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { // dataIndex: "anySearchParams", // hideInTable: true, // fieldProps: { - + // } // }, { @@ -304,6 +318,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { })) : []; setBigTypeList(formattedData); }; + useEffect(() => { fetchTreeData() }, []) @@ -563,6 +578,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { obj[item.value] = item.label }) } + setAllServiceList(data) setServiceObj(obj) return data }} @@ -586,13 +602,18 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { }]} /> - + + + + = (props) => { width={1400} title={`点位`} open={selectQuestionModal} + destroyOnClose onOk={() => { console.log('selectedQuestionDetail', selectedQuestionDetail); @@ -698,7 +720,9 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { actionRef={modalActionRef} formRef={modalFormRef} columns={modalColumns} - rowKey={"id"} + rowKey={(record) => { + return `${record?.id}` + }} scroll={{ y: 'calc(100vh - 500px)' }} request={async (params) => { console.log('查询参数:', params); @@ -737,6 +761,161 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { }} /> + + + { + console.log('selectedCloneId', selectedCloneId); + console.log('selectedCloneDetail', selectedCloneDetail); + + let res: any = [] + let detailList: any = [] + let idList: any = [] + let list: any = selectedCloneDetail[0].questionnaireTemplateQuestions + if (list && list.length > 0) { + list.forEach((item: any) => { + detailList.push(item) + idList.push(item.question.id.toString()) + if (item.question) { + let obj = JSON.parse(JSON.stringify(item.question)) + + let str: string = '' + if (obj.options && obj?.options.length > 0) { + obj.options.forEach((subItem: any, index: number) => { + str += `${index > 0 ? ',' : ''}选项${index + 1}:${subItem.text}` + }) + } + + obj.text = obj.title + obj.mark = JSON.stringify(obj.options) + obj.showText = str + res.push(obj) + } + }) + } + + setSelectedQuestionDetail(detailList) + console.log('idList', idList); + + setSelectedQuestionId(idList) + + modalRef.current?.setFieldsValue({ + questions: res + }) + handleShowCloneModal(false) + }} + onCancel={() => { + handleShowCloneModal(false) + }} + > + + { + return `${record?.id}` + }} + columns={[ + { + title:
服务区名称
, + dataIndex: "serverPartName", + // hideInSearch: true, + width: 200, + ellipsis: true, + render: (_, record) => { + return record?.type === 'district' || record?.type === 'servicePart' ? record?.name : + record?.title + } + }, + { + title:
问题列表
, + dataIndex: "questions", + hideInSearch: true, + width: 400, + ellipsis: true, + render: (_, record) => { + let questionStr: string = "" + if (record?.questionnaireTemplateQuestions && record?.questionnaireTemplateQuestions.length > 0) { + record?.questionnaireTemplateQuestions.forEach((item: any, index: number) => { + let options: string = '' + if (item.question.options && item.question.options.length > 0) { + item.question.options.forEach((subItem: any, subIndex: number) => { + options += `${subItem.text};` + // ${subIndex > 0 ? ',' : ''} 选项${subIndex + 1}: + }) + } + questionStr += `${index > 0 ? ',' : ''}问题:${item.question.title}。${options}` + // ${index + 1} + }) + } + return questionStr || '' + // return record?.questions && record?.questions.length > 0 ? JSON.stringify(record?.questions) : '' + } + }, + ]} + request={async (params) => { + let selectId: string[] = [] + console.log('cloneFormRef', cloneFormRef); + console.log('params', params); + + if (allServiceList && allServiceList.length > 0) { + allServiceList.forEach((item: any) => { + selectId.push(item.value) + }) + } + console.log('selectId', selectId); + const req: any = { + serverPartIds: selectId, + any: params?.serverPartName ? [ + { + key: "serverPartName", + value: params?.serverPartName + } + ] : undefined + } + const data = await handleSearchModalTree(req) + console.log('dasdsa', data); + let defaultRow: any = [] + + if (data && data.length > 0) { + data.forEach((item: any) => { + defaultRow.push(item.id.toString()) + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + defaultRow.push(subItem.id.toString()) + }) + } + }) + console.log('defaultRow', defaultRow); + + setDefaultExpandRow(defaultRow) + return { data, success: true } + } + setDefaultExpandRow(defaultRow) + return { data: [], success: true } + }} + expandable={{ + expandedRowKeys: defaultExpandRow, + defaultExpandAllRows: true + }} + scroll={{ x: '100%', y: '500px' }} + rowSelection={{ + type: "radio", + defaultSelectedRowKeys: selectedCloneId, + getCheckboxProps: (record) => ({ + disabled: record.type === "district" || record.type === "servicePart", + }), + onChange: (selectedRowKeys, selectedRows) => { + setSelectedCloneDetail(selectedRows) + setSelectedCloneId(selectedRowKeys) + } + }} + /> +
diff --git a/src/pages/examine/question/index.tsx b/src/pages/examine/question/index.tsx index 163d350..3c9c538 100644 --- a/src/pages/examine/question/index.tsx +++ b/src/pages/examine/question/index.tsx @@ -176,32 +176,72 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => { // 递归 处理 将问题拼在列表的对应层 不一定是第二层 const handleGetNewQuestion = (typeList: any, list: any) => { - let res: any = [] - if (typeList && typeList.length > 0) { - typeList.forEach((item: any) => { - if (item.children && item.children.length > 0) { - let newRes = handleGetNewQuestion(item.children, list) - item.children = newRes - res.push(item) - } else { - if (list && list.length > 0) { - list.forEach((subItem: any) => { - if (subItem.categoryId === item.id) { - if (item.children && item.children.length > 0) { - subItem.isNoChildren = true - item.children.push(subItem) - } else { - subItem.isNoChildren = true - item.children = [subItem] - } - } - }) - } - res.push(item) - } + console.log('typeList', typeList); + console.log('list', list); + if (list && list.length > 0) { + list.forEach((item: any) => { + item.isNoChildren = true }) } - return res + // 递归查找并插入匹配项的函数 + const findAndInsert = (nodes: any[], itemsToInsert: any[]) => { + for (const node of nodes) { + // 在当前节点的子节点中查找匹配 + if (node.children) { + findAndInsert(node.children, itemsToInsert); + } + + // 检查当前节点是否匹配list中的categoryId + const matchedItems = itemsToInsert.filter(item => item.categoryId === node.id); + + if (matchedItems.length > 0) { + // 如果匹配到,初始化children数组(如果不存在) + if (!node.children) { + node.children = []; + } + + // 将匹配到的项添加到children中 + node.children.push(...matchedItems); + + // 从待插入列表中移除已处理的项 + itemsToInsert = itemsToInsert.filter(item => !matchedItems.includes(item)); + } + } + }; + + // 创建list的副本以避免修改原数组 + const itemsToInsert = [...list]; + + // 开始递归处理 + findAndInsert(typeList, itemsToInsert); + return typeList + + // let res: any = [] + // if (typeList && typeList.length > 0) { + // typeList.forEach((item: any) => { + // if (item.children && item.children.length > 0) { + // let newRes = handleGetNewQuestion(item.children, list) + // item.children = newRes + // res.push(item) + // } else { + // if (list && list.length > 0) { + // list.forEach((subItem: any) => { + // if (subItem.categoryId === item.id) { + // if (item.children && item.children.length > 0) { + // subItem.isNoChildren = true + // item.children.push(subItem) + // } else { + // subItem.isNoChildren = true + // item.children = [subItem] + // } + // } + // }) + // } + // res.push(item) + // } + // }) + // } + // return res } return ( @@ -245,10 +285,10 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => { any: params?.title ? [{ key: "title", value: params?.title }] : undefined } const data = await handleGetQuestionList(req) - console.log('data', data); + console.log('data3231231231', data); let res = await handleGetNewQuestion(typeData, data) - console.log('res', res); + console.log('res432423', res); if (res && res.length > 0) { return { data: res, success: true } } diff --git a/src/pages/examine/recordSummary/index.tsx b/src/pages/examine/recordSummary/index.tsx index ee820a8..69369bf 100644 --- a/src/pages/examine/recordSummary/index.tsx +++ b/src/pages/examine/recordSummary/index.tsx @@ -79,13 +79,29 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { width: 150, ellipsis: true, render: (_, record) => { - return record?.template?.id && record?.inspectionNumber > 0 ? { - setCurrentRow(record) - setShowType(1) - setShowDetail(true) - }}> - {record?.inspectionNumber || '-'} - : {record?.inspectionNumber || '-'} + return record?.template?.id && record?.inspectionNumber > 0 ? + { + setCurrentRow(record) + setShowType(1) + setShowDetail(true) + }}> + {record?.inspectionNumber || '-'} + / {record?.allDay} + : {record?.inspectionNumber || '-'} / {record?.allDay} + } + }, + { + title:
巡查完成率
, + dataIndex: "inspectionRate", + align: 'center', + hideInSearch: true, + width: 150, + ellipsis: true, + render: (_, record) => { + return record?.allDay ? + + {((record?.inspectionNumber / record?.allDay) * 100).toFixed(2) + '%'} + : '' } }, { @@ -172,6 +188,19 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { {record?.processedNumber || '-'} : {record?.processedNumber || '-'} } + }, + { + title:
处理完成率
, + dataIndex: "processedRate", + align: 'center', + hideInSearch: true, + width: 150, + ellipsis: true, + render: (_, record) => { + return record?.errorNumber ? + {((record?.processedNumber / record?.errorNumber) * 100).toFixed(2)}% + : "" + } } ] @@ -351,6 +380,10 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { }] : undefined } + let allDay: number = moment(params?.endTime).diff(params?.startTime, 'd') + 1 + console.log('allDay', allDay); + + setSearchParams(params) console.log('req', req); @@ -367,29 +400,34 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { 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) } - if (templateIdList.indexOf(thirdItem.template.id) === -1) { - templateIdList.push(thirdItem.template.id) - // 没有过的点位数据 就给他默认值 - newChildren.push({ - template: thirdItem.template, - 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 { - // 如果已经有过了的点位 给他加当前的状态就好 - if (newChildren && newChildren.length > 0) { + + let oldDateList = dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] + + if (!oldDateList || (oldDateList && oldDateList.indexOf(thirdItem.template.id) === -1)) { + // templateIdList 是判断 newChildren 里面已经有几个点位id了 + if (templateIdList.indexOf(thirdItem.template.id) === -1) { + templateIdList.push(thirdItem.template.id) + newChildren.push({ + template: thirdItem.template, + templateId: thirdItem.template.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.template.id === thirdItem.template.id) { + fourthItem.inspectionNumber += 1 if (extendObj?.situation === 0) { fourthItem.normalNumber += 1 @@ -407,7 +445,62 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { } }) } + + if (oldDateList && oldDateList.length > 0) { + oldDateList.push(thirdItem.template.id) + } else { + dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] = [thirdItem.template.id] + } } + + // if (templateIdList.indexOf(thirdItem.template.id) === -1) { + // templateIdList.push(thirdItem.template.id) + // // 没有过的点位数据 就给他默认值 + // newChildren.push({ + // template: thirdItem.template, + // 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 { + // // 如果已经有过了的点位 给他加当前的状态就好 + // let nowDayData = dateObj[moment(thirdItem.createdAt).format('YYYY-MM-DD')] + // // 判断这一天 这个点位 是否已经有过了 + // let isHave: boolean = false + // if (nowDayData && nowDayData.length > 0) { + // if (nowDayData.indexOf(thirdItem.template.id) !== -1) { + // isHave = true + // } + // } + // if (!isHave) { + // if (newChildren && newChildren.length > 0) { + // newChildren.forEach((fourthItem: any) => { + // if (fourthItem.template.id === thirdItem.template.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 + // } + // } + // }) + // } + // } + // } + console.log('dateObj', dateObj); + }) subItem.children = newChildren } @@ -423,6 +516,8 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { let pendingProcessNumberItemSum: number = 0 let processingNumberItemSum: number = 0 let processedNumberItemSum: number = 0 + // 这一次时间段应该查询的次数(天数) + let allItemDaySum: number = 0 if (item.children && item.children.length > 0) { item.children.forEach((subItem: any) => { let inspectionNumberSum: number = 0 @@ -431,8 +526,12 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { let pendingProcessNumberSum: number = 0 let processingNumberSum: number = 0 let processedNumberSum: number = 0 + // 这一次时间段应该查询的次数(天数) + let allSubItemDaySum: number = 0 if (subItem.children && subItem.children.length > 0) { subItem.children.forEach((thirdItem: any) => { + thirdItem.allDay = allDay + allSubItemDaySum += thirdItem.allDay inspectionNumberSum += thirdItem.inspectionNumber normalNumberSum += thirdItem.normalNumber errorNumberSum += thirdItem.errorNumber @@ -441,6 +540,7 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { processedNumberSum += thirdItem.processedNumber }) } + subItem.allDay = allSubItemDaySum subItem.inspectionNumber = inspectionNumberSum subItem.normalNumber = normalNumberSum subItem.errorNumber = errorNumberSum @@ -454,7 +554,9 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { pendingProcessNumberItemSum += subItem.pendingProcessNumber processingNumberItemSum += subItem.processingNumber processedNumberItemSum += subItem.processedNumber + allItemDaySum += subItem.allDay }) + item.allDay = allItemDaySum item.inspectionNumber = inspectionNumberItemSum item.normalNumber = normalNumberItemSum item.errorNumber = errorNumberItemSum @@ -586,7 +688,21 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { console.log('data', data); if (data && data.length > 0) { - return { data, success: true } + + // 最后结果直接输出第三层的数据 好看点 + 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 } }}