<!-- 选择开展量传参数 单选 -->
<script lang="ts" setup name="SelectStaffDialog">
import { ElMessage } from 'element-plus'
import { ref } from 'vue'
import { getStaffList } from '@/api/resource/register'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import verifierParams from '/public/config/verifierParameter.json'
import { getAllStaffByName } from '@/api/equipment/standard/book'
const emits = defineEmits(['confirm'])
const dialogFormVisible = ref(false)
const verifierParamsList = ref([]) as any
verifierParamsList.value = verifierParams.map((item: any) => {
return {
name: item.name,
value: item.value,
}
})
const filterItem = ref('') // 项目-做筛选用
// 多选选中的内容
const checkoutList = ref([])
const loadingTable = ref(false)
const list = ref([]) // 表格数据
const total = ref(0)
const columns = ref<TableColumn[]>([
{ text: '开展量传参数名称', value: 'name', align: 'center', width: '160' },
{ text: '持有该参数人员', value: 'staffName', align: 'center' },
])
// 通过检定或校准名称获取持有该参数的人员
const fetchPersonByProject = () => {
loadingTable.value = true
const allRequest: any = [] // 所有的请求
verifierParamsList.value.forEach((item: any) => {
const request = getAllStaffByName({ name: item.name }).then((res) => {
const personList = res.data.map((item: { id: string; staffName: string }) => {
return {
staffId: item.id,
staffName: item.staffName,
}
})
item.personList = personList
if (personList && personList.length) {
item.staffName = personList.map((item: any) => item.staffName).join(',')
}
})
allRequest.push(request)
})
Promise.all(allRequest).then(() => {
list.value = verifierParamsList.value
loadingTable.value = false
})
}
// 多选选中
const handleSelectionChange = (val: any) => {
checkoutList.value = val
}
// 点击查询
const searchList = () => {
if (filterItem.value) {
list.value = verifierParamsList.value.filter((item: { name: string }) => item.name === filterItem.value)
}
else {
list.value = verifierParamsList.value
}
}
// 点击重置
const clearList = () => {
list.value = verifierParamsList.value
}
// 点击确定
const confirmSelect = () => {
if (!checkoutList.value.length) {
ElMessage.warning('请选择开展量传参数')
}
else {
emits('confirm', checkoutList.value)
dialogFormVisible.value = false
}
}
// 取消
const resetForm = () => {
dialogFormVisible.value = false
}
// 初始化
const initDialog = () => {
fetchPersonByProject()
dialogFormVisible.value = true
}
defineExpose({ initDialog })
</script>
<template>
<el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择开展量传参数" width="65%">
<!-- 筛选条件 -->
<search-area :need-clear="true" @search="searchList" @clear="clearList">
<search-item>
<el-input v-model="filterItem" placeholder="开展量传参数名称" clearable />
</search-item>
</search-area>
<!-- 查询结果Table显示 -->
<div style="padding: 12px;">
<normal-table
:data="list"
:total="total"
:columns="columns"
is-showmulti-select
:is-multi="true"
:list-loading="loadingTable"
:pagination="false"
:height="520"
@multi-select="handleSelectionChange"
>
<!-- 序号 -->
<template #preColumns>
<el-table-column label="#" width="55" align="center" fixed>
<template #default="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
</template>
</normal-table>
</div>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="confirmSelect">确认</el-button>
<el-button @click="resetForm">
取消
</el-button>
</span>
</template>
</el-dialog>
</template>
<style lang="scss" scoped>
:deep(.el-radio__label) {
display: none;
}
</style>