<!-- 选择计量人员弹窗 -->
<script setup lang="ts" name="SelectStaffsDialog">
import { computed, onMounted, reactive, ref, watch } from 'vue'
// import type { IEmployees } from './dialog'
import { getStaffList } from '@/api/resource/register'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
interface IEmployees {
staffName: string
id: string
}
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
data: {
type: Array,
default: () => [],
},
// 默认查询组织
deptId: {
type: String,
default: '',
},
// 过滤组织
deptName: {
type: String,
default: '',
},
// 是否显示部门选择下拉菜单
showDeptSelect: {
type: Boolean,
default: true,
},
// 是否多选
multi: {
type: Boolean,
default: true,
},
})
const emits = defineEmits(['update:visible', 'change'])
const table = ref() // 表格ref
// 表格表头
const columns = ref<TableColumn[]>([
{ text: '人员编号', value: 'staffNo', align: 'center', width: '160' },
{ text: '姓名', value: 'staffName', align: 'center' },
{ text: '岗位', value: 'station', align: 'center' },
{ text: '证号', value: 'certificateNumber', align: 'center' },
{ text: '工作部门', value: 'deptName', align: 'center' },
{ text: '计量专业', value: 'major', align: 'center' },
])
// 表格数据
const list = ref<IEmployees[]>([])
const loading = ref(false)
const total = ref(0)
// 查询参数
const listQuery = reactive({
deptId: '', // 部门id
name: '', // 姓名
deptName: '', // 工作部门名称
offset: 1,
limit: 5,
})
// 默认给deptId赋值
listQuery.deptId = props.deptId
const jobList = ref<dictType[]>([]) // 职务列表
// 多选的数据
const multipleTable = ref([])
const singleChecked = ref('') // 单选选中id
const closeDialog = () => {
emits('update:visible', false)
}
watch(() => props.visible, (val) => {
// 清除上次选中
if (!val) {
table.value.clearMulti()
}
})
function getDict() {
// 获取样品属性
getDictByCode('administrationJob').then((response) => {
jobList.value = response.data
})
}
// 点击确定,保存选择的成员配置
const saveDialog = () => {
// 多选
if (props.multi) { // 多选
const checkedList = multipleTable.value.map((item: IEmployees) => {
return {
name: item.staffName,
id: item.id,
}
})
emits('change', checkedList)
}
else { // 单选
const checkValue = list.value.find(item => item.id == singleChecked.value)
emits('change', checkValue)
}
}
const select = ref('')
// 获取列表数据
const fetchData = (isNowPage = false) => {
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.offset = 1
}
listQuery.deptId = props.deptId
loading.value = true
list.value = []
getStaffList(listQuery).then((res) => {
list.value = res.data.rows.map((item: { staffName: string }) => {
return {
...item,
name: item.staffName,
}
})
total.value = parseInt(res.data.total)
loading.value = false
})
}
const visibleDialog = computed({
get() {
fetchData(true)
return props.visible
},
set() {
closeDialog()
},
})
// 多选
const multiSelect = (val: any) => {
multipleTable.value = val
}
// 查询数据
const search = () => {
fetchData(true)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
if (val && val.size) {
listQuery.limit = val.size
}
if (val && val.page) {
listQuery.offset = val.page
}
fetchData(true)
}
onMounted(() => {
// 获取列表数据
fetchData(true)
getDict()
})
defineExpose({ fetchData })
</script>
<template>
<div class="select-emplotees-dialog">
<el-dialog v-model="visibleDialog" title="选择成员" width="65%" append-to-body custom-class="chengyuan-dialog promoter_person">
<!-- 右侧表格 -->
<div ref="tableContainer" class="table-area">
<!-- 筛选条件 -->
<search-area @search="search">
<search-item>
<el-input v-model.trim="listQuery.name" class="short-input" placeholder="姓名" clearable />
</search-item>
</search-area>
<!-- 表头标题 -->
<table-container :title-show="false" style="margin-top: 0;padding-top: 0;">
<!-- 查询结果Table显示 -->
<normal-table
ref="table"
:data="list"
:total="total"
:columns="columns"
:query="listQuery"
:list-loading="loading"
:is-showmulti-select="multi"
:page-sizes="[5]"
@change="changePage"
@multi-select="multiSelect"
>
<!-- 序号 -->
<template #preColumns>
<el-table-column label="#" width="55" align="center">
<template #default="scope">
{{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column v-if="!props.multi" label="" width="40" align="center">
<template #default="scope">
<el-radio v-model="singleChecked" :label="scope.row.id" class="radio" />
</template>
</el-table-column>
</template>
</normal-table>
</table-container>
</div>
<!-- </div> -->
<template #footer>
<el-button type="primary" @click="saveDialog">
确 定
</el-button>
<el-button @click="closeDialog">
取 消
</el-button>
</template>
</el-dialog>
</div>
</template>
<style lang="scss">
@import "@/css/dialog.css";
.chengyuan-dialog {
.el-table .cell {
white-space: nowrap;
}
.el-dialog__body {
display: flex;
overflow: auto;
}
}
</style>
<style lang="scss" scoped>
.chengyuan-dialog {
width: 100%;
.left-container {
white-space: nowrap;
height: 100%;
}
.table-area {
flex: 1;
overflow: auto;
:deep(.el-radio__label) {
display: none;
}
.pagination {
margin-top: 10px;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
}
}
</style>