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

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

View File

@@ -1,99 +1,134 @@
<template>
<!-- 权限信息弹出框 -->
<el-dialog title="标准设备绑定" v-model='dialogVisible' @close="close" v-bind="dialogBig" width="600" draggable>
<div>
<el-transfer v-model="value"
filterable
:filter-method="filterMethod"
filter-placeholder="请输入内容搜索"
:data="allData"
:titles="['未绑定标准设备', '已绑定标准设备']">
<template #default="{ option }">
<el-tooltip :content="option.tips" placement="top" :show-after=1000>
<span>{{ option.label }}</span>
</el-tooltip>
</template>
</el-transfer>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()">
保存
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import type { StandardDevice } from '@/api/device/interface/standardDevice'
import { dialogBig } from '@/utils/elementBind'
import { getBoundStandardDevList,getUnboundStandardDevList,subPlanBindStandardDevList } from '@/api/plan/plan.ts'
import { type Plan } from '@/api/plan/interface'
import { ElMessage } from 'element-plus'
const unboundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//指定模式下所有未绑定的标准设备
const boundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//根据检测计划id查询出所有已绑定的标准设备
const dialogVisible = ref(false)
const planData = ref<Plan.ReqPlan | null>(null) // 新增状态管理
const value = ref<string[]>([])
const generateData = () => {
const unboundData = unboundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id,
label: i.name,
}))
const boundData = boundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id,
label: i.name,
}))
<el-dialog title="标准设备绑定" v-model="dialogVisible" @close="close" v-bind="dialogBig" width="700" draggable>
<div>
<el-transfer
v-model="value"
filterable
:filter-method="filterMethod"
filter-placeholder="请输入内容搜索"
:data="allData"
:titles="['未绑定标准设备', '已绑定标准设备']"
>
<template #default="{ option }">
<div style="display: flex; align-items: center; justify-content: space-between">
<span>{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}</span>
<!-- <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>
</el-transfer>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()">保存</el-button>
</div>
</template>
</el-dialog>
</template>
return [...unboundData, ...boundData]
<script lang="ts" setup>
import { computed, ref } from 'vue'
import type { StandardDevice } from '@/api/device/interface/standardDevice'
import { dialogBig } from '@/utils/elementBind'
import { getBoundStandardDevList, getUnboundStandardDevList, subPlanBindStandardDevList } from '@/api/plan/plan.ts'
import { type Plan } from '@/api/plan/interface'
import { ElMessage } from 'element-plus'
import { useDictStore } from '@/stores/modules/dict'
const unboundStandardDevList = ref<StandardDevice.ResPqStandardDevice[]>([]) //指定模式下所有未绑定的标准设备
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) => ({
key: i.id,
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) => ({
key: i.id,
label: JSON.stringify(i)
}))
return [...unboundData, ...boundData]
}
const allData = computed(() => generateData())
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) => {
dialogVisible.value = true
planData.value = data
console.log('planData.value',planData.value)
const standardDevList_Result1 = await getUnboundStandardDevList(data);
unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[];
// 打开弹窗,可能是新增,也可能是编辑
const open = async (data: Plan.ReqPlan) => {
dialogVisible.value = true
planData.value = data
console.log('planData.value', planData.value)
const standardDevList_Result1 = await getUnboundStandardDevList(data)
unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[]
const standardDevList_Result2 = await getBoundStandardDevList(data);
boundStandardDevList.value = standardDevList_Result2.data as StandardDevice.ResPqStandardDevice[];
const standardDevList_Result2 = await getBoundStandardDevList(data)
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
}
}
const emit = defineEmits(['update:table'])
const emit = defineEmits(['update:table'])
const save = async () => {
const save = async () => {
if (planData.value) {
planData.value.planId = planData.value.id
planData.value.devIds = value.value
await subPlanBindStandardDevList(planData.value)
emit('update:table')
ElMessage.success({ message: `标准设备绑定保存成功!` })
planData.value.planId = planData.value.id
planData.value.devIds = value.value
await subPlanBindStandardDevList(planData.value)
emit('update:table')
ElMessage.success({ message: `标准设备绑定保存成功!` })
}
dialogVisible.value = false
}
}
// 对外映射
// 对外映射
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
>
<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-item label="名称" prop="name" :label-width="110">
<el-input
@@ -20,18 +20,13 @@
show-word-limit
/>
</el-form-item>
<el-form-item
label="标准设备"
prop="standardDevIds"
:label-width="110"
v-if="selectByMode && planType == 0"
>
<el-form-item label="标准设备" prop="standardDevIds" :label-width="110">
<el-select
v-model="formContent.standardDevIds"
multiple
filterable
collapse-tags
:max-collapse-tags="2"
:disabled="planType != 0"
placeholder="请选择标准设备"
clearable
>
@@ -46,6 +41,7 @@
</el-form-item>
<el-form-item label="测试项" prop="testItems" :label-width="110" v-if="selectByMode">
<el-select
filterable
v-model="formContent.testItems"
multiple
collapse-tags
@@ -64,6 +60,7 @@
</el-form-item>
<el-form-item label="检测源" prop="sourceIds" :label-width="110" v-if="!selectByMode">
<el-select
filterable
v-model="formContent.sourceIds"
:multiple="selectByMode"
collapse-tags
@@ -80,6 +77,7 @@
</el-form-item>
<el-form-item label="数据源" prop="datasourceIds" :label-width="110">
<el-select
filterable
v-model="formContent.datasourceIds"
:multiple="selectByMode"
:max-collapse-tags="2"
@@ -116,6 +114,7 @@
</el-form-item>
<el-form-item label="误差体系" prop="errorSysId" :label-width="110">
<el-select
filterable
v-model="formContent.errorSysId"
placeholder="请选择误差体系"
autocomplete="off"
@@ -180,7 +179,7 @@
</el-form-item>
</el-form>
</el-col>
<el-col :span="14" v-if="planType == 0">
<el-col :span="14">
<el-transfer
v-model="value"
filterable
@@ -190,7 +189,7 @@
:titles="['未绑定被检设备', '已绑定被检设备']"
>
<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>
{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}
</span>
@@ -219,7 +218,7 @@
</div>
</template>
<template #left-footer>
<template #left-footer v-if="planType === 0">
<el-button
class="transfer-footer"
v-if="modeStore.currentMode !== '比对式'"
@@ -243,7 +242,7 @@
导入被检设备
</el-button>
</template>
<template #right-footer>
<template #right-footer v-if="planType === 0">
<el-text></el-text>
</template>
<template #left-empty>
@@ -261,7 +260,7 @@
<el-button type="primary" @click="save()"> </el-button>
</div>
</template>
<ImportExcel ref="deviceImportExcel" />
<ImportExcel ref="deviceImportExcel" @result="importResult" />
</el-dialog>
</template>
@@ -273,12 +272,12 @@ import { type Plan } from '@/api/plan/interface'
import {
addPlan,
getBoundPqDevList,
getBoundStandardDevAllList,
getPqErrSysList,
getPqScriptList,
getTestSourceList,
getUnboundPqDevList,
updatePlan,
updateSubPlanName
updatePlan
} from '@/api/plan/plan.ts'
import { useDictStore } from '@/stores/modules/dict'
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 boundPqDevList = ref<Device.ResPqDev[]>([]) //根据检测计划id查询出所有已绑定的设备
const value = ref<string[]>([])
const allData = computed(() => generateData())
const allData = ref<[any[], any[]]>([])
const isSelectDisabled = ref(false)
const planType = ref<number>(0)
const subPlanBindStandardDev = ref<any>([]) //哪些标准设备已经被子计划绑定
@@ -359,7 +358,7 @@ const generateData = () => {
//tips: i.description
disabled: i.checkState != 0 || i.assign == 1
}))
return [...unboundData, ...boundData]
allData.value = [...unboundData, ...boundData]
}
const filterMethod = (query: string, item: { label?: string }) => {
@@ -504,7 +503,6 @@ const save = () => {
dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
formContent.devIds = value.value
if (formContent.id) {
// 把数据处理原则转成字典ID
const patternItem = dictStore
@@ -514,16 +512,18 @@ const save = () => {
formContent.dataRule = patternItem.id
}
if (mode.value === '比对式') {
// 新增子计划
if (planType.value == 1) {
formContent.fatherPlanId = formContent.id
formContent.id = ''
formContent.devIds = []
formContent.standardDevIds = []
formContent.standardDevMap = new Map<string, number>()
//formContent.devIds = []
//formContent.standardDevIds = []
// formContent.standardDevMap = new Map<string, number>()
await addPlan(formContent)
emit('update:tab')
// 编辑子计划
} else if (planType.value == 2) {
await updateSubPlanName(formContent)
await updatePlan(formContent)
emit('update:tab')
console.log('更新子计划', formContent)
} else {
@@ -565,9 +565,7 @@ const save = () => {
}
close()
// 刷新表格
if (planType.value == 0) {
await props.refreshTable!()
}
await props.refreshTable!()
}
})
} catch (err) {
@@ -759,8 +757,20 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
Object.assign(formContent, { ...data })
//设备绑定显示
unboundPqDevList.value = unboundData as Device.ResPqDev[]
boundPqDevList.value = boundData as Device.ResPqDev[]
if (planType.value === 0) {
unboundPqDevList.value = unboundData 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() //将对象转为数组
@@ -796,6 +806,7 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
value: item.id
}))
}
generateData()
// 所有数据加载完成后显示对话框
dialogVisible.value = true
}
@@ -837,10 +848,30 @@ function pqToArray() {
}))
const sourceArray5 = Array.isArray(pqStandardDevList.value) ? pqStandardDevList.value : []
pqStandardDevArray.value = sourceArray5.map(item => ({
label: item.name,
value: item.id
}))
if (planType.value === 0) {
pqStandardDevArray.value = sourceArray5.map(item => ({
label: item.name,
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(() => {
@@ -899,7 +930,17 @@ const importFile = async (pattern: string) => {
}
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 })
const props = defineProps<{