UPDATE:1.完善主计划导入被检设备逻辑;2.完善新增编辑子计划逻辑。

This commit is contained in:
贾同学
2025-08-13 20:34:08 +08:00
parent 0025895696
commit b1ddf540ca
5 changed files with 781 additions and 660 deletions

View File

@@ -2,7 +2,6 @@ import type { Plan } from './interface'
import http from '@/api' import http from '@/api'
import type { ErrorSystem } from '../device/interface/error' import type { ErrorSystem } from '../device/interface/error'
import type { Device } from '../device/interface/device' import type { Device } from '../device/interface/device'
import { pa } from 'element-plus/es/locale/index.mjs'
/** /**
* @name 检测计划管理模块 * @name 检测计划管理模块
@@ -23,7 +22,7 @@ export const updatePlan = (params: any) => {
} }
// 删除检测计划 // 删除检测计划
export const deletePlan = (params: { id: string[] ,pattern: string}) => { export const deletePlan = (params: { id: string[]; pattern: string }) => {
return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id) return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id)
} }
@@ -91,31 +90,36 @@ export const staticsAnalyse = (params: { id: string[] }) => {
} }
//根据计划id分页查询被检设 //根据计划id分页查询被检设
export const getDevListByPlanId = (params:any) => { export const getDevListByPlanId = (params: any) => {
return http.post(`/adPlan/listDevByPlanId`, params) return http.post(`/adPlan/listDevByPlanId`, params)
} }
//修改子计划名称 //修改子计划名称
export const updateSubPlanName = (params:Plan.ReqPlan) => { export const updateSubPlanName = (params: Plan.ReqPlan) => {
return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`) return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`)
} }
//子计划绑定/解绑标准设备 //子计划绑定/解绑标准设备
export const subPlanBindStandardDevList = (params:Plan.ReqPlan) => { export const subPlanBindStandardDevList = (params: Plan.ReqPlan) => {
return http.post(`/adPlan/updateBindStandardDev`, params) return http.post(`/adPlan/updateBindStandardDev`, params)
} }
//子计划绑定/解绑被检设备 //子计划绑定/解绑被检设备
export const subPlanBindDev = (params:Plan.ReqPlan) => { export const subPlanBindDev = (params: Plan.ReqPlan) => {
return http.post(`/adPlan/updateBindDev`, params) return http.post(`/adPlan/updateBindDev`, params)
} }
//根据父计划ID获取未被子计划绑定的标准设备 //根据父计划ID获取未被子计划绑定的标准设备
export const getUnboundStandardDevList = (params:Plan.ResPlan) => { export const getUnboundStandardDevList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`) return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`)
} }
//根据计划ID获取已绑定的标准设备 //根据计划ID获取已绑定的标准设备
export const getBoundStandardDevList = (params:Plan.ResPlan) => { export const getBoundStandardDevList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`) return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`)
} }
//根据计划ID获取已绑定的所有标准设备
export const getBoundStandardDevAllList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}&all=1`)
}

View File

@@ -1,59 +1,69 @@
<template> <template>
<el-dialog v-model='dialogVisible' :title='`批量添加${parameter.title}`' :destroy-on-close='true' width='580px' <el-dialog
draggable> v-model="dialogVisible"
<el-form class='drawer-multiColumn-form' label-width='100px'> :title="`批量添加${parameter.title}`"
<el-form-item label='模板下载 :'> :destroy-on-close="true"
<el-button type='primary' :icon='Download' @click='downloadTemp'> 点击下载</el-button> width="580px"
draggable
>
<el-form class="drawer-multiColumn-form" label-width="100px">
<el-form-item label="模板下载 :">
<el-button type="primary" :icon="Download" @click="downloadTemp">点击下载</el-button>
</el-form-item> </el-form-item>
<el-form-item label='文件上传 :'> <el-form-item label="文件上传 :">
<el-upload <el-upload
action='#' action="#"
class='upload' class="upload"
:drag='true' :drag="true"
:limit='excelLimit' :limit="excelLimit"
:multiple='true' :multiple="true"
:show-file-list='true' :show-file-list="true"
:http-request='uploadExcel' :http-request="uploadExcel"
:before-upload='beforeExcelUpload' :before-upload="beforeExcelUpload"
:on-exceed='handleExceed' :on-exceed="handleExceed"
:accept="parameter.fileType!.join(',')" :accept="parameter.fileType!.join(',')"
> >
<slot name='empty'> <slot name="empty">
<el-icon class='el-icon--upload'> <el-icon class="el-icon--upload">
<upload-filled /> <upload-filled />
</el-icon> </el-icon>
<div class='el-upload__text'>将文件拖到此处<em>点击上传</em></div> <div class="el-upload__text">
将文件拖到此处
<em>点击上传</em>
</div>
</slot> </slot>
<template #tip> <template #tip>
<slot name='tip'> <slot name="tip">
<div class='el-upload__tip'>请上传 .xls , .xlsx 标准格式文件文件最大为 {{ parameter.fileSize }}M</div> <div class="el-upload__tip">
请上传 .xls , .xlsx 标准格式文件文件最大为 {{ parameter.fileSize }}M
</div>
</slot> </slot>
</template> </template>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item v-if='parameter.showCover' label='数据覆盖 :'> <el-form-item v-if="parameter.showCover" label="数据覆盖 :">
<el-switch v-model='isCover' /> <el-switch v-model="isCover" />
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang='ts' name='ImportExcel'> <script setup lang="ts" name="ImportExcel">
import { ref } from 'vue' import { ref } from 'vue'
import { useDownload } from '@/hooks/useDownload' import { useDownload } from '@/hooks/useDownload'
import { Download } from '@element-plus/icons-vue' import { Download } from '@element-plus/icons-vue'
import { ElNotification, UploadRequestOptions, UploadRawFile, ElMessage } from 'element-plus' import { ElMessage, ElNotification, UploadRawFile, UploadRequestOptions } from 'element-plus'
export interface ExcelParameterProps { export interface ExcelParameterProps {
title: string; // 标题 title: string // 标题
showCover?: boolean; // 是否显示”数据覆盖“选项 showCover?: boolean // 是否显示”数据覆盖“选项
patternId?: string; // 模式ID patternId?: string // 模式ID
planId?: string | null ;//计划ID planId?: string | null //计划ID
fileSize?: number; // 上传文件的大小 fileSize?: number // 上传文件的大小
fileType?: File.ExcelMimeType[]; // 上传文件的类型 fileType?: File.ExcelMimeType[] // 上传文件的类型
tempApi?: (params: any) => Promise<any>; // 下载模板的Api tempApi?: (params: any) => Promise<any> // 下载模板的Api
importApi?: (params: any) => Promise<any>; // 批量导入的Api importApi?: (params: any) => Promise<any> // 批量导入的Api
getTableList?: () => void; // 获取表格数据的Api getTableList?: () => void // 获取表格数据的Api
} }
// 是否覆盖数据 // 是否覆盖数据
@@ -66,9 +76,11 @@ const dialogVisible = ref(false)
const parameter = ref<ExcelParameterProps>({ const parameter = ref<ExcelParameterProps>({
title: '', title: '',
fileSize: 5, fileSize: 5,
fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
}) })
const emit = defineEmits<{
(e: 'result', data: boolean): void
}>()
// 接收父组件参数 // 接收父组件参数
const acceptParams = (params: ExcelParameterProps) => { const acceptParams = (params: ExcelParameterProps) => {
parameter.value = { ...parameter.value, ...params } parameter.value = { ...parameter.value, ...params }
@@ -78,7 +90,7 @@ const acceptParams = (params: ExcelParameterProps) => {
// Excel 导入模板下载 // Excel 导入模板下载
const downloadTemp = () => { const downloadTemp = () => {
if (!parameter.value.tempApi) return if (!parameter.value.tempApi) return
useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, {'pattern':parameter.value.patternId}, false) useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, { pattern: parameter.value.patternId }, false)
} }
// 文件上传 // 文件上传
@@ -93,13 +105,11 @@ const uploadExcel = async (param: UploadRequestOptions) => {
isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob) isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob)
//await parameter.value.importApi!(excelFormData); //await parameter.value.importApi!(excelFormData);
await parameter.value.importApi!(excelFormData) await parameter.value.importApi!(excelFormData).then(res => handleImportResponse(res))
.then(res => handleImportResponse(res))
parameter.value.getTableList && parameter.value.getTableList() parameter.value.getTableList && parameter.value.getTableList()
dialogVisible.value = false dialogVisible.value = false
} }
async function handleImportResponse(res: any) { async function handleImportResponse(res: any) {
console.log(res) console.log(res)
@@ -113,12 +123,14 @@ async function handleImportResponse(res: any) {
} else { } else {
ElMessage.error(jsonData.message) ElMessage.error(jsonData.message)
} }
emit('result', jsonData.data)
} catch (err) { } catch (err) {
console.log(err) console.log(err)
} }
} }
fileReader.readAsText(res) fileReader.readAsText(res)
} else { } else {
emit('result', false)
ElMessage.error('导入失败,请查看下载附件!') ElMessage.error('导入失败,请查看下载附件!')
let blob = new Blob([res], { type: 'application/vnd.ms-excel' }) let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
const url = window.URL.createObjectURL(blob) const url = window.URL.createObjectURL(blob)
@@ -142,14 +154,14 @@ const beforeExcelUpload = (file: UploadRawFile) => {
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: '上传文件只能是 xls / xlsx 格式!', message: '上传文件只能是 xls / xlsx 格式!',
type: 'warning', type: 'warning'
}) })
if (!fileSize) if (!fileSize)
setTimeout(() => { setTimeout(() => {
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: `上传文件大小不能超过 ${parameter.value.fileSize}MB`, message: `上传文件大小不能超过 ${parameter.value.fileSize}MB`,
type: 'warning', type: 'warning'
}) })
}, 0) }, 0)
return isExcel && fileSize return isExcel && fileSize
@@ -160,7 +172,7 @@ const handleExceed = () => {
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: '最多只能上传一个文件!', message: '最多只能上传一个文件!',
type: 'warning', type: 'warning'
}) })
} }
@@ -183,9 +195,9 @@ const handleExceed = () => {
// } // }
defineExpose({ defineExpose({
acceptParams, acceptParams
}) })
</script> </script>
<style lang='scss' scoped> <style lang="scss" scoped>
@import "./index.scss"; @use './index.scss';
</style> </style>

View File

@@ -14,27 +14,16 @@
class="table-box" class="table-box"
:style="{ height: height - 64 + 'px', maxHeight: height - 64 + 'px', overflow: 'hidden' }" :style="{ height: height - 64 + 'px', maxHeight: height - 64 + 'px', overflow: 'hidden' }"
> >
<el-tabs <el-tabs v-model="editableTabsValue" type="card" @tab-remove="removeTab" @tab-click="handleTabClick">
v-model="editableTabsValue"
type="card"
@tab-remove="removeTab"
@tab-click="handleTabClick"
>
<el-tab-pane <el-tab-pane
v-for="item in editableTabs" v-for="item in editableTabs"
:key="item.name" :key="item.name"
:label="item.title" :label="item.title"
:name="item.name" :name="item.name"
:closable="item.closable" :closable="item.closable"
> ></el-tab-pane>
</el-tab-pane>
</el-tabs> </el-tabs>
<ProTable <ProTable ref="proTable" :columns="columns" :request-api="getTableList" type="selection">
ref="proTable"
:columns="columns"
:request-api="getTableList"
type="selection"
>
<!-- 表格 header 按钮 --> <!-- 表格 header 按钮 -->
<template #tableHeader="scope"> <template #tableHeader="scope">
<el-button type="primary" :icon="CirclePlus" @click="addTab('add')" v-if="!isTabPlanFather"> <el-button type="primary" :icon="CirclePlus" @click="addTab('add')" v-if="!isTabPlanFather">
@@ -49,30 +38,57 @@
<el-button type="primary" :icon="Download" > <el-button type="primary" :icon="Download" >
导入检测结果 导入检测结果
</el-button> --> </el-button> -->
<el-button type="danger" :icon="Delete" plain :disabled="!scope.isSelected" v-if="isTabPlanFather" @click="subBatchRemove(scope.selectedListIds)"> <el-button
type="danger"
:icon="Delete"
plain
:disabled="!scope.isSelected"
v-if="isTabPlanFather"
@click="subBatchRemove(scope.selectedListIds)"
>
批量移除 批量移除
</el-button> </el-button>
<el-dropdown trigger="hover" placement="right-start" :disabled="!scope.isSelected"> <el-dropdown
<el-button type="primary" :icon="ScaleToOriginal" style="margin-left: 10px;" v-if="!isTabPlanFather" :disabled="!scope.isSelected"> v-if="planFormContent && planFormContent?.children.length > 0"
trigger="hover"
placement="right-start"
:disabled="!scope.isSelected"
>
<el-button
type="primary"
:icon="ScaleToOriginal"
style="margin-left: 10px"
v-if="!isTabPlanFather"
:disabled="!scope.isSelected"
>
分配被检设备 分配被检设备
</el-button> </el-button>
<template #dropdown > <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item <el-dropdown-item
v-for="child in planFormContent?.children" v-for="child in planFormContent?.children"
:key="child.id" :key="child.id"
@click="distribute(child,scope)" @click="distribute(child, scope)"
> >
{{ child.name }} {{ child.name }}
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
</el-dropdown> </el-dropdown>
<el-dropdown trigger="hover" placement="right-start"> <el-dropdown
<el-button type="primary" :icon="ScaleToOriginal" style="margin-left: 10px;" v-if="!isTabPlanFather"> v-if="planFormContent && planFormContent?.children.length > 0"
trigger="hover"
placement="right-start"
>
<el-button
type="primary"
:icon="ScaleToOriginal"
style="margin-left: 10px"
v-if="!isTabPlanFather"
>
标准设备管理 标准设备管理
</el-button> </el-button>
<template #dropdown > <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item <el-dropdown-item
v-for="child in planFormContent?.children" v-for="child in planFormContent?.children"
@@ -87,36 +103,52 @@
</template> </template>
<!-- 表格操作 --> <!-- 表格操作 -->
<template #operation="scope"> <template #operation="scope">
<el-button type="primary" link :icon="Delete" v-if="!isTabPlanFather" :disabled="scope.row.checkState != 0" @click="handleRemove(scope.row)">删除</el-button> <el-button
<el-button type="primary" link :icon="Delete" v-if="isTabPlanFather" @click="subHandleRemove(scope.row)">移除</el-button> type="primary"
link
:icon="Delete"
v-if="!isTabPlanFather"
:disabled="scope.row.checkState != 0"
@click="handleRemove(scope.row)"
>
删除
</el-button>
<el-button
type="primary"
link
:icon="Delete"
v-if="isTabPlanFather"
@click="subHandleRemove(scope.row)"
>
移除
</el-button>
</template> </template>
</ProTable> </ProTable>
</div> </div>
</el-dialog> </el-dialog>
<!-- 向计划导入/导出设备对话框 --> <!-- 向计划导入/导出设备对话框 -->
<PlanPopup :refresh-table='proTable?.getTableList' ref='planPopup' @update:tab="addNewChildTab"/> <PlanPopup :refresh-table="proTable?.getTableList" ref="planPopup" @update:tab="addNewChildTab" />
<DevTransfer ref='devTransfer' @update:table="addNewChildTab"/> <DevTransfer ref="devTransfer" @update:table="addNewChildTab" />
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
import { ElMessage, ElMessageBox, TabPaneName } from 'element-plus' import { ElMessage, ElMessageBox, TabPaneName } from 'element-plus'
import { ref, computed, watch, reactive } from 'vue' import { computed, reactive, ref } from 'vue'
import { ScaleToOriginal, CirclePlus, Delete, Upload, Download } from '@element-plus/icons-vue' import { CirclePlus, Delete, ScaleToOriginal } from '@element-plus/icons-vue'
import PlanPopup from '@/views/plan/planList/components/planPopup.vue' // 导入子组件 import PlanPopup from '@/views/plan/planList/components/planPopup.vue' // 导入子组件
import { Plan } from '@/api/plan/interface' import { Plan } from '@/api/plan/interface'
import {useModeStore } from '@/stores/modules/mode'; // 引入模式 store import { useModeStore } from '@/stores/modules/mode' // 引入模式 store
import { ColumnProps, ProTableInstance, SearchRenderScope } from '@/components/ProTable/interface' import { ColumnProps, ProTableInstance, SearchRenderScope } from '@/components/ProTable/interface'
import {getDevListByPlanId ,subPlanBindDev,deletePlan} from '@/api/plan/plan' import { deletePlan, getDevListByPlanId, subPlanBindDev } from '@/api/plan/plan'
import { Device } from '@/api/device/interface/device' import { Device } from '@/api/device/interface/device'
import { useDictStore } from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import DevTransfer from '@/views/plan/planList/components/devTransfer.vue' import DevTransfer from '@/views/plan/planList/components/devTransfer.vue'
import { useHandleData } from '@/hooks/useHandleData' import { useHandleData } from '@/hooks/useHandleData'
import router from '@/routers' import router from '@/routers'
const dictStore = useDictStore() const dictStore = useDictStore()
const planFormContent = ref<Plan.ReqPlan>() const planFormContent = ref<Plan.ReqPlan>()
const proTable = ref<ProTableInstance>() const proTable = ref<ProTableInstance>()
const modeStore = useModeStore(); const modeStore = useModeStore()
const planPopup = ref() const planPopup = ref()
const devTransfer = ref() const devTransfer = ref()
@@ -133,135 +165,131 @@ const patternId = ref('')
const getTableList = async (params: any) => { const getTableList = async (params: any) => {
if (!planFormContent.value) { if (!planFormContent.value) {
return Promise.resolve({ data: [], total: 0 }); return Promise.resolve({ data: [], total: 0 })
} }
let newParams = JSON.parse(JSON.stringify(params)); let newParams = JSON.parse(JSON.stringify(params))
newParams.pattern = patternId.value newParams.pattern = patternId.value
if(!isTabPlanFather.value) if (!isTabPlanFather.value) newParams.planId = planFormContent.value.id
newParams.planId = planFormContent.value.id else newParams.planId = planId.value
else newParams.planIdList = [newParams.planId]
newParams.planId = planId.value
newParams.planIdList = [newParams.planId];
proTable.value?.clearSelection() proTable.value?.clearSelection()
planTabDevList.value = await getDevListByPlanId(newParams); planTabDevList.value = await getDevListByPlanId(newParams)
return planTabDevList.value; return planTabDevList.value
} }
const columns = reactive<ColumnProps<Device.ResPqDev>[]>([ const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
{ type: 'selection', fixed: 'left', width: 70,selectable: (row) => row.checkState == 0 }, { type: 'selection', fixed: 'left', width: 70, selectable: row => row.checkState == 0 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' }, { type: 'index', fixed: 'left', width: 70, label: '序号' },
{ {
prop: 'name', prop: 'name',
label: '名称', label: '名称',
search: { el: 'input' }, search: { el: 'input' },
minWidth: 180, minWidth: 180
}, },
{ {
prop: 'devType', prop: 'devType',
label: '设备类型', label: '设备类型',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'createDate', prop: 'createDate',
label: '出厂日期', label: '出厂日期',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'devChns', prop: 'devChns',
label: '通道数', label: '通道数',
minWidth: 100, minWidth: 100
}, },
{ {
prop: 'devVolt', prop: 'devVolt',
label: '额定电压V', label: '额定电压V',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'devCurr', prop: 'devCurr',
label: '额定电流A', label: '额定电流A',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'manufacturer', prop: 'manufacturer',
label: '设备厂家', label: '设备厂家',
enum: dictStore.getDictData('Dev_Manufacturers'), enum: dictStore.getDictData('Dev_Manufacturers'),
search: {el: 'select', props: {filterable: true}, order: 1}, search: { el: 'select', props: { filterable: true }, order: 1 },
fieldNames: {label: 'name', value: 'id'}, fieldNames: { label: 'name', value: 'id' },
minWidth: 200, minWidth: 200
}, },
{ {
prop: 'cityName', prop: 'cityName',
label: '地市', label: '地市',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'region', prop: 'region',
label: '地市', label: '地市',
minWidth: 150, minWidth: 150,
isShow:false, isShow: false,
search: { search: {
el: 'input', el: 'input',
label :'关键词', label: '关键词',
render: (scope: SearchRenderScope) => { render: (scope: SearchRenderScope) => {
return ( return <el-input v-model={scope.searchParam.region} placeholder="请输入关键词" clearable />
<el-input
v-model={scope.searchParam.region}
placeholder="请输入关键词"
clearable
/>
);
} }
} }
}, },
{ {
prop: 'gdName', prop: 'gdName',
label: '供电公司', label: '供电公司',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'subName', prop: 'subName',
label: '变电站', label: '变电站',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'boundPlanName', prop: 'boundPlanName',
label: '子计划', label: '子计划',
minWidth: 150, minWidth: 150,
render: (scope) => { render: scope => {
console.log('boundPlanName', isTabPlanFather.value) console.log('boundPlanName', isTabPlanFather.value)
const value = scope.row.boundPlanName; const value = scope.row.boundPlanName
if (!value) { if (!value) {
return '/'; // 空值直接返回空字符串 return '/' // 空值直接返回空字符串
} }
return ( return (
<el-link type='primary' link onClick={() => unbindDevice(scope.row)}> <el-link type="primary" link onClick={() => unbindDevice(scope.row)}>
{value} {value}
</el-link> </el-link>
); )
}, }
}, },
{ {
prop: 'checkState', prop: 'checkState',
label: '检测状态', label: '检测状态',
minWidth: 150, minWidth: 150,
render: (scope: { row: { checkState: number } }) => { render: (scope: { row: { checkState: number } }) => {
return ( return scope.row.checkState === 0 ? (
scope.row.checkState === 0 ? <el-tag type='warning' effect="dark">未检</el-tag> : <el-tag type="warning" effect="dark">
scope.row.checkState === 1 ? <el-tag type='danger' effect="dark">检测中</el-tag> : 未检
<el-tag type='success' effect="dark">检测完成</el-tag> </el-tag>
) : scope.row.checkState === 1 ? (
<el-tag type="danger" effect="dark">
检测中
</el-tag>
) : (
<el-tag type="success" effect="dark">
检测完成
</el-tag>
) )
}
}, },
}, { prop: 'operation', label: '操作', fixed: 'right', width: 100 }
{ prop: 'operation', label: '操作', fixed: 'right', width: 100}, ])
])
const editableTabs = computed(() => { const editableTabs = computed(() => {
console.log('editableTabs',planFormContent.value) console.log('editableTabs', planFormContent.value)
const tabs = [] const tabs = []
// 主计划 tab // 主计划 tab
if (planFormContent.value) { if (planFormContent.value) {
@@ -286,75 +314,77 @@ const editableTabs = computed(() => {
//解绑被检设备 //解绑被检设备
const unbindDevice = (row: any) => { const unbindDevice = (row: any) => {
if(row.state == '/') if (row.state == '/') return
return
ElMessageBox.confirm(`确定将设备 ${row.name} 从子计划中解绑吗?`, '提示', { ElMessageBox.confirm(`确定将设备 ${row.name} 从子计划中解绑吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.checkState != 0){ .then(async () => {
ElMessage.warning(`当前设备已检,无法解除绑定!`); if (row.checkState != 0) {
ElMessage.warning(`当前设备已检,无法解除绑定!`)
return return
} }
await subPlanBindDev({'planId': row.planId, 'devIds': [row.id] ,'bindFlag': 0}) //解绑 0 绑定 1 await subPlanBindDev({ planId: row.planId, devIds: [row.id], bindFlag: 0 }) //解绑 0 绑定 1
// 👇 更新数据(例如清空 state 字段) // 👇 更新数据(例如清空 state 字段)
row.state = '/' row.state = '/'
proTable.value?.getTableList() proTable.value?.getTableList()
// 可选:刷新表格或提交接口 // 可选:刷新表格或提交接口
ElMessage.success('解绑成功') ElMessage.success('解绑成功')
}).catch(() => { })
.catch(() => {
// 用户取消操作 // 用户取消操作
}) })
} }
// 新增 tab 方法 // 新增 tab 方法
const addTab = (type: string) => { const addTab = (type: string) => {
if(type === "add"){ if (type === 'add') {
planPopup.value?.open("edit", planFormContent.value,modeStore.currentMode,1) planPopup.value?.open('edit', planFormContent.value, modeStore.currentMode, 1)
}else { } else {
const subPlanFormContent = ref<Plan.ReqPlan>() const subPlanFormContent = ref<Plan.ReqPlan>()
// 从 planFormContent.value?.children 中找到 id 与 item.name 匹配的子计划 // 从 planFormContent.value?.children 中找到 id 与 item.name 匹配的子计划
subPlanFormContent.value = planFormContent.value?.children?.find( subPlanFormContent.value = planFormContent.value?.children?.find(
(child: Plan.ReqPlan) => child.id === planId.value (child: Plan.ReqPlan) => child.id === planId.value
) )
console.log('0000---',subPlanFormContent.value) console.log('0000---', subPlanFormContent.value)
planPopup.value?.open("edit", subPlanFormContent.value,modeStore.currentMode,2) planPopup.value?.open('edit', subPlanFormContent.value, modeStore.currentMode, 2)
} }
} }
//收到子组件回复后新增子计划tab //收到子组件回复后新增子计划tab
const addNewChildTab = async () => { const addNewChildTab = async () => {
await props.refreshTable!()//刷新检测计划列表 await props.refreshTable!() //刷新检测计划列表
} }
//分配被检设备 //分配被检设备
const distribute = (childPlan: Plan.ResPlan, scope: any) => { const distribute = (childPlan: Plan.ResPlan, scope: any) => {
// 获取当前选中的设备对象 // 获取当前选中的设备对象
const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) => const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) =>
scope.selectedListIds.includes(dev.id) scope.selectedListIds.includes(dev.id)
); )
// 找出不符合条件的设备 // 找出不符合条件的设备
const invalidDevices = selectedDevices.filter( const invalidDevices = selectedDevices.filter(
(dev: { checkState: number; assign: number }) => dev.checkState !== 0 || dev.assign === 1 (dev: { checkState: number; assign: number }) => dev.checkState !== 0 || dev.assign === 1
); )
if (invalidDevices.length > 0) { if (invalidDevices.length > 0) {
const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、'); const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、')
ElMessage.warning(`以下设备不可分配:${names}`); ElMessage.warning(`以下设备不可分配:${names}`)
proTable.value?.clearSelection() proTable.value?.clearSelection()
return; return
} }
ElMessageBox.confirm(`确定将以下被检设备分配给 ${childPlan.name} 吗?`, '提示', { ElMessageBox.confirm(`确定将以下被检设备分配给 ${childPlan.name} 吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning'
}).then(async () => { })
await subPlanBindDev({'planId': childPlan.id, 'devIds': scope.selectedListIds ,'bindFlag': 1}) //解绑 0 绑定 1 .then(async () => {
await subPlanBindDev({ planId: childPlan.id, devIds: scope.selectedListIds, bindFlag: 1 }) //解绑 0 绑定 1
proTable.value?.getTableList() proTable.value?.getTableList()
ElMessage.success('分配成功') ElMessage.success('分配成功')
}).catch(() => { })
.catch(() => {
// 用户取消操作 // 用户取消操作
}) })
} }
@@ -366,53 +396,54 @@ const allotStandardDev = (childPlan: Plan.ResPlan) => {
// 删除 tab 方法 // 删除 tab 方法
const removeTab = async (targetName: TabPaneName) => { const removeTab = async (targetName: TabPaneName) => {
// 找到匹配的 tab // 找到匹配的 tab
const tab = editableTabs.value.find(item => item.name === targetName); const tab = editableTabs.value.find(item => item.name === targetName)
const tabTitle = tab?.title || '未知计划'; // 获取 tab 的标题,若不存在则默认为 '未知计划' const tabTitle = tab?.title || '未知计划' // 获取 tab 的标题,若不存在则默认为 '未知计划'
await useHandleData(deletePlan, { id: [targetName], pattern: patternId.value }, `删除【${tabTitle}】检测计划`); await useHandleData(deletePlan, { id: [targetName], pattern: patternId.value }, `删除【${tabTitle}】检测计划`)
await props.refreshTable!()//刷新检测计划列表 await props.refreshTable!() //刷新检测计划列表
} }
// 弹窗打开方法 // 弹窗打开方法
const open = async (textTitle: string,data: Plan.ReqPlan,pattern: string) => { const open = async (textTitle: string, data: Plan.ReqPlan, pattern: string) => {
console.log('open',data) console.log('open', data)
dialogVisible.value = true dialogVisible.value = true
title.value = textTitle title.value = textTitle
planTitle.value = data.name planTitle.value = data.name
planId.value = data.id planId.value = data.id
planFormContent.value = data planFormContent.value = data
editableTabsValue.value = planFormContent.value.id//默认tab第一个 editableTabsValue.value = planFormContent.value.id //默认tab第一个
proTable.value?.getTableList() proTable.value?.getTableList()
isTabPlanFather.value = false//子计划页面按钮默认展示主计划的 isTabPlanFather.value = false //子计划页面按钮默认展示主计划的
patternId.value = pattern patternId.value = pattern
columns.forEach(item => {//刚进去子计划页面隐藏主计划的操作列 columns.forEach(item => {
//刚进去子计划页面隐藏主计划的操作列
if (item.prop === 'operation') { if (item.prop === 'operation') {
item.isShow = false; item.isShow = false
} }
}); })
} }
const handleTabClick = (tab:any) => { const handleTabClick = (tab: any) => {
if(tab.props.closable){ if (tab.props.closable) {
columns.forEach(item => {//隐藏子计划名称 columns.forEach(item => {
//隐藏子计划名称
if (item.prop === 'boundPlanName') { if (item.prop === 'boundPlanName') {
item.isShow = false; item.isShow = false
} }
if (item.prop === 'operation') { if (item.prop === 'operation') {
item.isShow = true; item.isShow = true
} }
}); })
isTabPlanFather.value = true isTabPlanFather.value = true
}else{ } else {
columns.forEach(item => { columns.forEach(item => {
if (item.prop === 'boundPlanName') { if (item.prop === 'boundPlanName') {
item.isShow = true; item.isShow = true
} }
if (item.prop === 'operation') { if (item.prop === 'operation') {
item.isShow = false; item.isShow = false
} }
}); })
isTabPlanFather.value = false isTabPlanFather.value = false
} }
planId.value = tab.props.name planId.value = tab.props.name
@@ -422,7 +453,7 @@ const handleTabClick = (tab:any) => {
const handleTableDataUpdate = async (newData: any[]) => { const handleTableDataUpdate = async (newData: any[]) => {
// 👇 处理新数据,例如更新 planFormContent // 👇 处理新数据,例如更新 planFormContent
console.log('handleTableDataUpdate', newData) console.log('handleTableDataUpdate', newData)
const matchedItem = findItemById(newData, planId.value); const matchedItem = findItemById(newData, planId.value)
if (matchedItem) { if (matchedItem) {
planFormContent.value = matchedItem planFormContent.value = matchedItem
console.log('递归匹配成功:', planFormContent.value) console.log('递归匹配成功:', planFormContent.value)
@@ -434,19 +465,17 @@ const handleTableDataUpdate = async (newData: any[]) => {
const findItemById = (data: any[], id: string): any => { const findItemById = (data: any[], id: string): any => {
for (const item of data) { for (const item of data) {
if (item.id === id) { if (item.id === id) {
return item; // 找到匹配项,返回它 return item // 找到匹配项,返回它
} }
if (item.children && item.children.length > 0) { if (item.children && item.children.length > 0) {
const result = findItemById(item.children, id); // 递归查找子项 const result = findItemById(item.children, id) // 递归查找子项
if (result) { if (result) {
return item; // 如果子项中找到,返回结果 return item // 如果子项中找到,返回结果
} }
} }
} }
return null; // 未找到匹配项 return null // 未找到匹配项
}; }
//主计划下移除被检设备 //主计划下移除被检设备
const handleRemove = async (row: any) => { const handleRemove = async (row: any) => {
@@ -454,16 +483,18 @@ const handleRemove = async (row: any) => {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.assign != 0){ .then(async () => {
ElMessage.warning(`当前设备已被子计划绑定,无法删除!`); if (row.assign != 0) {
ElMessage.warning(`当前设备已被子计划绑定,无法删除!`)
return return
} }
console.log('shcn',planFormContent.value) console.log('shcn', planFormContent.value)
proTable.value?.getTableList(); // 刷新当前表格 proTable.value?.getTableList() // 刷新当前表格
}).catch(() => { })
.catch(() => {
// 用户取消操作 // 用户取消操作
}); })
} }
//子计划下移除被检设备 //子计划下移除被检设备
@@ -472,36 +503,34 @@ const subHandleRemove = async (row: any) => {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.checkState != 0){ .then(async () => {
ElMessage.warning(`当前设备已检,无法移除!`); if (row.checkState != 0) {
ElMessage.warning(`当前设备已检,无法移除!`)
return return
} }
await subPlanBindDev({'planId': row.planId, 'devIds': [row.id] ,'bindFlag': 0}) //解绑 0 绑定 1 await subPlanBindDev({ planId: row.planId, devIds: [row.id], bindFlag: 0 }) //解绑 0 绑定 1
ElMessage.success('移除成功'); ElMessage.success('移除成功')
proTable.value?.getTableList(); // 刷新当前表格 proTable.value?.getTableList() // 刷新当前表格
}).catch(() => { })
.catch(() => {
// 用户取消操作 // 用户取消操作
}); })
} }
// 子计划下批量移除被检设备 // 子计划下批量移除被检设备
const subBatchRemove = async (selectedListIds: string[]) => { const subBatchRemove = async (selectedListIds: string[]) => {
const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) => const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) =>
selectedListIds.includes(dev.id) selectedListIds.includes(dev.id)
); )
const invalidDevices = selectedDevices.filter( const invalidDevices = selectedDevices.filter((dev: { checkState: number }) => dev.checkState !== 0)
(dev: { checkState: number }) => dev.checkState !== 0
);
if (invalidDevices.length > 0) { if (invalidDevices.length > 0) {
const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、'); const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、')
ElMessage.warning(`以下设备不可移除(已检):${names}`); ElMessage.warning(`以下设备不可移除(已检):${names}`)
proTable.value?.clearSelection(); proTable.value?.clearSelection()
return; return
} }
try { try {
@@ -509,23 +538,23 @@ const subBatchRemove = async (selectedListIds: string[]) => {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}); })
await subPlanBindDev({ planId: planId.value, devIds: selectedListIds, bindFlag: 0 }); await subPlanBindDev({ planId: planId.value, devIds: selectedListIds, bindFlag: 0 })
ElMessage.success('批量移除成功'); ElMessage.success('批量移除成功')
proTable.value?.getTableList(); // 刷新表格 proTable.value?.getTableList() // 刷新表格
} catch (error) { } catch (error) {
// 用户取消或接口异常 // 用户取消或接口异常
console.error('批量移除失败:', error); console.error('批量移除失败:', error)
} }
}; }
const handleClose = () => { const handleClose = () => {
dialogVisible.value = false dialogVisible.value = false
router.push('/plan/planList') router.push('/plan/planList')
} }
defineExpose({ open,handleTableDataUpdate }) defineExpose({ open, handleTableDataUpdate })
interface ChildrenPlanProps { interface ChildrenPlanProps {
refreshTable?: () => Promise<void> refreshTable?: () => Promise<void>

View File

@@ -1,88 +1,118 @@
<template> <template>
<!-- 权限信息弹出框 --> <!-- 权限信息弹出框 -->
<el-dialog title="标准设备绑定" v-model='dialogVisible' @close="close" v-bind="dialogBig" width="600" draggable> <el-dialog title="标准设备绑定" v-model="dialogVisible" @close="close" v-bind="dialogBig" width="700" draggable>
<div> <div>
<el-transfer v-model="value" <el-transfer
v-model="value"
filterable filterable
:filter-method="filterMethod" :filter-method="filterMethod"
filter-placeholder="请输入内容搜索" filter-placeholder="请输入内容搜索"
:data="allData" :data="allData"
:titles="['未绑定标准设备', '已绑定标准设备']"> :titles="['未绑定标准设备', '已绑定标准设备']"
>
<template #default="{ option }"> <template #default="{ option }">
<el-tooltip :content="option.tips" placement="top" :show-after=1000> <div style="display: flex; align-items: center; justify-content: space-between">
<span>{{ option.label }}</span> <span>{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}</span>
</el-tooltip> <!-- <el-tooltip placement="top" effect="light">
<template #content>
<el-descriptions size="small" title="标准设备详情" border>
<el-descriptions-item label="设备名称">
{{ JSON.parse(option.label).name }}
</el-descriptions-item>
<el-descriptions-item label="设备厂家">
{{ JSON.parse(option.label).manufacturer }}
</el-descriptions-item>
</el-descriptions>
</template>
<el-icon><Warning /></el-icon>
</el-tooltip>-->
</div>
</template> </template>
</el-transfer> </el-transfer>
</div> </div>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button @click="close()">取消</el-button> <el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()"> <el-button type="primary" @click="save()">保存</el-button>
保存
</el-button>
</div> </div>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import type { StandardDevice } from '@/api/device/interface/standardDevice' import type { StandardDevice } from '@/api/device/interface/standardDevice'
import { dialogBig } from '@/utils/elementBind' import { dialogBig } from '@/utils/elementBind'
import { getBoundStandardDevList,getUnboundStandardDevList,subPlanBindStandardDevList } from '@/api/plan/plan.ts' import { getBoundStandardDevList, getUnboundStandardDevList, subPlanBindStandardDevList } from '@/api/plan/plan.ts'
import { type Plan } from '@/api/plan/interface' import { type Plan } from '@/api/plan/interface'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const unboundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//指定模式下所有未绑定的标准设备 import { useDictStore } from '@/stores/modules/dict'
const boundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//根据检测计划id查询出所有已绑定的标准设备
const dialogVisible = ref(false)
const planData = ref<Plan.ReqPlan | null>(null) // 新增状态管理
const value = ref<string[]>([]) const unboundStandardDevList = ref<StandardDevice.ResPqStandardDevice[]>([]) //指定模式下所有未绑定的标准设备
const generateData = () => { const boundStandardDevList = ref<StandardDevice.ResPqStandardDevice[]>([]) //根据检测计划id查询出所有已绑定的标准设备
const dialogVisible = ref(false)
const planData = ref<Plan.ReqPlan | null>(null) // 新增状态管理
const value = ref<string[]>([])
const dictStore = useDictStore()
const generateData = () => {
const manufacturerDict = dictStore.getDictData('Dev_Manufacturers')
unboundStandardDevList.value.forEach(i => {
// 确保字段不为空且字典存在再进行查找
if (i.manufacturer && manufacturerDict) {
const manufacturer = manufacturerDict.find(item => item.id === i.manufacturer)
if (manufacturer) {
i.manufacturer = manufacturer.name
}
}
})
const unboundData = unboundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({ const unboundData = unboundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id, key: i.id,
label: i.name, label: JSON.stringify(i)
})) }))
boundStandardDevList.value.forEach(i => {
// 确保字段不为空且字典存在再进行查找
if (i.manufacturer && manufacturerDict) {
const manufacturer = manufacturerDict.find(item => item.id === i.manufacturer)
if (manufacturer) {
i.manufacturer = manufacturer.name
}
}
})
const boundData = boundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({ const boundData = boundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id, key: i.id,
label: i.name, label: JSON.stringify(i)
})) }))
return [...unboundData, ...boundData] return [...unboundData, ...boundData]
} }
const allData = computed(() => generateData()) const allData = computed(() => generateData())
const filterMethod = (query: string, item: { label?: string }) => { const filterMethod = (query: string, item: { label?: string }) => {
return item.label?.toLowerCase().includes(query.toLowerCase()) ?? false return item.label?.toLowerCase().includes(query.toLowerCase()) ?? false
} }
// 打开弹窗,可能是新增,也可能是编辑 // 打开弹窗,可能是新增,也可能是编辑
const open = async (data: Plan.ReqPlan) => { const open = async (data: Plan.ReqPlan) => {
dialogVisible.value = true dialogVisible.value = true
planData.value = data planData.value = data
console.log('planData.value',planData.value) console.log('planData.value', planData.value)
const standardDevList_Result1 = await getUnboundStandardDevList(data); const standardDevList_Result1 = await getUnboundStandardDevList(data)
unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[]; unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[]
const standardDevList_Result2 = await getBoundStandardDevList(data); const standardDevList_Result2 = await getBoundStandardDevList(data)
boundStandardDevList.value = standardDevList_Result2.data as StandardDevice.ResPqStandardDevice[]; boundStandardDevList.value = standardDevList_Result2.data as StandardDevice.ResPqStandardDevice[]
value.value = boundStandardDevList.value.map((i: { id: { toString: () => any } }) => i.id.toString());
value.value = boundStandardDevList.value.map((i: { id: { toString: () => any } }) => i.id.toString())
} }
const close = () => { const close = () => {
dialogVisible.value = false dialogVisible.value = false
} }
const emit = defineEmits(['update:table'])
const emit = defineEmits(['update:table']) const save = async () => {
const save = async () => {
if (planData.value) { if (planData.value) {
planData.value.planId = planData.value.id planData.value.planId = planData.value.id
planData.value.devIds = value.value planData.value.devIds = value.value
@@ -91,9 +121,14 @@ const filterMethod = (query: string, item: { label?: string }) => {
ElMessage.success({ message: `标准设备绑定保存成功!` }) ElMessage.success({ message: `标准设备绑定保存成功!` })
} }
dialogVisible.value = false dialogVisible.value = false
} }
// 对外映射 // 对外映射
defineExpose({ open }) defineExpose({ open })
</script>
</script> <style scoped lang="scss">
:deep(.el-transfer) {
--el-transfer-panel-width: 250px;
--el-transfer-panel-body-height: 315px;
}
</style>

View File

@@ -9,7 +9,7 @@
align-center align-center
> >
<el-row :gutter="24"> <el-row :gutter="24">
<el-col :span="planType == 0 ? 10 : 24"> <el-col :span="10">
<el-form :model="formContent" ref="dialogFormRef" :rules="rules"> <el-form :model="formContent" ref="dialogFormRef" :rules="rules">
<el-form-item label="名称" prop="name" :label-width="110"> <el-form-item label="名称" prop="name" :label-width="110">
<el-input <el-input
@@ -20,18 +20,13 @@
show-word-limit show-word-limit
/> />
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="标准设备" prop="standardDevIds" :label-width="110">
label="标准设备"
prop="standardDevIds"
:label-width="110"
v-if="selectByMode && planType == 0"
>
<el-select <el-select
v-model="formContent.standardDevIds" v-model="formContent.standardDevIds"
multiple multiple
filterable
collapse-tags collapse-tags
:max-collapse-tags="2" :max-collapse-tags="2"
:disabled="planType != 0"
placeholder="请选择标准设备" placeholder="请选择标准设备"
clearable clearable
> >
@@ -46,6 +41,7 @@
</el-form-item> </el-form-item>
<el-form-item label="测试项" prop="testItems" :label-width="110" v-if="selectByMode"> <el-form-item label="测试项" prop="testItems" :label-width="110" v-if="selectByMode">
<el-select <el-select
filterable
v-model="formContent.testItems" v-model="formContent.testItems"
multiple multiple
collapse-tags collapse-tags
@@ -64,6 +60,7 @@
</el-form-item> </el-form-item>
<el-form-item label="检测源" prop="sourceIds" :label-width="110" v-if="!selectByMode"> <el-form-item label="检测源" prop="sourceIds" :label-width="110" v-if="!selectByMode">
<el-select <el-select
filterable
v-model="formContent.sourceIds" v-model="formContent.sourceIds"
:multiple="selectByMode" :multiple="selectByMode"
collapse-tags collapse-tags
@@ -80,6 +77,7 @@
</el-form-item> </el-form-item>
<el-form-item label="数据源" prop="datasourceIds" :label-width="110"> <el-form-item label="数据源" prop="datasourceIds" :label-width="110">
<el-select <el-select
filterable
v-model="formContent.datasourceIds" v-model="formContent.datasourceIds"
:multiple="selectByMode" :multiple="selectByMode"
:max-collapse-tags="2" :max-collapse-tags="2"
@@ -116,6 +114,7 @@
</el-form-item> </el-form-item>
<el-form-item label="误差体系" prop="errorSysId" :label-width="110"> <el-form-item label="误差体系" prop="errorSysId" :label-width="110">
<el-select <el-select
filterable
v-model="formContent.errorSysId" v-model="formContent.errorSysId"
placeholder="请选择误差体系" placeholder="请选择误差体系"
autocomplete="off" autocomplete="off"
@@ -180,7 +179,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
<el-col :span="14" v-if="planType == 0"> <el-col :span="14">
<el-transfer <el-transfer
v-model="value" v-model="value"
filterable filterable
@@ -190,7 +189,7 @@
:titles="['未绑定被检设备', '已绑定被检设备']" :titles="['未绑定被检设备', '已绑定被检设备']"
> >
<template #default="{ option }"> <template #default="{ option }">
<div style="display: flex; align-items: center; justify-content:space-between"> <div style="display: flex; align-items: center; justify-content: space-between">
<span> <span>
{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }} {{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}
</span> </span>
@@ -219,7 +218,7 @@
</div> </div>
</template> </template>
<template #left-footer> <template #left-footer v-if="planType === 0">
<el-button <el-button
class="transfer-footer" class="transfer-footer"
v-if="modeStore.currentMode !== '比对式'" v-if="modeStore.currentMode !== '比对式'"
@@ -243,7 +242,7 @@
导入被检设备 导入被检设备
</el-button> </el-button>
</template> </template>
<template #right-footer> <template #right-footer v-if="planType === 0">
<el-text></el-text> <el-text></el-text>
</template> </template>
<template #left-empty> <template #left-empty>
@@ -261,7 +260,7 @@
<el-button type="primary" @click="save()"> </el-button> <el-button type="primary" @click="save()"> </el-button>
</div> </div>
</template> </template>
<ImportExcel ref="deviceImportExcel" /> <ImportExcel ref="deviceImportExcel" @result="importResult" />
</el-dialog> </el-dialog>
</template> </template>
@@ -273,12 +272,12 @@ import { type Plan } from '@/api/plan/interface'
import { import {
addPlan, addPlan,
getBoundPqDevList, getBoundPqDevList,
getBoundStandardDevAllList,
getPqErrSysList, getPqErrSysList,
getPqScriptList, getPqScriptList,
getTestSourceList, getTestSourceList,
getUnboundPqDevList, getUnboundPqDevList,
updatePlan, updatePlan
updateSubPlanName
} from '@/api/plan/plan.ts' } from '@/api/plan/plan.ts'
import { useDictStore } from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import { type TestSource } from '@/api/device/interface/testSource' import { type TestSource } from '@/api/device/interface/testSource'
@@ -322,7 +321,7 @@ const userArray = ref<{ label: string; value: string }[]>([])
const unboundPqDevList = ref<Device.ResPqDev[]>([]) //指定模式下所有未绑定的设备 const unboundPqDevList = ref<Device.ResPqDev[]>([]) //指定模式下所有未绑定的设备
const boundPqDevList = ref<Device.ResPqDev[]>([]) //根据检测计划id查询出所有已绑定的设备 const boundPqDevList = ref<Device.ResPqDev[]>([]) //根据检测计划id查询出所有已绑定的设备
const value = ref<string[]>([]) const value = ref<string[]>([])
const allData = computed(() => generateData()) const allData = ref<[any[], any[]]>([])
const isSelectDisabled = ref(false) const isSelectDisabled = ref(false)
const planType = ref<number>(0) const planType = ref<number>(0)
const subPlanBindStandardDev = ref<any>([]) //哪些标准设备已经被子计划绑定 const subPlanBindStandardDev = ref<any>([]) //哪些标准设备已经被子计划绑定
@@ -359,7 +358,7 @@ const generateData = () => {
//tips: i.description //tips: i.description
disabled: i.checkState != 0 || i.assign == 1 disabled: i.checkState != 0 || i.assign == 1
})) }))
return [...unboundData, ...boundData] allData.value = [...unboundData, ...boundData]
} }
const filterMethod = (query: string, item: { label?: string }) => { const filterMethod = (query: string, item: { label?: string }) => {
@@ -504,7 +503,6 @@ const save = () => {
dialogFormRef.value?.validate(async (valid: boolean) => { dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) { if (valid) {
formContent.devIds = value.value formContent.devIds = value.value
if (formContent.id) { if (formContent.id) {
// 把数据处理原则转成字典ID // 把数据处理原则转成字典ID
const patternItem = dictStore const patternItem = dictStore
@@ -514,16 +512,18 @@ const save = () => {
formContent.dataRule = patternItem.id formContent.dataRule = patternItem.id
} }
if (mode.value === '比对式') { if (mode.value === '比对式') {
// 新增子计划
if (planType.value == 1) { if (planType.value == 1) {
formContent.fatherPlanId = formContent.id formContent.fatherPlanId = formContent.id
formContent.id = '' formContent.id = ''
formContent.devIds = [] //formContent.devIds = []
formContent.standardDevIds = [] //formContent.standardDevIds = []
formContent.standardDevMap = new Map<string, number>() // formContent.standardDevMap = new Map<string, number>()
await addPlan(formContent) await addPlan(formContent)
emit('update:tab') emit('update:tab')
// 编辑子计划
} else if (planType.value == 2) { } else if (planType.value == 2) {
await updateSubPlanName(formContent) await updatePlan(formContent)
emit('update:tab') emit('update:tab')
console.log('更新子计划', formContent) console.log('更新子计划', formContent)
} else { } else {
@@ -565,10 +565,8 @@ const save = () => {
} }
close() close()
// 刷新表格 // 刷新表格
if (planType.value == 0) {
await props.refreshTable!() await props.refreshTable!()
} }
}
}) })
} catch (err) { } catch (err) {
console.error('验证过程中出现错误', err) console.error('验证过程中出现错误', err)
@@ -759,8 +757,20 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
Object.assign(formContent, { ...data }) Object.assign(formContent, { ...data })
//设备绑定显示 //设备绑定显示
if (planType.value === 0) {
unboundPqDevList.value = unboundData as Device.ResPqDev[] unboundPqDevList.value = unboundData as Device.ResPqDev[]
boundPqDevList.value = boundData as Device.ResPqDev[] boundPqDevList.value = boundData as Device.ResPqDev[]
} else if (planType.value === 1) {
unboundPqDevList.value = boundData.filter(i => !i.boundPlanName) as Device.ResPqDev[]
} else if (planType.value === 2) {
const fatherBoundData_Result = await getBoundPqDevList({ planIdList: [data.fatherPlanId] })
const fatherBoundData = Array.isArray(fatherBoundData_Result.data) ? fatherBoundData_Result.data : []
// 从 fatherBoundData 中排除 boundData 中已存在的数据(根据 id 进行比较)
unboundPqDevList.value = fatherBoundData.filter(
fatherItem => !boundData.some(boundItem => boundItem.id === fatherItem.id)
) as Device.ResPqDev[]
boundPqDevList.value = boundData as Device.ResPqDev[]
}
} }
pqToArray() //将对象转为数组 pqToArray() //将对象转为数组
@@ -796,6 +806,7 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
value: item.id value: item.id
})) }))
} }
generateData()
// 所有数据加载完成后显示对话框 // 所有数据加载完成后显示对话框
dialogVisible.value = true dialogVisible.value = true
} }
@@ -837,10 +848,30 @@ function pqToArray() {
})) }))
const sourceArray5 = Array.isArray(pqStandardDevList.value) ? pqStandardDevList.value : [] const sourceArray5 = Array.isArray(pqStandardDevList.value) ? pqStandardDevList.value : []
if (planType.value === 0) {
pqStandardDevArray.value = sourceArray5.map(item => ({ pqStandardDevArray.value = sourceArray5.map(item => ({
label: item.name, label: item.name,
value: item.id value: item.id
})) }))
} else if (planType.value === 1) {
pqStandardDevArray.value = sourceArray5
.filter(item => formContent.standardDevIds.includes(item.id))
.map(item => ({
label: item.name,
value: item.id
}))
formContent.standardDevIds = []
formContent.standardDevMap = new Map<string, number>()
} else if (planType.value === 2) {
const params = { id: formContent.id }
getBoundStandardDevAllList(params).then(result => {
const boundStandardDevAllList = Array.isArray(result.data) ? result.data : []
pqStandardDevArray.value = boundStandardDevAllList.map(item => ({
label: item.name,
value: item.id
}))
})
}
} }
const dataSourceType = computed(() => { const dataSourceType = computed(() => {
@@ -899,7 +930,17 @@ const importFile = async (pattern: string) => {
} }
deviceImportExcel.value?.acceptParams(params) deviceImportExcel.value?.acceptParams(params)
} }
const importResult = async (success: boolean | undefined) => {
if (success) {
const patternId = dictStore.getDictData('Pattern').find(item => item.name === mode.value)?.id ?? ''
const data = { pattern: patternId }
// 刷新未绑定的
const unboundPqDevList_Result = await getUnboundPqDevList(data)
const unboundData = Array.isArray(unboundPqDevList_Result.data) ? unboundPqDevList_Result.data : []
unboundPqDevList.value = unboundData
generateData()
}
}
// 对外映射 // 对外映射
defineExpose({ open }) defineExpose({ open })
const props = defineProps<{ const props = defineProps<{