<!-- 智能模型台账管理列表页 -->
<script name="EquipmentInfoBookList" setup lang="ts">
import type { Ref } from 'vue'
import { getCurrentInstance, onMounted, ref, watch } from 'vue'
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import type { IList, IListQuery } from './book-interface'
import delReasonDialog from './dialog/delReasonDialog.vue'
import configWeekAndMonthDialog from './dialog/configWeekAndMonthDialog.vue'
import { approvalDelete, batchImport, cancelApproval, draftDelete, exportEquipmentExcel, getEquipmentList, getStream, refuseApproval, submit } from '@/api/equipment/info/book'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import type { deptType } from '@/global'
import buttonBox from '@/components/buttonBox/buttonBox.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getAllDeptList, getCompanyList, getDeptList, getDeptTreeList, getDeptTreeListByPid } from '@/api/system/dept'
import { getStaffList } from '@/api/resource/register'
import { toTreeList } from '@/utils/structure'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import useTemplateDownload from '@/utils/useTemplateDownload'
import useUserStore from '@/store/modules/user'
import scanEquipmentDialog from '@/components/scanEquipmentDialog/index.vue'
import { exportFile } from '@/utils/exportUtils'
const user = useUserStore()
const $router = useRouter()
const active = ref('')
const operateWidth = ref('150') // 操作栏的宽度
const buttonBoxActive = 'equipmentInfoBook' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const approvalDialog = ref() // 审批对话ref
const delRef = ref() // 删除弹窗组件ref
// 查询条件
const listQuery: Ref<IListQuery> = ref({
approvalStatus: active.value, // 审批状态类型code,导出接口不用传
groupCode: '', // 组别代码--后台定义用此字段筛选部门(刘翔)
directorId: '', // 负责人id
equipmentName: '', // 智能模型名称
equipmentNo: '', // 智能模型编号
formId: SCHEDULE.EQUIPMENT_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
labCode: '', // 实验室代码
labName: '', // 实验室名称
manufactureNo: '', // 出厂编号
measureValidDateStart: '', // 检定有效期开始
measureValidDateEnd: '', // 检定有效期结束
meterStandardName: '', // 所属标准库名称
model: '', // 规格型号
manufacturer: '', // 厂商
// partType: '', // 参照标准、工作标准和关键测量智能模型表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数
standardType: '', // 标准类型(字典code)
traceCompany: '', // 溯源单位
usageStatus: '', // 使用状态
offset: 1,
limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
// 表头
const columns = ref<TableColumn[]>([
// { text: '标签信息', value: 'label', align: 'center' },
{ text: '智能模型名称', value: 'equipmentName', align: 'center' },
{ text: '规格型号', value: 'model', align: 'center' },
{ text: '出厂编号', value: 'manufactureNo', align: 'center' },
{ text: '厂商', value: 'manufacturer', align: 'center' },
{ text: '实验室', value: 'labCodeName', align: 'center' },
{ text: '部门', value: 'groupCodeName', align: 'center' },
{ text: '智能模型单价(万元)', value: 'unitPrice', align: 'center' },
{ text: '负责人', value: 'directorName', align: 'center', width: '120' },
{ text: '使用状态', value: 'usageStatusName', align: 'center', width: '90' },
{ text: '溯源单位', value: 'traceCompany', align: 'center' },
{ text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' },
{ text: '所属标准库', value: 'meterStandardName', align: 'center', width: '120' },
])
const list = ref<IList[]>([]) // 表格数据
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const checkoutList = ref<string[]>([])// 选中的内容
// -----------------------------------------字典--------------------------------------------------------------
const useDeptList = ref<deptType[]>([]) // 所属部门列表
const labDeptList = ref<deptType[]>([]) // 实验室
const usageStatusList = ref<deptType[]>([]) // 使用状态
const userList = ref<{ [key: string]: string }[]>([]) // 用户列表
// 查询字典
const getDict = async () => {
loadingTable.value = true
// 审批状态
const res = await getDictByCode('approvalStatus')
// 制作右上角的菜单
const tempMenu = ['全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消']
tempMenu.forEach((item) => {
const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item)
if (tempFindData) {
menu.value.push({
name: tempFindData.name,
id: `${tempFindData.value}`,
})
}
})
// 获取用户列表
getStaffList({ offset: 1, limit: 999999 }).then((res: any) => {
userList.value = res.data.rows
})
// 实验室
getDictByCode('bizGroupCodeEquipment').then((response) => {
labDeptList.value = response.data
})
// 部门
getDictByCode('bizGroupCode').then((response) => {
useDeptList.value = response.data
})
// 使用状态
getDictByCode('bizUsageStatus').then((response) => {
usageStatusList.value = response.data
})
}
// -------------------------------------------------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
listQuery.value.offset = 1
}
console.log(active.value)
if (listQuery.value.approvalStatus === '10') { listQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''
// 检定部门(全部)只能查看本部门的智能模型
// getEquipmentList({ ...listQuery.value, deptId: active.value === '0' && user.deptType === '3' ? user.deptId : '' }).then((response) => {
getEquipmentList({ ...listQuery.value }).then((response) => {
list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; measureValidDate: string }) => {
return {
...item,
measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate,
}
})
total.value = parseInt(response.data.total)
loadingTable.value = false
}).catch(() => {
loadingTable.value = false
})
}
// 搜索
const searchList = () => {
fetchData(true)
}
// 重置
const clearList = () => {
listQuery.value = {
approvalStatus: active.value, // 审批状态类型code,导出接口不用传
groupCode: '', // 组别代码、部门
directorId: '', // 负责人id
equipmentName: '', // 智能模型名称
equipmentNo: '', // 智能模型编号
formId: SCHEDULE.EQUIPMENT_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
labCode: '', // 实验室代码
labName: '', // 实验室名称
manufactureNo: '', // 出厂编号
measureValidDateStart: '', // 检定有效期开始
measureValidDateEnd: '', // 检定有效期结束
meterStandardName: '', // 所属标准库名称
model: '', // 规格型号
manufacturer: '', // 厂商
// partType: '', // 参照标准、工作标准和关键测量智能模型表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数
standardType: '', // 标准类型(字典code)
traceCompany: '', // 溯源单位
usageStatus: '', // 使用状态
offset: 1,
limit: 20,
}
dateRange.value = ['', '']
fetchData(true)
}
// 多选发生改变时
function handleSelectionChange(e: any) {
checkoutList.value = e.map((item: { id: string }) => item.id)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
// 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)
// }
// 改变页容量
function handleSizeChange(val: number) {
listQuery.value.limit = val
fetchData()
}
// 改变当前页
function handleCurrentChange(val: number) {
listQuery.value.offset = val
fetchData(true)
}
// ---------------------------------------审批按钮---------------------------------------------------------------------
// 切换tab状态
const changeCurrentButton = (val: string) => {
active.value = val // 此时的tab
window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态
clearList() // 刷新
}
// 审批结束回调
const approvalSuccess = () => {
fetchData(true)
}
// -------------------------------------表格上方工具栏-----------------------------------
const fileRef = ref() // 文件上传input
const onFileChange = (event: any) => {
// 原生上传
if (event.target.files?.length !== 0) {
// 创建formdata对象
const fd = new FormData()
fd.append('file', event.target.files[0])
const loading = ElLoading.service({
lock: true,
background: 'rgba(255, 255, 255, 0.8)',
})
// 调批量导入接口
batchImport(fd).then((res) => {
ElMessage.success('上传成功')
event.target.value = null
loading.close()
fetchData(true)
loading.close()
}).catch(() => {
event.target.value = null
loading.close()
})
}
}
// 批量导入
const handleBatchImport = () => {
fileRef.value.click()
}
// 导出word
const exportWord = () => {
// if (!checkoutList.value.length) {
// ElMessage.warning('请先选中数据')
// return false
// }
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
getStream({
// ...listQuery.value,
ids: checkoutList.value,
pdf: false,
approvalStatus: listQuery.value.approvalStatus, // 审批状态类型code,导出接口不用传
groupCode: listQuery.value.groupCode, // 组别代码--后台定义用此字段筛选部门(刘翔)
directorId: listQuery.value.directorId, // 负责人id
equipmentName: listQuery.value.equipmentName, // 智能模型名称
equipmentNo: listQuery.value.equipmentNo, // 智能模型编号
formId: listQuery.value.formId, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
labCode: listQuery.value.labCode, // 实验室代码
labName: listQuery.value.labName, // 实验室名称
manufactureNo: listQuery.value.manufactureNo, // 出厂编号
measureValidDateStart: listQuery.value.measureValidDateStart, // 检定有效期开始
measureValidDateEnd: listQuery.value.measureValidDateEnd, // 检定有效期结束
meterStandardName: listQuery.value.meterStandardName, // 所属标准库名称
model: listQuery.value.model, // 规格型号
manufacturer: listQuery.value.manufacturer, // 厂商
// partType: listQuery.value., // 参照标准、工作标准和关键测量智能模型表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数
standardType: listQuery.value.standardType, // 标准类型(字典code)
traceCompany: listQuery.value.traceCompany, // 溯源单位
usageStatus: listQuery.value.usageStatus, // 使用状态
}).then((res) => {
exportFile(res.data, '智能模型台账管理.doc')
loading.close()
})
}
// 导出excel
const exportExcel = () => {
// 导出
const loading = ElLoading.service({
lock: true,
text: '下载中请稍后',
background: 'rgba(255, 255, 255, 0.8)',
})
if (list.value.length > 0) {
const params = {
approvalStatus: listQuery.value.approvalStatus, // 审批状态类型code,导出接口不用传
groupCode: listQuery.value.groupCode, // 组别代码--后台定义用此字段筛选部门(刘翔)
directorId: listQuery.value.directorId, // 负责人id
equipmentName: listQuery.value.equipmentName, // 智能模型名称
equipmentNo: listQuery.value.equipmentNo, // 智能模型编号
formId: listQuery.value.formId, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
labCode: listQuery.value.labCode, // 实验室代码
labName: listQuery.value.labName, // 实验室名称
manufactureNo: listQuery.value.manufactureNo, // 出厂编号
measureValidDateStart: listQuery.value.measureValidDateStart, // 检定有效期开始
measureValidDateEnd: listQuery.value.measureValidDateEnd, // 检定有效期结束
meterStandardName: listQuery.value.meterStandardName, // 所属标准库名称
model: listQuery.value.model, // 规格型号
manufacturer: listQuery.value.manufacturer, // 厂商
// partType: listQuery.value., // 参照标准、工作标准和关键测量智能模型表功能该参数传1(同时approvalStatus参数传0),其余情况不用传该参数
standardType: listQuery.value.standardType, // 标准类型(字典code)
traceCompany: listQuery.value.traceCompany, // 溯源单位
usageStatus: listQuery.value.usageStatus, // 使用状态
offset: 1,
limit: 20,
ids: checkoutList.value,
}
exportEquipmentExcel(params).then((res) => {
const blob = new Blob([res.data])
loading.close()
exportFile(blob, '智能模型台账.xlsx')
})
loading.close()
}
else {
loading.close()
ElMessage.warning('无数据可导出数据')
}
}
// 新建
const add = () => {
$router.push({ path: '/equipmentInfo/add' })
}
// ----------------------------------------------扫描----------------------------------------------------
const scanEquipmentRef = ref()
// 点击扫描查看绑定标签的智能模型
const scan = () => {
// 参数:是标签绑定
scanEquipmentRef.value.initDialog(false)
}
// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
if (type === 'edit' || type === 'detail') { // 编辑、详情
$router.push({
path: `/equipmentInfo/${type}/${row.id}`,
query: {
approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
equipmentNo: row.equipmentNo, // 智能模型编号
processId: row.processId, // 流程实例id
taskId: row.taskId, // 任务id
},
})
}
else if (type === '同意') {
approvalDialog.value.initDialog('agree', row.taskId)
}
else if (type === '拒绝') {
approvalDialog.value.initDialog('refuse', row.taskId, row.id)
}
else if (type === '取消') {
const params = {
processInstanceId: row.processId!,
comments: '',
id: row.id,
}
ElMessageBox.confirm(
'确认取消该审批吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
)
.then(() => {
cancelApproval(params).then((res) => {
ElMessage({
type: 'success',
message: '已取消',
})
fetchData(true)
})
})
}
else {
ElMessageBox.confirm(
`确认${type}吗?`,
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
).then(() => {
if (type === '删除' && row.approvalStatusName === '草稿箱') {
draftDelete({ id: row.id }).then(() => {
ElMessage.success(`已${type}`)
fetchData()
})
}
else if (type === '删除' && row.approvalStatusName === '已取消') {
approvalDelete({ id: row.id, taskId: row.taskId }).then(() => {
ElMessage.success(`已${type}`)
fetchData()
})
}
else if (type === '删除' && active.value === '0') { // 全部的删除
delRef.value.initDialog(row)
}
})
}
}
// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
const params = {
id,
taskId, // 任务id
comments, // 拒绝原因
}
refuseApproval(params).then((res) => {
ElMessage({
type: 'success',
message: '已拒绝',
})
fetchData(true)
})
}
// ----------------------------------------------配置周维护月保养------------------------------------------------------
const configWeekAndMonthDialogRef = ref()
// 点击配置周维护、月保养
const config = () => {
if (!checkoutList.value.length) {
ElMessage.warning('请至少选择一个智能模型!')
return
}
configWeekAndMonthDialogRef.value.initDialog(checkoutList.value)
}
// ----------------------------------------------钩子------------------------------------------------------
watch(dateRange, (val) => {
if (val) {
listQuery.value.measureValidDateStart = `${val[0]}`
listQuery.value.measureValidDateEnd = `${val[1]}`
}
else {
listQuery.value.measureValidDateStart = ''
listQuery.value.measureValidDateEnd = ''
}
})
// 只有审批给看审批状态
watch(() => active.value, (val) => {
if (val === '10') { // 审批把审批状态加上
if (columns.value[columns.value.length - 1].value !== 'approvalStatusName') {
columns.value.push({ text: '审批状态', value: 'approvalStatusName', align: 'center' })
}
}
else { // 其他不显示审批状态
if (columns.value[columns.value.length - 1].value === 'approvalStatusName') {
columns.value.pop()
}
}
}, { immediate: true })
onMounted(async () => {
await getDict()
if (window.sessionStorage.getItem(buttonBoxActive)) {
active.value = window.sessionStorage.getItem(buttonBoxActive)!
}
else {
active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部
}
})
function TableCellStyle(value: any) {
if (value.row.colorMark === 1) {
return 'background-color:#e43c2f !important;color: #000 !important;font-weight: 600 !important;'
}
else if (value.row.colorMark === 2) {
return 'background-color:#f9be15; !important;color: #000 !important;'
}
}
</script>
<template>
<div class="equipment-info-book">
<app-container>
<search-area :need-clear="true" @search="searchList" @clear="clearList">
<search-item>
<el-input v-model.trim="listQuery.equipmentName" placeholder="智能模型名称" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.model" placeholder="规格型号" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" class="short-input" clearable />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.manufacturer" placeholder="厂商" class="short-input" clearable />
</search-item>
<search-item>
<el-select
v-model="listQuery.usageStatus"
placeholder="使用状态"
class="short-input"
filterable
clearable
>
<el-option v-for="item in usageStatusList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
<search-item>
<el-select
v-model="listQuery.labCode"
placeholder="实验室"
class="short-input"
filterable
clearable
>
<el-option v-for="item in labDeptList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
<search-item>
<el-select
v-model="listQuery.groupCode"
placeholder="部门"
class="short-input"
filterable
clearable
>
<el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</search-item>
<search-item>
<el-select
v-model="listQuery.directorId"
placeholder="负责人"
class="short-input"
filterable
clearable
>
<el-option v-for="item in userList" :key="item.id" :label="item.staffName" :value="item.id" />
</el-select>
</search-item>
<search-item>
<el-input v-model.trim="listQuery.traceCompany" placeholder="溯源单位" class="short-input" clearable />
</search-item>
<search-item>
<el-date-picker
v-model="dateRange"
class="short-input"
type="daterange"
range-separator="至"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
start-placeholder="检定有效期(开始)"
end-placeholder="检定有效期(结束)"
/>
</search-item>
<search-item>
<el-input v-model.trim="listQuery.meterStandardName" placeholder="所属标准库" class="short-input" clearable />
</search-item>
</search-area>
<table-container>
<template #btns-right>
<icon-button v-if="active === '0'" icon="icon-word" title="导出word" type="primary" @click="exportWord" />
<icon-button v-if="active === '0'" icon="icon-excel" title="导出excel" type="primary" @click="exportExcel" />
<icon-button v-if="active === '0'" icon="icon-rfid" title="扫描" type="primary" @click="scan" />
<icon-button v-if="active === '0'" icon="icon-add" title="新建" type="primary" @click="add" />
<!-- <icon-button v-if="proxy.hasPerm('/equipment/info/book/import')" icon="icon-import" title="批量导入" type="primary" @click="uploadAll" /> -->
<icon-button v-if="active === '0'" icon="icon-import" title="批量导入" type="primary" @click="handleBatchImport" />
<icon-button v-if="active === '0'" icon="icon-template" title="模板下载" type="primary" @click="useTemplateDownload('智能模型台账管理')" />
<icon-button v-if="active === '0'" icon="icon-config" title="周维护/月保养配置" type="primary" @click="config" />
</template>
<input v-show="false" id="fileInput" ref="fileRef" type="file" accept="*" @change="onFileChange">
<el-table
v-loading="loadingTable"
:data="list"
border
style="width: 100%;"
:row-style="TableCellStyle as any"
:row-key="(row: any) => { return row.id || row.index }"
@selection-change="handleSelectionChange"
>
<el-table-column :reserve-selection="true" type="selection" width="38" fixed="left" />
<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-for="item in columns"
:key="item.value"
:prop="item.value"
:label="item.text"
:width="item.width"
:show-overflow-tooltip="true"
align="center"
/>
<el-table-column
fixed="right"
label="操作"
width="120"
align="center"
>
<template #default="{ row }">
<el-button
v-if="active !== '1' && active !== '6' && active !== '5'"
size="small"
type="primary"
link
@click="handleEdit(row, 'detail')"
>
查看
</el-button>
<el-button
v-if=" active === '1' || active === '6' || active === '5'"
size="small"
type="primary"
link
@click="handleEdit(row, 'edit')"
>
查看
</el-button>
<el-button
v-if="row.approvalStatusName === '待审批'"
size="small"
link
type="primary"
@click="handleEdit(row, '同意')"
>
同意
</el-button>
<el-button
v-if="row.approvalStatusName === '待审批'"
size="small"
link
type="danger"
@click="handleEdit(row, '拒绝')"
>
拒绝
</el-button>
<el-button
v-if="active === '0' && user.groupNo === row.groupCode && user.bizLabCode === row.labCode"
size="small"
link
type="primary"
@click="handleEdit(row, 'edit')"
>
编辑
</el-button>
<!-- 是发起者且审批中可以取消 -->
<el-button
v-if="row.approvalStatusName === '审批中' && active !== '7' && active !== '0'"
size="small"
link
type="info"
@click="handleEdit(row, '取消')"
>
取消
</el-button>
<el-button
v-if="active !== '7' && (active === '0' || row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消')"
size="small"
link
type="danger"
@click="handleEdit(row, '删除')"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 页码 -->
<el-pagination
style="width: 100%;margin-top: 10px;"
:current-page="listQuery.offset"
:page-sizes="[5, 10, 20, 30, 50, 100, 150, 200]"
:page-size="listQuery.limit"
:total="total"
layout="total, sizes, prev, pager, next"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</table-container>
<!-- 审批弹窗 -->
<approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" />
<!-- 右上角按钮集合 -->
<button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" />
<!-- 删除弹窗 -->
<del-reason-dialog ref="delRef" @on-success="fetchData(true)" />
<!-- 扫描 -->
<scan-equipment-dialog ref="scanEquipmentRef" title="扫描查询智能模型" />
<!-- 配置周维护月保养 -->
<config-week-and-month-dialog ref="configWeekAndMonthDialogRef" />
</app-container>
</div>
</template>