<!-- 检定项管理列表 -->
<script lang="ts" setup name="BusinessMeasureItemList">
import type { Ref } from 'vue'
import { ElLoading, ElMessage } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './item-interface'
import confirmConfigDialog from './dialog/confirmConfigDialog.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { exportFile } from '@/utils/exportUtils'
import { addItem, exportItemList, getDeviceNameList, getItemList, getModelAllList, updateItem } from '@/api/business/measure/item'
const $router = useRouter()
const loadingTable = ref(false)
const operateWidth = ref('160') // 操作栏的宽度
// 查询条件
const listQuery: Ref<IListQuery> = ref({
dataSync: '', // 检定项数据是否同步
deviceName: '', // 设备名称
deviceType: '', // 设备分类
helpInstruction: '', // 辅助字段
model: '', // 型号规格
syncTimeEnd: '', // 自动检定系统最新同步时间结束
syncTimeStart: '', // 自动检定系统最新同步时间开始
limit: 20,
offset: 1,
})
// 表头
const columns = ref<TableColumn[]>([
{ text: '设备名称', value: 'deviceName', align: 'center' },
{ text: '型号规格', value: 'model', align: 'center' },
{ text: '辅助字段', value: 'helpInstruction', align: 'center' },
{ text: '辅助字段说明', value: 'helpInstruction', align: 'center' },
{ text: '设备分类', value: 'deviceTypeName', align: 'center' },
{ text: '检校标准装置', value: 'belongStandardEquipmentName', align: 'center' },
{ text: '设备检定项分类', value: 'itemCategoryName', align: 'center' },
{ text: '检定项更新时间', value: 'updateTime', align: 'center', width: '180' },
{ text: '自动检定系统数据是否同步', value: 'dataSyncStr', align: 'center' },
{ text: '自动检定系统最新同步时间', value: 'updateTime', align: 'center', width: '180' },
])
const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
const checkoutList = ref<IList[]>([]) // 选中的内容
const timeRange = ref<[DateModelType, DateModelType]>(['', '']) // 查询条件
const selectedRow = ref<IList>() // 点击操作的行数据
// ------------------------------------------字典----------------------------------------------
const deviceTypeList = ref<dictType[]>([])// 设备分类
const deviceTypeMap = ref({}) as any // 设备分类map
const isSyncMap = ref({}) as any // 是否同步{1: 是}
const isSyncList = ref({}) as any // 是否同步
const deviceNameList = ref<string[]>([]) // 设备名称
const modelList = ref<any[]>([])// 规格型号
const helpList = ref<any[]>([])// 辅助字段
const allList = ref<any[]>([])
async function getDict() {
// 是否同步
getDictByCode('bizBusinessMeasureIsSync').then((response) => {
isSyncList.value = response.data
response.data.forEach((item: any) => {
isSyncMap.value[`${item.value}`] = item.name
})
})
// 设备分类
const res = await getDictByCode('eqptDeviceType')
deviceTypeList.value = res.data
res.data.forEach((item: any) => {
deviceTypeMap.value[`${item.value}`] = item.name
})
// 设备名称
getDeviceNameList().then((res) => {
deviceNameList.value = res.data
})
// 规格型号及辅助字段
getModelAllList({}).then((res) => {
allList.value = res.data
modelList.value = Array.from(new Set(res.data.filter((item: any) => item.model).map((item: any) => item.model)))
helpList.value = Array.from(new Set(res.data.filter((item: any) => item.helpInstruction).map((item: any) => item.helpInstruction)))
})
}
// --------------------------------------配置检定项--------------------------------------------
const confirmConfigRef = ref() // 点击配置检定项确认操作对话框组件ref
// 确认配置检定项
const confirmConfig = async (form: any) => {
const loading = ElLoading.service({
lock: true,
text: '加载中',
background: 'rgba(255, 255, 255, 0.6)',
})
let getId = ''
if (form.configType === 'add') {
const res = await addItem({ ...selectedRow.value!, appearanceFunctionCheck: '', dataSync: '', itemCategoryName: form.itemCategoryName, itemCategoryId: form.itemCategoryId, belongStandardEquipment: form.belongStandardEquipment, belongStandardEquipmentName: form.belongStandardEquipmentName })
getId = res.data
}
else {
const res = await updateItem({ ...selectedRow.value!, appearanceFunctionCheck: '', dataSync: '', itemCategoryName: form.itemCategoryName, itemCategoryId: form.itemCategoryId, belongStandardEquipment: form.belongStandardEquipment, belongStandardEquipmentName: form.belongStandardEquipmentName })
getId = res.data
}
loading.close()
$router.push({
path: `measureItem/edit/${getId}`,
query: {
...selectedRow.value!,
deviceType: form.deviceType, // 设备分类(检校分类)
itemCategoryId: form.itemCategoryId, // 设备检定项分类id
itemCategoryName: form.itemCategoryName, // 设备检定项分类名称
belongStandardEquipment: form.belongStandardEquipment, // 检校标准装置(字典code)
},
})
}
// ---------------------------------------------------------------------------------------------
// 多选发生改变时
function handleSelectionChange(e: any) {
checkoutList.value = e
}
// 数据查询
function fetchData(isNowPage = false) {
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.value.offset = 1
}
getItemList(listQuery.value).then((response) => {
list.value = response.data.rows.map((item: { deviceType: string }) => {
return {
...item,
deviceTypeName: deviceTypeMap.value[item.deviceType], // 设备分类
}
})
total.value = parseInt(response.data.total)
loadingTable.value = false
console.log(list.value)
})
}
// 清除条件
const clearList = () => {
listQuery.value = {
dataSync: '', // 检定项数据是否同步
deviceName: '', // 设备名称
deviceType: '', // 设备分类
helpInstruction: '', // 辅助字段
model: '', // 型号规格
syncTimeEnd: '', // 自动检定系统最新同步时间结束
syncTimeStart: '', // 自动检定系统最新同步时间开始
limit: 20,
offset: 1,
}
timeRange.value = ['', '']
getDict()
fetchData()
}
// 搜索
const searchList = () => {
fetchData(true)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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
}
fetchData(true)
}
// 操作
const handleEdit = (row: IList, val: 'detail' | 'config') => {
selectedRow.value = row // 表格行数据
if (val === 'detail') {
$router.push({
path: `measureItem/${val}/${row.id}`,
query: {
...row,
deviceType: row.deviceType, // 设备分类(检校分类)
itemCategoryId: row.itemCategoryId, // 设备检定项分类id
itemCategoryName: row.itemCategoryName, // 设备检定项分类名称
belongStandardEquipment: row.belongStandardEquipment, // 检校标准装置(字典code)
},
})
}
else if (val === 'config') { // 配置检定项
confirmConfigRef.value.initDialog(row.configType ? row.configType : 'edit', row.deviceType, row.belongStandardEquipment, row.itemCategoryId)
}
}
// 导出
const exportAll = () => {
const loading = ElLoading.service({
lock: true,
text: '下载中请稍后',
background: 'rgba(255, 255, 255, 0.6)',
})
if (list.value.length > 0) {
const params = {
dataSync: listQuery.value.dataSync, // 检定项数据是否同步
deviceName: listQuery.value.deviceName, // 设备名称
deviceType: listQuery.value.deviceType, // 设备分类
helpInstruction: listQuery.value.helpInstruction, // 辅助字段
model: listQuery.value.model, // 型号规格
syncTimeEnd: listQuery.value.syncTimeEnd, // 自动检定系统最新同步时间结束
syncTimeStart: listQuery.value.syncTimeStart, // 自动检定系统最新同步时间开始
offset: 1,
limit: 20,
ids: checkoutList.value.map(item => item.id),
}
exportItemList(params).then((res) => {
const blob = new Blob([res.data])
loading.close()
exportFile(blob, '监测设备.xlsx')
})
}
else {
loading.close()
ElMessage.warning('无数据可导出数据')
}
}
// 点击增加配置项
const addConfig = () => {
if (checkoutList.value.length > 1) {
ElMessage.warning('只允许选择一条数据')
return false
}
if (!checkoutList.value.length) {
ElMessage.warning('请选中数据')
return false
}
console.log(checkoutList.value)
if (!checkoutList.value[0].id && !checkoutList.value[0].belongStandardEquipment && !checkoutList.value[0].itemCategoryId) {
ElMessage.warning('选中设备未配置检定项,不允许再增加')
return false
}
const index = list.value.findIndex(item => item.id === checkoutList.value[0].id)
console.log(index)
if (index !== -1) {
list.value.splice(index + 1, 0, {
id: '',
deviceName: checkoutList.value[0].deviceName, // 设备名称
model: checkoutList.value[0].model, // 型号规格
helpInstruction: checkoutList.value[0].helpInstruction, // 辅助字段
helpFieldInstruction: checkoutList.value[0].helpFieldInstruction, // 辅助字段说明
deviceType: checkoutList.value[0].deviceType, // 设备分类(检校分类)
deviceTypeName: checkoutList.value[0].deviceTypeName, // 设备分类(检校分类)名称
belongStandardEquipment: checkoutList.value[0].belongStandardEquipment, // 检校标准装置
belongStandardEquipmentName: checkoutList.value[0].belongStandardEquipmentName, // 检校标准装置名称
itemCategoryId: checkoutList.value[0].itemCategoryId, // 设备检定项分类id
itemCategoryName: checkoutList.value[0].itemCategoryName, // 设备检定项分类
checkCycle: checkoutList.value[0].checkCycle,
eqptDeviceModelId: checkoutList.value[0].eqptDeviceModelId,
deviceModelId: checkoutList.value[0].deviceModelId,
updateTime: '', // 检定项更新时间
dataSyncStr: '', // 自动检定系统数据是否同步
syncTime: '', // 自动检定系统最新同步时间
configType: 'add', // 检定项配置类型-新增
})
}
}
// ---------------------------------------钩子----------------------------------------------
// 监听设备名称下拉框,修改规格型号和辅助字段
watch(() => listQuery.value.deviceName, (newVal) => {
listQuery.value.helpInstruction = '' // 辅助字段清空
listQuery.value.model = '' // 型号规格清空
// 修改规格型号和辅助字段列表
const data = allList.value.filter(item => item.equipmentName === newVal)
modelList.value = Array.from(new Set(data.filter(item => item.model).map(item => item.model)))
helpList.value = Array.from(new Set(data.filter(item => item.helpInstruction).map(item => item.helpInstruction)))
})
// 监听规格型号下拉框,修改辅助字段
watch(() => listQuery.value.model, (newVal) => {
listQuery.value.helpInstruction = '' // 辅助字段清空
// 修改规格型号和辅助字段列表
helpList.value = Array.from(new Set(allList.value.filter(item => item.helpInstruction).filter(item => item.equipmentName === listQuery.value.deviceName && item.model === newVal).map(item => item.helpInstruction)))
})
watch(timeRange, (val) => {
if (val) {
listQuery.value.syncTimeStart = `${val[0]}`
listQuery.value.syncTimeEnd = `${val[1]}`
}
else {
listQuery.value.syncTimeStart = ''
listQuery.value.syncTimeEnd = ''
}
})
onMounted(async () => {
getDict().then(() => {
fetchData(false)
})
})
</script>
<template>
<div>
<!-- 布局 -->
<app-container>
<search-area :need-clear="true" @search="searchList" @clear="clearList">
<search-item>
<el-select v-model.trim="listQuery.deviceName" filterable class="short-input" placeholder="设备名称" clearable>
<el-option v-for="item in deviceNameList" :key="item" :label="item" :value="item" />
</el-select>
</search-item>
<search-item>
<el-select v-model.trim="listQuery.model" filterable class="short-input" placeholder="型号规格" clearable>
<el-option v-for="item in modelList" :key="item" :label="item" :value="item" />
</el-select>
</search-item>
<search-item>
<el-select v-model.trim="listQuery.helpInstruction" class="short-input" placeholder="辅助字段" clearable>
<el-option v-for="item in helpList" :key="item" :label="item" :value="item" />
</el-select>
</search-item>
<search-item>
<el-select
v-model="listQuery.deviceType"
placeholder="设备分类"
class="short-input"
filterable
clearable
>
<el-option v-for="item in deviceTypeList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
<search-item>
<el-select
v-model="listQuery.dataSync"
placeholder="检定点数据是否同步"
filterable
clearable
>
<el-option v-for="item in isSyncList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
<search-item>
<el-date-picker
v-model="timeRange"
type="datetimerange"
range-separator="至"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
start-placeholder="完成同步时间(开始)"
end-placeholder="完成同步时间(结束)"
/>
</search-item>
</search-area>
<table-container>
<template #btns-right>
<icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" />
<icon-button icon="icon-batchConfig" title="增加配置项" type="primary" @click="addConfig" />
</template>
<normal-table
:data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
>
<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>
</template>
<template #columns>
<el-table-column
label="操作"
align="center"
fixed="right"
:width="operateWidth"
>
<template #default="{ row }">
<el-button
v-if="row.id"
size="small"
type="primary"
link
@click="handleEdit(row, 'detail')"
>
详情
</el-button>
<el-button
size="small"
link
type="primary"
@click="handleEdit(row, 'config')"
>
配置检定项
</el-button>
</template>
</el-table-column>
</template>
</normal-table>
</table-container>
<confirm-config-dialog ref="confirmConfigRef" @confirm="confirmConfig" />
</app-container>
</div>
</template>