人员资质修改正常接收数据

This commit is contained in:
何德超 2025-07-24 20:53:50 +08:00
parent b028f2a7bd
commit cf780323e0
3 changed files with 84 additions and 122 deletions

View File

@ -1,5 +1,5 @@
import http from '@/utils/http' import http from '@/utils/http'
import type { CertificationInfo, CertificationListParams, CertificationListResponse, SimpleUserInfo } from './type' import type { CertificationInfo, CertificationListParams, CertificationListResponse, SimpleUserInfo,CertificationPageResponse, CertificationReq } from './type'
const { request } = http const { request } = http
@ -7,7 +7,7 @@ const { request } = http
export type { CertificationInfo, CertificationListParams, CertificationListResponse, SimpleUserInfo } export type { CertificationInfo, CertificationListParams, CertificationListResponse, SimpleUserInfo }
// 新增人员资质 // 新增人员资质
export function createCertification(data: CertificationInfo) { export function createCertification(data: CertificationReq) {
return request({ return request({
url: '/certification', url: '/certification',
method: 'post', method: 'post',
@ -74,4 +74,12 @@ export function getUserList() {
url: '/user/list', url: '/user/list',
method: 'get' method: 'get'
}) })
} }
// 查询人员资质信息分页列表(新接口)
export function getCertificationPage(params: CertificationListParams) {
return request<CertificationPageResponse>({
url: '/certification/page',
method: 'get',
params
})
}

View File

@ -11,19 +11,25 @@ export interface CertificationInfo {
createTime?: string createTime?: string
updateTime?: string updateTime?: string
} }
export interface CertificationReq {
certificationCode: string
certificationImage: string
certificationName: string
certificationType: string
userId: string
validityDateBegin: string
validityDateEnd: string
}
/** 人员资质列表查询参数 */ /** 人员资质列表查询参数 */
export interface CertificationListParams { export interface CertificationListParams {
certificationName?: string certificationName?: string
certificationType?: string certificationType?: string
userName?: string userName?: string
current?: number
size?: number
} }
/** 人员资质列表响应 */ /** 人员资质列表响应 */
export interface CertificationListResponse { export interface CertificationListResponse {
records: CertificationInfo[] data: CertificationInfo[]
total: number total: number
current: number current: number
size: number size: number
@ -32,7 +38,22 @@ export interface CertificationListResponse {
/** 用户信息简化版 */ /** 用户信息简化版 */
export interface SimpleUserInfo { export interface SimpleUserInfo {
userId: string userId: string
userName: string
account: string
name: string name: string
} account: string
}
export interface CertificationInfo {
certificationId?: string
certificationCode: string
certificationName: string
userId: string
userName?: string // 新增,后端会返回
}
// 分页响应
export interface CertificationPageResponse {
rows: CertificationInfo[]
total: number
code?: number
msg?: string
[key: string]: any
}

View File

@ -15,30 +15,15 @@
<a-card class="search-card" :bordered="false"> <a-card class="search-card" :bordered="false">
<a-form :model="searchForm" layout="inline"> <a-form :model="searchForm" layout="inline">
<a-form-item label="证书名称" field="certificationName"> <a-form-item label="证书名称" field="certificationName">
<a-input <a-input v-model="searchForm.certificationName" placeholder="请输入证书名称" allow-clear style="width: 200px" />
v-model="searchForm.certificationName"
placeholder="请输入证书名称"
allow-clear
style="width: 200px"
/>
</a-form-item> </a-form-item>
<a-form-item label="证书类型" field="certificationType"> <a-form-item label="证书类型" field="certificationType">
<a-input <a-input v-model="searchForm.certificationType" placeholder="请输入证书类型" allow-clear style="width: 200px" />
v-model="searchForm.certificationType"
placeholder="请输入证书类型"
allow-clear
style="width: 200px"
/>
</a-form-item> </a-form-item>
<a-form-item label="用户姓名" field="userName"> <a-form-item label="用户姓名" field="userName">
<a-input <a-input v-model="searchForm.userName" placeholder="请输入用户姓名" allow-clear style="width: 200px" />
v-model="searchForm.userName"
placeholder="请输入用户姓名"
allow-clear
style="width: 200px"
/>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
@ -62,28 +47,15 @@
<!-- 人员资质表格 --> <!-- 人员资质表格 -->
<a-card class="table-card" :bordered="false"> <a-card class="table-card" :bordered="false">
<a-table <a-table :columns="columns" :data="certificationList" :pagination="paginationConfig" :loading="loading"
:columns="columns" row-key="certificationId" @page-change="handlePageChange">
:data="certificationList"
:pagination="paginationConfig"
:loading="loading"
row-key="certificationId"
@page-change="handlePageChange"
>
<template #userName="{ record }"> <template #userName="{ record }">
<span>{{ getUserName(record.userId) }}</span> <span>{{ getUserName(record.userId) }}</span>
</template> </template>
<template #certificationImage="{ record }"> <template #certificationImage="{ record }">
<a-image <a-image v-if="record.certificationImage" :src="record.certificationImage" width="60" height="40"
v-if="record.certificationImage" fit="cover" show-loader preview />
:src="record.certificationImage"
width="60"
height="40"
fit="cover"
show-loader
preview
/>
<span v-else>-</span> <span v-else>-</span>
</template> </template>
@ -105,19 +77,9 @@
</a-card> </a-card>
<!-- 新增/编辑资质信息模态框 --> <!-- 新增/编辑资质信息模态框 -->
<a-modal <a-modal v-model:visible="modalVisible" :title="isEdit ? '编辑资质信息' : '新增资质信息'" width="700px" @ok="handleSubmit"
v-model:visible="modalVisible" @cancel="handleCancel">
:title="isEdit ? '编辑资质信息' : '新增资质信息'" <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
width="700px"
@ok="handleSubmit"
@cancel="handleCancel"
>
<a-form
ref="formRef"
:model="formData"
:rules="formRules"
layout="vertical"
>
<a-row :gutter="16"> <a-row :gutter="16">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="证书编号" field="certificationCode"> <a-form-item label="证书编号" field="certificationCode">
@ -141,19 +103,9 @@
<a-col :span="12"> <a-col :span="12">
<a-form-item label="持证人" field="userId"> <a-form-item label="持证人" field="userId">
<a-select <a-select v-model="formData.userId" placeholder="请选择持证人" :loading="loadingUsers" allow-search
v-model="formData.userId" :filter-option="filterUserOption" @="console.log('d', formData)">
placeholder="请选择持证人" <a-option v-for="user in userList" :key="user.userId" :value="user.userId" :label="user.name">
:loading="loadingUsers"
allow-search
:filter-option="filterUserOption"
>
<a-option
v-for="user in userList"
:key="user.userId"
:value="user.userId"
:label="user.name"
>
{{ user.name }}({{ user.account }}) {{ user.name }}({{ user.account }})
</a-option> </a-option>
</a-select> </a-select>
@ -164,43 +116,24 @@
<a-row :gutter="16"> <a-row :gutter="16">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="有效期开始" field="validityDateBegin"> <a-form-item label="有效期开始" field="validityDateBegin">
<a-date-picker <a-date-picker v-model="formData.validityDateBegin" placeholder="请选择有效期开始日期" style="width: 100%" />
v-model="formData.validityDateBegin"
placeholder="请选择有效期开始日期"
style="width: 100%"
/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12"> <a-col :span="12">
<a-form-item label="有效期结束" field="validityDateEnd"> <a-form-item label="有效期结束" field="validityDateEnd">
<a-date-picker <a-date-picker v-model="formData.validityDateEnd" placeholder="请选择有效期结束日期" style="width: 100%" />
v-model="formData.validityDateEnd"
placeholder="请选择有效期结束日期"
style="width: 100%"
/>
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
<a-form-item label="证书图片" field="certificationImage"> <a-form-item label="证书图片" field="certificationImage">
<a-upload <a-upload :custom-request="handleUpload" :show-file-list="false" accept="image/*"
:custom-request="handleUpload" :before-upload="beforeUpload">
:show-file-list="false"
accept="image/*"
:before-upload="beforeUpload"
>
<template #upload-button> <template #upload-button>
<div class="upload-wrapper"> <div class="upload-wrapper">
<a-image <a-image v-if="formData.certificationImage" :src="formData.certificationImage" width="200"
v-if="formData.certificationImage" height="120" fit="cover" show-loader preview />
:src="formData.certificationImage"
width="200"
height="120"
fit="cover"
show-loader
preview
/>
<div v-else class="upload-placeholder"> <div v-else class="upload-placeholder">
<icon-plus /> <icon-plus />
<div>点击上传证书图片</div> <div>点击上传证书图片</div>
@ -233,7 +166,7 @@ const isEdit = ref(false)
const formRef = ref() const formRef = ref()
// //
const certificationList = ref<CertificationInfo[]>([]) const certificationList = ref<CertificationAPI.CertificationListResponse>()
const userList = ref<SimpleUserInfo[]>([]) const userList = ref<SimpleUserInfo[]>([])
// //
@ -254,14 +187,14 @@ const paginationConfig = reactive({
// //
const formData = reactive<CertificationInfo>({ const formData = reactive<CertificationInfo>({
certificationId: '',
certificationCode: '', certificationCode: '',
certificationImage: '', certificationImage: 'n',
certificationName: '', certificationName: '',
certificationType: '', certificationType: '',
userId: '', userId: '',
validityDateBegin: '', validityDateBegin: '',
validityDateEnd: '' validityDateEnd: '',
// certificationTypeLabel: ''
}) })
// //
@ -305,7 +238,7 @@ const columns = [
}, },
{ {
title: '持证人', title: '持证人',
dataIndex: 'userId', dataIndex: 'userName',
slotName: 'userName', slotName: 'userName',
width: 120 width: 120
}, },
@ -339,10 +272,10 @@ const getUserName = (userId: string) => {
const filterUserOption = (inputValue: string, option: any) => { const filterUserOption = (inputValue: string, option: any) => {
const user = userList.value.find(u => u.userId === option.value) const user = userList.value.find(u => u.userId === option.value)
if (!user) return false if (!user) return false
const searchText = inputValue.toLowerCase() const searchText = inputValue.toLowerCase()
return user.name.toLowerCase().includes(searchText) || return user.name.toLowerCase().includes(searchText) ||
user.account.toLowerCase().includes(searchText) user.account.toLowerCase().includes(searchText)
} }
// //
@ -350,11 +283,16 @@ const getUserList = async () => {
try { try {
loadingUsers.value = true loadingUsers.value = true
const response = await CertificationAPI.getUserList() const response = await CertificationAPI.getUserList()
console.log('用户列表响应:', response) console.log('用户列表响应:', response)
if (response.data) { if (response.data) {
userList.value = response.data || [] userList.value = response.data.map(item => ({
userId: item.userId,
name: item.name,
account: item.account,
})) || []
console.log('用户列表响应2:', userList.value)
} }
} catch (error) { } catch (error) {
console.error('获取用户列表失败:', error) console.error('获取用户列表失败:', error)
@ -370,20 +308,15 @@ const getCertificationList = async () => {
loading.value = true loading.value = true
const params: CertificationListParams = { const params: CertificationListParams = {
...searchForm, ...searchForm,
current: paginationConfig.current,
size: paginationConfig.pageSize
} }
const response = await CertificationAPI.getCertificationList(params) const response = await CertificationAPI.getCertificationList(params)
console.log('资质信息列表响应:', response)
if (response.data) { if (response.data) {
certificationList.value = response.data.records || [] certificationList.value = response.data || []
paginationConfig.total = response.data.total || 0 paginationConfig.total = response.data.total || 0
console.log('cc', certificationList.value)
console.log('cd', response.data[0])
} }
} catch (error) { } catch (error) {
console.error('获取资质信息列表失败:', error)
Message.error('获取资质信息列表失败') Message.error('获取资质信息列表失败')
} finally { } finally {
loading.value = false loading.value = false
@ -397,13 +330,13 @@ const beforeUpload = (file: File) => {
Message.error('只能上传图片文件') Message.error('只能上传图片文件')
return false return false
} }
const isLt2M = file.size / 1024 / 1024 < 2 const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) { if (!isLt2M) {
Message.error('图片大小不能超过 2MB') Message.error('图片大小不能超过 2MB')
return false return false
} }
return true return true
} }
@ -412,9 +345,9 @@ const handleUpload = async (option: any) => {
try { try {
const uploadFormData = new FormData() const uploadFormData = new FormData()
uploadFormData.append('file', option.fileItem.file) uploadFormData.append('file', option.fileItem.file)
const response = await uploadFile(uploadFormData) const response = await uploadFile(uploadFormData)
if (response.data && response.data.url) { if (response.data && response.data.url) {
formData.certificationImage = response.data.url formData.certificationImage = response.data.url
Message.success('图片上传成功') Message.success('图片上传成功')
@ -491,7 +424,7 @@ const deleteRecord = (record: CertificationInfo) => {
const handleSubmit = async () => { const handleSubmit = async () => {
try { try {
await formRef.value?.validate() await formRef.value?.validate()
if (isEdit.value) { if (isEdit.value) {
await CertificationAPI.updateCertification(formData.certificationId!, formData) await CertificationAPI.updateCertification(formData.certificationId!, formData)
Message.success('更新成功') Message.success('更新成功')
@ -499,7 +432,7 @@ const handleSubmit = async () => {
await CertificationAPI.createCertification(formData) await CertificationAPI.createCertification(formData)
Message.success('创建成功') Message.success('创建成功')
} }
modalVisible.value = false modalVisible.value = false
resetForm() resetForm()
await getCertificationList() await getCertificationList()
@ -598,4 +531,4 @@ onMounted(() => {
font-size: 24px; font-size: 24px;
margin-bottom: 8px; margin-bottom: 8px;
} }
</style> </style>