mod 更新巡检人字段名称为ownerUserId,调整相关表单和展示逻辑

pull/853/head
wersd 2025-12-05 08:57:35 +08:00
parent 4cd6de36c2
commit a5fe3d15e3
4 changed files with 159 additions and 49 deletions

View File

@ -5,7 +5,7 @@ export interface ProjectInspectionRecordVO {
id: number // 主键ID id: number // 主键ID
projectId: number // 项目ID projectId: number // 项目ID
inspectionDate: Date // 巡检日期时间 inspectionDate: Date // 巡检日期时间
inspector: number // 巡检人 ownerUserId: number // 巡检人
overallStatus: number // 总体状态 overallStatus: number // 总体状态
summary: string // 巡检总结 summary: string // 巡检总结
remark: string // 备注 remark: string // 备注

View File

@ -41,9 +41,9 @@
</el-row> </el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="12">
<el-form-item label="巡检人" prop="inspector"> <el-form-item label="巡检人" prop="ownerUserId">
<el-select <el-select
v-model="formData.inspector" v-model="formData.ownerUserId"
placeholder="请选择巡检人" placeholder="请选择巡检人"
clearable clearable
filterable filterable
@ -141,7 +141,7 @@ const formData = ref({
id: undefined, id: undefined,
projectId: undefined, projectId: undefined,
inspectionDate: undefined, inspectionDate: undefined,
inspector: undefined, ownerUserId: undefined,
overallStatus: undefined, overallStatus: undefined,
summary: undefined, summary: undefined,
remark: undefined, remark: undefined,
@ -150,7 +150,7 @@ const formData = ref({
const formRules = reactive({ const formRules = reactive({
projectId: [{ required: true, message: '项目名称不能为空', trigger: 'change' }], projectId: [{ required: true, message: '项目名称不能为空', trigger: 'change' }],
inspectionDate: [{ required: true, message: '巡检日期不能为空', trigger: 'blur' }], inspectionDate: [{ required: true, message: '巡检日期不能为空', trigger: 'blur' }],
inspector: [{ required: true, message: '巡检人不能为空', trigger: 'change' }], ownerUserId: [{ required: true, message: '巡检人不能为空', trigger: 'change' }],
status: [{ required: true, message: '状态不能为空', trigger: 'blur' }], status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
}) })
const formRef = ref() // 表单 Ref const formRef = ref() // 表单 Ref
@ -215,7 +215,7 @@ const resetForm = () => {
id: undefined, id: undefined,
projectId: undefined, projectId: undefined,
inspectionDate: undefined, inspectionDate: undefined,
inspector: undefined, ownerUserId: undefined,
overallStatus: undefined, overallStatus: undefined,
summary: undefined, summary: undefined,
remark: undefined, remark: undefined,

View File

@ -13,8 +13,8 @@
<el-form-item label="巡检日期" prop="inspectionDate"> <el-form-item label="巡检日期" prop="inspectionDate">
<el-input v-model="inspectionDate" disabled /> <el-input v-model="inspectionDate" disabled />
</el-form-item> </el-form-item>
<el-form-item label="巡检人" prop="inspector"> <el-form-item label="巡检人" prop="ownerUserId">
<el-input v-model="inspectorName" disabled /> <el-input v-model="ownerUserIdName" disabled />
</el-form-item> </el-form-item>
<!-- 按配置类型分组显示巡检内容字段 --> <!-- 按配置类型分组显示巡检内容字段 -->
@ -135,6 +135,21 @@
</el-radio> </el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<!-- 备注 -->
<el-divider>
<span style="font-weight: bold; font-size: 16px;">备注</span>
</el-divider>
<el-form-item label="备注" prop="remark">
<el-input
v-model="formData.remark"
type="textarea"
:rows="4"
placeholder="请输入备注信息"
maxlength="500"
show-word-limit
clearable
/>
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button> <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
@ -169,7 +184,7 @@ const projectList = ref<ProjectApi.ProjectVO[]>([]) // 项目列表
const userList = ref<UserApi.UserVO[]>([]) // 用户列表 const userList = ref<UserApi.UserVO[]>([]) // 用户列表
const projectName = ref('') // 项目名称 const projectName = ref('') // 项目名称
const inspectionDate = ref('') // 巡检日期 const inspectionDate = ref('') // 巡检日期
const inspectorName = ref('') // 巡检人名称(显示当前用户) const ownerUserIdName = ref('') // 巡检人名称(显示当前用户)
const recordId = ref<number | undefined>(undefined) // 记录ID const recordId = ref<number | undefined>(undefined) // 记录ID
const originalRecord = ref<ProjectInspectionRecordApi.ProjectInspectionRecordVO | null>(null) // 原始记录数据 const originalRecord = ref<ProjectInspectionRecordApi.ProjectInspectionRecordVO | null>(null) // 原始记录数据
@ -311,7 +326,7 @@ const open = async (record: ProjectInspectionRecordApi.ProjectInspectionRecordVO
projectName.value = project?.name || '' projectName.value = project?.name || ''
// 巡检人显示当前登录用户名称 // 巡检人显示当前登录用户名称
inspectorName.value = userStore.user.nickname || '当前用户' ownerUserIdName.value = userStore.user.nickname || '当前用户'
// 格式化巡检日期时间 // 格式化巡检日期时间
if (record.inspectionDate) { if (record.inspectionDate) {
@ -332,7 +347,10 @@ const open = async (record: ProjectInspectionRecordApi.ProjectInspectionRecordVO
inspectionDataList.value = inspectionDataListResult inspectionDataList.value = inspectionDataListResult
// 初始化表单数据和验证规则 // 初始化表单数据和验证规则
formData.value = {} formData.value = {
remark: originalRecord.value?.remark || '', // 初始化备注字段
overallStatus: originalRecord.value?.overallStatus // 初始化巡检结论
}
formRules.value = {} formRules.value = {}
inspectionDataList.value.forEach((item) => { inspectionDataList.value.forEach((item) => {
@ -362,7 +380,44 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => { const submitForm = async () => {
// 校验表单 // 校验表单
try {
await formRef.value.validate() await formRef.value.validate()
} catch (error: any) {
// 验证失败时,查找所有未填写的必填项并显示友好提示
const invalidFields: string[] = []
inspectionDataList.value.forEach((item) => {
if (item.isRequired) {
const fieldKey = `data_${item.id}`
const value = formData.value[fieldKey]
// 检查值是否为空
const isEmpty = value === undefined ||
value === null ||
value === '' ||
(Array.isArray(value) && value.length === 0)
if (isEmpty) {
invalidFields.push(item.name)
}
}
})
// 如果有未填写的必填项,显示提示
if (invalidFields.length > 0) {
const fieldNames = invalidFields.join('、')
message.warning(`请填写以下必填项:${fieldNames}`)
// 滚动到第一个未填写的字段
const firstInvalidField = inspectionDataList.value.find(item =>
item.isRequired && invalidFields.includes(item.name)
)
if (firstInvalidField) {
const fieldKey = `data_${firstInvalidField.id}`
await formRef.value.validateField(fieldKey)
}
} else {
// 如果没有找到未填写的必填项,可能是其他验证错误,显示通用提示
message.warning('请检查表单填写是否完整')
}
return
}
// 提交请求 // 提交请求
formLoading.value = true formLoading.value = true
@ -375,13 +430,13 @@ const submitForm = async () => {
// 构建分组数据(用于后端处理,使用ID作为键) // 构建分组数据(用于后端处理,使用ID作为键)
const summaryData: Record<number, Record<number, any>> = {} const summaryData: Record<number, Record<number, any>> = {}
// 构建易读的总结数据(用于人类阅读,使用名称作为键,包含字段类型信息) // 构建易读的总结数据(用于人类阅读,使用名称作为键,包含字段类型信息和备注)
const readableSummaryData: Record<string, Array<{ name: string; value: any; type: number }>> = {} const readableSummaryData: Record<string, Array<{ name: string; value: any; type: number; remark?: string }>> = {}
// 按配置类型分组收集表单数据 // 按配置类型分组收集表单数据
groupedInspectionData.value.forEach((group) => { groupedInspectionData.value.forEach((group) => {
const groupData: Record<number, any> = {} const groupData: Record<number, any> = {}
const readableGroupData: Array<{ name: string; value: any; type: number }> = [] const readableGroupData: Array<{ name: string; value: any; type: number; remark?: string }> = []
const configTypeName = getConfigTypeName(group.configType) const configTypeName = getConfigTypeName(group.configType)
group.items.forEach((item) => { group.items.forEach((item) => {
@ -396,7 +451,8 @@ const submitForm = async () => {
readableGroupData.push({ readableGroupData.push({
name: item.name, name: item.name,
value: value.join('、'), // 使用中文顿号分隔,更易读 value: value.join('、'), // 使用中文顿号分隔,更易读
type: item.type type: item.type,
remark: item.remark // 添加备注
}) })
} }
} else if (value !== undefined && value !== null && value !== '') { } else if (value !== undefined && value !== null && value !== '') {
@ -405,7 +461,8 @@ const submitForm = async () => {
readableGroupData.push({ readableGroupData.push({
name: item.name, name: item.name,
value: value, value: value,
type: item.type type: item.type,
remark: item.remark // 添加备注
}) })
} }
}) })
@ -443,10 +500,10 @@ const submitForm = async () => {
id: recordId.value, id: recordId.value,
projectId: originalRecord.value.projectId, projectId: originalRecord.value.projectId,
inspectionDate: originalRecord.value.inspectionDate, inspectionDate: originalRecord.value.inspectionDate,
inspector: originalRecord.value.inspector, ownerUserId: originalRecord.value.ownerUserId,
overallStatus: formData.value.overallStatus, // 使用表单中选择的巡检结论 overallStatus: formData.value.overallStatus, // 使用表单中选择的巡检结论
summary: summaryJson || JSON.stringify(summaryData), // 使用JSON格式存储结构化数据 summary: summaryJson || JSON.stringify(summaryData), // 使用JSON格式存储结构化数据
remark: originalRecord.value.remark || '', remark: formData.value.remark || '', // 使用表单中填写的备注
status: recordStatus // 根据填报日期和巡检日期比较结果设置状态(recordStatus的值通过status字段传递) status: recordStatus // 根据填报日期和巡检日期比较结果设置状态(recordStatus的值通过status字段传递)
} }

View File

@ -36,9 +36,9 @@
class="!w-220px" class="!w-220px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="巡检人" prop="inspector"> <el-form-item label="巡检人" prop="ownerUserId">
<el-select <el-select
v-model="queryParams.inspector" v-model="queryParams.ownerUserId"
placeholder="请选择巡检人" placeholder="请选择巡检人"
clearable clearable
filterable filterable
@ -119,7 +119,7 @@
<div class="card-info"> <div class="card-info">
<div class="info-item"> <div class="info-item">
<span class="info-label">巡检人:</span> <span class="info-label">巡检人:</span>
<span class="info-value">{{ getUserName(item.inspector) }}</span> <span class="info-value">{{ getUserName(item.ownerUserId) }}</span>
</div> </div>
<div v-if="item.inspectionDate" class="info-item"> <div v-if="item.inspectionDate" class="info-item">
<span class="info-label">计划完成时间:</span> <span class="info-label">计划完成时间:</span>
@ -185,9 +185,14 @@
class="summary-field" class="summary-field"
> >
<div class="field-question"> <div class="field-question">
<div class="field-question-header">
<span class="field-question-label">题目:</span> <span class="field-question-label">题目:</span>
<span class="field-question-text">{{ field.name }}</span> <span class="field-question-text">{{ field.name }}</span>
</div> </div>
<div v-if="field.remark" class="field-question-remark">
{{ field.remark }}
</div>
</div>
<div class="field-answer"> <div class="field-answer">
<span class="field-answer-label">答案:</span> <span class="field-answer-label">答案:</span>
<span v-if="field.type === 6" class="field-value-image"> <span v-if="field.type === 6" class="field-value-image">
@ -231,10 +236,12 @@
/> />
</div> </div>
<div v-if="item.remark" class="card-remark"> <div v-if="item.remark" class="card-remark">
<div class="remark-wrapper">
<span class="remark-label">备注:</span> <span class="remark-label">备注:</span>
<span class="remark-content">{{ item.remark }}</span> <span class="remark-content">{{ item.remark }}</span>
</div> </div>
</div> </div>
</div>
</el-card> </el-card>
</el-timeline-item> </el-timeline-item>
</el-timeline> </el-timeline>
@ -266,9 +273,9 @@
:formatter="dateFormatter" :formatter="dateFormatter"
width="180" width="180"
/> />
<el-table-column label="巡检人" align="center" prop="inspector"> <el-table-column label="巡检人" align="center" prop="ownerUserId">
<template #default="scope"> <template #default="scope">
{{ getUserName(scope.row.inspector) }} {{ getUserName(scope.row.ownerUserId) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="配置类型" align="center" prop="configType" width="180"> <el-table-column label="配置类型" align="center" prop="configType" width="180">
@ -350,9 +357,9 @@
:formatter="dateFormatter" :formatter="dateFormatter"
width="180" width="180"
/> />
<el-table-column label="巡检人" align="center" prop="inspector"> <el-table-column label="巡检人" align="center" prop="ownerUserId">
<template #default="scope"> <template #default="scope">
{{ getUserName(scope.row.inspector) }} {{ getUserName(scope.row.ownerUserId) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="配置类型" align="center" prop="configType" width="180"> <el-table-column label="配置类型" align="center" prop="configType" width="180">
@ -433,9 +440,9 @@
:formatter="dateFormatter" :formatter="dateFormatter"
width="180" width="180"
/> />
<el-table-column label="巡检人" align="center" prop="inspector"> <el-table-column label="巡检人" align="center" prop="ownerUserId">
<template #default="scope"> <template #default="scope">
{{ getUserName(scope.row.inspector) }} {{ getUserName(scope.row.ownerUserId) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="配置类型" align="center" prop="configType" width="180"> <el-table-column label="配置类型" align="center" prop="configType" width="180">
@ -537,7 +544,7 @@ const queryParams = reactive({
pageSize: 10, pageSize: 10,
projectId: undefined, projectId: undefined,
inspectionDate: [], inspectionDate: [],
inspector: undefined, ownerUserId: undefined,
overallStatus: undefined, overallStatus: undefined,
}) })
const queryFormRef = ref() // 搜索的表单 const queryFormRef = ref() // 搜索的表单
@ -701,7 +708,7 @@ const getProjectName = (projectId: number | undefined) => {
/** 获取用户名称 */ /** 获取用户名称 */
const getUserName = (userId: number | string | undefined) => { const getUserName = (userId: number | string | undefined) => {
if (!userId && userId !== 0) return '' if (!userId && userId !== 0) return ''
// 处理类型不匹配问题:inspector可能是字符串,需要转换为数字进行比较 // 处理类型不匹配问题:ownerUserId可能是字符串,需要转换为数字进行比较
const userIdNum = typeof userId === 'string' ? Number(userId) : userId const userIdNum = typeof userId === 'string' ? Number(userId) : userId
// 避免NaN的情况 // 避免NaN的情况
if (isNaN(userIdNum as number)) return String(userId) if (isNaN(userIdNum as number)) return String(userId)
@ -750,11 +757,11 @@ const canShowUploadButton = (row: ProjectInspectionRecordApi.ProjectInspectionRe
} }
// 3. 只有巡检人或者管理员才能看到 // 3. 只有巡检人或者管理员才能看到
const inspectorIdNum = typeof row.inspector === 'string' ? Number(row.inspector) : row.inspector const ownerUserIdIdNum = typeof row.ownerUserId === 'string' ? Number(row.ownerUserId) : row.ownerUserId
const currentUserId = userStore.user.id const currentUserId = userStore.user.id
// 是巡检人 // 是巡检人
if (currentUserId === inspectorIdNum) { if (currentUserId === ownerUserIdIdNum) {
return true return true
} }
@ -795,7 +802,7 @@ const parseSummaryData = (summary: string) => {
// 检查是否是新的JSON格式(包含type字段的数组) // 检查是否是新的JSON格式(包含type字段的数组)
if (typeof data === 'object' && !Array.isArray(data) && data !== null) { if (typeof data === 'object' && !Array.isArray(data) && data !== null) {
const result: Record<string, Array<{ name: string; value: any; type: number }>> = {} const result: Record<string, Array<{ name: string; value: any; type: number; remark?: string }>> = {}
Object.keys(data).forEach((key) => { Object.keys(data).forEach((key) => {
const value = data[key] const value = data[key]
// 检查是否是数组,且数组元素包含type字段 // 检查是否是数组,且数组元素包含type字段
@ -1158,10 +1165,16 @@ watch(list, (newList) => {
padding-bottom: 8px; padding-bottom: 8px;
border-bottom: 1px dashed #dcdfe6; border-bottom: 1px dashed #dcdfe6;
.field-question-header {
display: flex;
align-items: flex-start;
gap: 6px;
margin-bottom: 6px;
.field-question-label { .field-question-label {
font-weight: 600; font-weight: 600;
color: #409EFF; color: #409EFF;
margin-right: 6px; flex-shrink: 0;
font-size: 13px; font-size: 13px;
} }
@ -1169,6 +1182,26 @@ watch(list, (newList) => {
font-weight: 500; font-weight: 500;
color: #303133; color: #303133;
word-break: break-word; word-break: break-word;
flex: 1;
}
}
.field-question-remark {
font-size: 12px;
color: #909399;
line-height: 1.5;
word-break: break-word;
padding: 6px 10px;
background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
border-radius: 4px;
border-left: 3px solid #409EFF;
margin-top: 6px;
&::before {
content: '💡';
margin-right: 6px;
font-size: 12px;
}
} }
} }
@ -1241,9 +1274,29 @@ watch(list, (newList) => {
} }
} }
.remark-wrapper {
display: flex;
align-items: flex-start;
gap: 8px;
padding: 10px 12px;
background-color: #f8f9fa;
border-radius: 6px;
border-left: 3px solid #909399;
.remark-label {
color: #909399;
font-weight: 500;
flex-shrink: 0;
margin-right: 0;
}
.remark-content { .remark-content {
color: #606266; color: #606266;
line-height: 1.6; line-height: 1.6;
word-break: break-word;
flex: 1;
white-space: pre-wrap;
}
} }
} }
} }