<!-- 选择标准装置 -->
<script lang="ts" setup name="SelectStandardDialog">
import { ElMessage } from 'element-plus'
import type { Ref } from 'vue'
import { ref } from 'vue'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import { getStandardList } from '@/api/equipment/standard/book'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getDeptTreeList } from '@/api/system/dept'
import { getStaffList } from '@/api/resource/register'
import { toTreeList } from '@/utils/structure'
import type { deptType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import useUserStore from '@/store/modules/user'
const props = defineProps({
isMulti: { // 是否多选
type: Boolean,
default: false, // 默认单选
},
isSelectDeptId: {
type: Boolean,
default: true,
},
})
// 用户信息
const emits = defineEmits(['confirm'])
const user = useUserStore()
const dialogFormVisible = ref(false)
const standardId = ref('') // 标准装置id
// 查询条件
const listQuery = ref({
approvalStatus: '0', // 审批状态
deptId: props.isSelectDeptId ? user.deptId : '', // 部门id
formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
groupCode: '', // 组别代码
inUseStatus: '', // 在用状态
labCode: '', // 实验室名称
lastChangeDateStart: '', // 最近变更日期开始
lastChangeDateEnd: '', // 最近变更日期结束
lastReviewDateStart: '', // 最近复查日期开始
lastReviewDateEnd: '', // 最近复查日期结束
nextReviewDateStart: '', // 下次复查日期开始
nextReviewDateEnd: '', // 下次复查日期结束
majorType: '', // 专业类别
standardName: '', // 计量标准装置名称
standardNo: '', // 计量标准证书号
storageLocation: '', // 存放地点(字典code)
technologyFileName: '', // 依据技术文件名称
offset: 1,
limit: props.isMulti ? 5 : 20,
})
// 多选选中的内容
const checkoutList = ref([])
const loadingTable = ref(false)
const list = ref([]) // 表格数据
const total = ref(0)
const columns = ref<TableColumn[]>([
{ text: '计量标准证书号', value: 'standardCertNo', align: 'center' },
{ text: '计量标准装置名称', value: 'standardName', align: 'center' },
{ text: '实验室', value: 'labCodeName', align: 'center', width: '120' },
{ text: '部门', value: 'groupCodeName', align: 'center', width: '120' },
{ text: '专业类别', value: 'majorTypeName', align: 'center', width: '120' },
{ text: '最近复查日期', value: 'lastReviewDate', align: 'center', width: '120' },
{ text: '下次复查日期', value: 'nextReviewDate', align: 'center', width: '120' },
{ text: '在用状态', value: 'manageStatusName', align: 'center' },
{ text: '最近变更日期', value: 'lastChangeDate', align: 'center', width: '120' },
{ text: '标准证书', value: 'standardCertFile', align: 'center' },
])
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
// -----------------------------------------字典--------------------------------------------------------------
const bizStandardManagerStateList = ref({}) as any // 在用状态
// 查询字典
const getDict = async () => {
// 在用状态
getDictByCode('bizStandardManagerState').then((response) => {
bizStandardManagerStateList.value = response.data
})
}
// --------------------------------------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.value.offset = 1
}
getStandardList(listQuery.value).then((response) => {
list.value = response.data.rows.map((item: { lastReviewDate: string; agreementAmount: number }) => {
return {
...item,
lastReviewDate: item.lastReviewDate ? dayjs(item.lastReviewDate).format('YYYY-MM-DD') : item.lastReviewDate, // 最近复查日期
}
})
total.value = parseInt(response.data.total)
loadingTable.value = false
}).catch(() => {
loadingTable.value = false
})
}
// 重置
const clearList = () => {
listQuery.value = {
approvalStatus: '0', // 审批状态
deptId: props.isSelectDeptId ? user.deptId : '', // 部门id
formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
groupCode: '', // 组别代码
inUseStatus: '', // 在用状态
labCode: '', // 实验室名称
lastChangeDateStart: '', // 最近变更日期开始
lastChangeDateEnd: '', // 最近变更日期结束
lastReviewDateStart: '', // 最近复查日期开始
lastReviewDateEnd: '', // 最近复查日期结束
nextReviewDateStart: '', // 下次复查日期开始
nextReviewDateEnd: '', // 下次复查日期结束
majorType: '', // 专业类别
standardName: '', // 计量标准装置名称
standardNo: '', // 计量标准证书号
storageLocation: '', // 存放地点(字典code)
technologyFileName: '', // 依据技术文件名称
offset: 1,
limit: props.isMulti ? 5 : 20,
}
dateRange.value = ['', '']
fetchData()
}
// 搜索
const search = () => {
fetchData(true)
}
// 多选选中
const handleSelectionChange = (val: any) => {
checkoutList.value = val
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number;page?: number }) => {
if (val && val.size) {
listQuery.value.limit = val.size
}
if (val && val.page) {
listQuery.value.offset = val.page
}
search()
}
// 点击确定
const confirmSelect = () => {
if (!checkoutList.value.length) {
ElMessage.warning('请选择标准装置')
}
else {
emits('confirm', checkoutList.value)
dialogFormVisible.value = false
}
}
// 取消
const resetForm = () => {
dialogFormVisible.value = false
clearList()
}
// 初始化
const initDialog = async (id: string) => {
await getDict()
dialogFormVisible.value = true
fetchData()
}
defineExpose({ initDialog })
</script>
<template>
<el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择标准装置" width="65%">
<!-- 筛选条件 -->
<search-area :need-clear="true" @search="search" @clear="clearList">
<search-item>
<el-input v-model.trim="listQuery.standardNo" placeholder="计量标准证书号" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.standardName" placeholder="计量标准装置名称" class="short-input" clearable />
</search-item>
<search-item>
<el-select
v-model="listQuery.inUseStatus"
placeholder="在用状态"
class="short-input"
filterable
clearable
>
<el-option v-for="item in bizStandardManagerStateList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
</search-area>
<!-- 查询结果Table显示 -->
<div style="padding: 12px;">
<normal-table
:data="list"
:total="total"
:columns="columns"
:query="listQuery"
is-showmulti-select
:list-loading="loadingTable"
:is-multi="props.isMulti"
:height="260"
@change="changePage"
@multi-select="handleSelectionChange"
>
<!-- 序号 -->
<template #preColumns>
<el-table-column label="#" width="55" align="center" fixed>
<template #default="scope">
{{ (listQuery.offset - 1) * listQuery.limit + 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>