♻️ refactor(mes): 清理无用代码和调整组件结构
parent
934baa46d4
commit
796c095044
|
|
@ -32,9 +32,6 @@ export const MdClientApi = {
|
|||
return await request.get({ url: `/mes/md-client/page`, params })
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
// 查询客户详情
|
||||
getClient: async (id: number) => {
|
||||
return await request.get({ url: `/mes/md-client/get?id=` + id })
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ export const MdWorkstationApi = {
|
|||
return await request.get({ url: `/mes/md-workstation/page`, params })
|
||||
},
|
||||
|
||||
|
||||
// 查询工作站详情
|
||||
getWorkstation: async (id: number) => {
|
||||
return await request.get({ url: `/mes/md-workstation/get?id=` + id })
|
||||
|
|
|
|||
|
|
@ -78,5 +78,5 @@ export const ProWorkOrderApi = {
|
|||
// 确认工单
|
||||
confirmWorkOrder: async (id: number) => {
|
||||
return await request.put({ url: `/mes/pro/work-order/confirm?id=` + id })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,10 +48,5 @@ export const TmToolApi = {
|
|||
// 导出工具台账 Excel
|
||||
exportTool: async (params: any) => {
|
||||
return await request.download({ url: `/mes/tm/tool/export-excel`, params })
|
||||
},
|
||||
|
||||
// 查询工具台账精简列表
|
||||
getToolSimpleList: async () => {
|
||||
return await request.get({ url: `/mes/tm/tool/simple-list` })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,5 +54,5 @@ export const BatchApi = {
|
|||
// 向后追溯
|
||||
getBackwardList: async (code: string) => {
|
||||
return await request.get({ url: `/mes/wm/batch/backward-list`, params: { code } })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,5 +45,5 @@ export const WmMaterialStockApi = {
|
|||
// 导出库存台账 Excel
|
||||
exportMaterialStock: async (params: any) => {
|
||||
return await request.download({ url: '/mes/wm/material-stock/export-excel', params })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { MdWorkstationToolApi, MdWorkstationToolVO } from '@/api/mes/md/workstation/tool'
|
||||
import TmToolTypeSelect from '@/views/mes/tm/tool/components/TmToolTypeSelect.vue'
|
||||
import TmToolTypeSelect from '@/views/mes/tm/tool/type/components/TmToolTypeSelect.vue'
|
||||
|
||||
defineOptions({ name: 'WorkstationToolList' })
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
|||
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
|
||||
import { TmToolTypeVO } from '@/api/mes/tm/tool/type'
|
||||
import { AutoCodeRecordApi } from '@/api/mes/md/autocode/record'
|
||||
import TmToolTypeSelect from '@/views/mes/tm/tool/components/TmToolTypeSelect.vue'
|
||||
import TmToolTypeSelect from '@/views/mes/tm/tool/type/components/TmToolTypeSelect.vue'
|
||||
import {
|
||||
MesToolStatusEnum,
|
||||
MesMaintenTypeEnum,
|
||||
|
|
|
|||
|
|
@ -1,37 +1,66 @@
|
|||
<!-- MES 工具选择器:纯下拉,前端过滤(支持 name、code) -->
|
||||
<!--
|
||||
MES 工具选择器:只读输入框 + 点击弹窗选择
|
||||
|
||||
交互:显示为只读 el-input,点击打开弹窗(单选模式)进行选择
|
||||
Props:
|
||||
modelValue — 绑定的工具 ID(v-model)
|
||||
disabled — 是否禁用
|
||||
clearable — 是否允许清空(鼠标悬停时显示清除图标)
|
||||
placeholder — 占位文字
|
||||
Events:
|
||||
update:modelValue — v-model 更新
|
||||
change(item) — 选中工具变化时触发,传递完整 TmToolVO(清空时为 undefined)
|
||||
-->
|
||||
<template>
|
||||
<el-select
|
||||
v-model="selectValue"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:clearable="clearable"
|
||||
filterable
|
||||
:filter-method="handleFilter"
|
||||
class="!w-1/1"
|
||||
@change="handleChange"
|
||||
<div
|
||||
v-bind="attrs"
|
||||
class="w-full"
|
||||
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
||||
@click="handleClick"
|
||||
@mouseenter="hovering = true"
|
||||
@mouseleave="hovering = false"
|
||||
>
|
||||
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
||||
<div class="flex items-center gap-8px">
|
||||
<span>{{ item.name }}</span>
|
||||
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
||||
编号: {{ item.code }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-tooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||
<template #content>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>工具编码:{{ selectedItem.code }}</div>
|
||||
<div>工具名称:{{ selectedItem.name }}</div>
|
||||
<div v-if="selectedItem.brand">品牌:{{ selectedItem.brand }}</div>
|
||||
<div v-if="selectedItem.spec">型号规格:{{ selectedItem.spec }}</div>
|
||||
<div v-if="selectedItem.toolTypeName">工具类型:{{ selectedItem.toolTypeName }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-input
|
||||
:model-value="displayLabel"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
readonly
|
||||
:suffix-icon="suffixIcon"
|
||||
:class="disabled ? 'is-select-disabled' : 'is-select-clickable'"
|
||||
/>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<!-- 弹窗必须放在 div 外部,否则弹窗内的点击事件会冒泡到 div 触发 handleClick -->
|
||||
<TmToolSelectDialog ref="dialogRef" :multiple="false" @selected="handleSelected" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
|
||||
import { Search, CircleClose } from '@element-plus/icons-vue'
|
||||
import TmToolSelectDialog from './TmToolSelectDialog.vue'
|
||||
|
||||
defineOptions({ name: 'TmToolSelect' })
|
||||
// 组件有两个根节点(div + Dialog),Vue 不会自动继承 attrs;
|
||||
// 手动透传到外层 div,确保父组件传入的 class / style 等生效
|
||||
const attrs = useAttrs()
|
||||
|
||||
defineOptions({ name: 'TmToolSelect', inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: number
|
||||
disabled?: boolean
|
||||
clearable?: boolean
|
||||
placeholder?: string
|
||||
modelValue?: number // 绑定的工具 ID
|
||||
disabled?: boolean // 是否禁用
|
||||
clearable?: boolean // 是否允许清空
|
||||
placeholder?: string // 占位文字
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
|
|
@ -45,36 +74,98 @@ const emit = defineEmits<{
|
|||
change: [item: TmToolVO | undefined]
|
||||
}>()
|
||||
|
||||
const allList = ref<TmToolVO[]>([])
|
||||
const filteredList = ref<TmToolVO[]>([])
|
||||
const dialogRef = ref() // 弹窗 Ref
|
||||
const hovering = ref(false) // 鼠标是否悬停
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
// ==================== 名称回显 ====================
|
||||
const selectedItem = ref<TmToolVO | undefined>() // 当前选中的工具对象
|
||||
|
||||
/** 输入框显示文本:只展示工具名称,保持简洁 */
|
||||
const displayLabel = computed(() => {
|
||||
return selectedItem.value?.name ?? ''
|
||||
})
|
||||
|
||||
/** 前端过滤(name + code) */
|
||||
const handleFilter = (query: string) => {
|
||||
if (!query) {
|
||||
filteredList.value = allList.value
|
||||
/** 是否显示清除图标 */
|
||||
const showClear = computed(() => {
|
||||
return props.clearable && !props.disabled && hovering.value && props.modelValue != null
|
||||
})
|
||||
|
||||
/** 后缀图标:悬停且有值时显示清除,否则显示搜索 */
|
||||
const suffixIcon = computed(() => {
|
||||
return showClear.value ? CircleClose : Search
|
||||
})
|
||||
|
||||
/** 根据 ID 单条查询工具信息(用于编辑回显) */
|
||||
const resolveItemById = async (id: number | undefined) => {
|
||||
if (id == null) {
|
||||
selectedItem.value = undefined
|
||||
return
|
||||
}
|
||||
const keyword = query.toLowerCase()
|
||||
filteredList.value = allList.value.filter(
|
||||
(item) =>
|
||||
item.name?.toLowerCase().includes(keyword) || item.code?.toLowerCase().includes(keyword)
|
||||
)
|
||||
if (selectedItem.value?.id === id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
selectedItem.value = await TmToolApi.getTool(id)
|
||||
} catch (e) {
|
||||
console.error('[TmToolSelect] resolveItemById failed:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/** 选中变化 */
|
||||
const handleChange = (val: number | undefined) => {
|
||||
const item = allList.value.find((o) => o.id === val)
|
||||
/** 监听 modelValue 变化,触发回显 */
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
resolveItemById(val)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// ==================== 点击交互 ====================
|
||||
|
||||
/** 点击组件:清除或打开弹窗 */
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
if (props.disabled) {
|
||||
return
|
||||
}
|
||||
// 点击清除图标:清空选中
|
||||
const target = e.target as HTMLElement
|
||||
if (showClear.value && target.closest('.el-input__suffix')) {
|
||||
e.stopPropagation()
|
||||
selectedItem.value = undefined
|
||||
emit('update:modelValue', undefined)
|
||||
emit('change', undefined)
|
||||
return
|
||||
}
|
||||
// 打开弹窗,传入当前选中 ID 用于预选高亮
|
||||
const selectedIds = props.modelValue != null ? [props.modelValue] : []
|
||||
dialogRef.value.open(selectedIds)
|
||||
}
|
||||
|
||||
/** 弹窗选中回调 */
|
||||
const handleSelected = (rows: TmToolVO[]) => {
|
||||
if (!rows || rows.length === 0) {
|
||||
return
|
||||
}
|
||||
const item = rows[0]
|
||||
selectedItem.value = item
|
||||
emit('update:modelValue', item.id)
|
||||
emit('change', item)
|
||||
}
|
||||
|
||||
/** 加载工具列表 */
|
||||
onMounted(async () => {
|
||||
allList.value = await TmToolApi.getToolSimpleList()
|
||||
filteredList.value = allList.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* :deep 用于穿透 el-input 内部元素的 cursor 样式,UnoCSS 无法直接处理组件内部 DOM */
|
||||
.is-select-clickable {
|
||||
:deep(.el-input__wrapper),
|
||||
:deep(.el-input__inner) {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.is-select-disabled {
|
||||
:deep(.el-input__wrapper),
|
||||
:deep(.el-input__inner) {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,314 @@
|
|||
<!--
|
||||
MES 工具弹窗选择器(支持单选/多选)
|
||||
-->
|
||||
<template>
|
||||
<Dialog title="工具选择" v-model="dialogVisible" width="75%">
|
||||
<ContentWrap>
|
||||
<el-form :inline="true" :model="queryParams" label-width="85px">
|
||||
<el-form-item label="工具编码">
|
||||
<el-input
|
||||
v-model="queryParams.code"
|
||||
placeholder="请输入工具编码"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-220px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="工具名称">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入工具名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-220px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="工具类型">
|
||||
<TmToolTypeSelect
|
||||
v-model="queryParams.toolTypeId"
|
||||
placeholder="请选择工具类型"
|
||||
class="!w-220px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌">
|
||||
<el-input
|
||||
v-model="queryParams.brand"
|
||||
placeholder="请输入品牌"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-220px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select
|
||||
v-model="queryParams.status"
|
||||
placeholder="请选择状态"
|
||||
clearable
|
||||
class="!w-220px"
|
||||
>
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.MES_TM_TOOL_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery">
|
||||
<Icon icon="ep:search" class="mr-5px" /> 搜索
|
||||
</el-button>
|
||||
<el-button @click="resetQuery">
|
||||
<Icon icon="ep:refresh" class="mr-5px" /> 重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
<ContentWrap>
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
:stripe="true"
|
||||
:show-overflow-tooltip="true"
|
||||
row-key="id"
|
||||
:highlight-current-row="!multiple"
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-click="handleRowClick"
|
||||
@row-dblclick="handleRowDblClick"
|
||||
>
|
||||
<!-- 多选:checkbox(reserve-selection 保证跨页勾选不丢失) -->
|
||||
<el-table-column
|
||||
v-if="multiple"
|
||||
type="selection"
|
||||
:reserve-selection="true"
|
||||
width="50"
|
||||
align="center"
|
||||
/>
|
||||
<!-- 单选:radio -->
|
||||
<el-table-column v-else width="50" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-radio
|
||||
v-model="selectedRadioId"
|
||||
:value="row.id"
|
||||
class="radio-no-label"
|
||||
@change="handleRadioChange(row)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="工具编码" align="center" prop="code" width="120" />
|
||||
<el-table-column label="工具名称" align="left" prop="name" min-width="120" />
|
||||
<el-table-column label="品牌" align="left" prop="brand" min-width="100" />
|
||||
<el-table-column label="型号规格" align="left" prop="spec" min-width="100" />
|
||||
<el-table-column label="工具类型" align="center" prop="toolTypeName" width="120" />
|
||||
<el-table-column label="库存数量" align="center" prop="quantity" width="100" />
|
||||
<el-table-column label="可用数量" align="center" prop="availableQuantity" width="100" />
|
||||
<el-table-column label="状态" align="center" prop="status" width="100">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.MES_TM_TOOL_STATUS" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="创建时间"
|
||||
align="center"
|
||||
prop="createTime"
|
||||
:formatter="dateFormatter"
|
||||
width="180"
|
||||
/>
|
||||
</el-table>
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
<template #footer>
|
||||
<el-button type="primary" @click="confirmSelect">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
|
||||
import TmToolTypeSelect from '../type/components/TmToolTypeSelect.vue'
|
||||
|
||||
defineOptions({ name: 'TmToolSelectDialog' })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
multiple?: boolean // true 多选(checkbox),false 单选(radio)
|
||||
}>(),
|
||||
{
|
||||
multiple: true
|
||||
}
|
||||
)
|
||||
|
||||
const message = useMessage()
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: TmToolVO[]]
|
||||
}>()
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗是否展示
|
||||
const loading = ref(false) // 列表加载中
|
||||
const list = ref<TmToolVO[]>([]) // 工具列表
|
||||
const total = ref(0) // 总条数
|
||||
|
||||
// ==================== 选中状态 ====================
|
||||
const tableRef = ref() // 表格 Ref
|
||||
const selectedRows = ref<TmToolVO[]>([]) // 多选模式:选中行
|
||||
const selectedRadioId = ref<number>() // 单选模式:选中 ID
|
||||
const currentRadioRow = ref<TmToolVO>() // 单选模式:选中行对象
|
||||
const preSelectedIds = ref<number[]>([]) // 打开弹窗时传入的已选 ID
|
||||
|
||||
/** 多选:checkbox 变化 */
|
||||
const handleSelectionChange = (rows: TmToolVO[]) => {
|
||||
if (props.multiple) {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
}
|
||||
|
||||
/** 单选:radio 变化 */
|
||||
const handleRadioChange = (row: TmToolVO) => {
|
||||
currentRadioRow.value = row
|
||||
}
|
||||
|
||||
/** 单击行:单选模式下点击整行即选中(降低操作成本),多选不处理(避免和 dblclick 冲突) */
|
||||
const handleRowClick = (row: TmToolVO) => {
|
||||
if (props.multiple) {
|
||||
return
|
||||
}
|
||||
selectedRadioId.value = row.id
|
||||
currentRadioRow.value = row
|
||||
}
|
||||
|
||||
/** 双击行:多选模式切换勾选,单选模式直接确认 */
|
||||
const handleRowDblClick = (row: TmToolVO) => {
|
||||
if (props.multiple) {
|
||||
tableRef.value?.toggleRowSelection(row)
|
||||
return
|
||||
}
|
||||
selectedRadioId.value = row.id
|
||||
currentRadioRow.value = row
|
||||
confirmSelect()
|
||||
}
|
||||
|
||||
// ==================== 查询 ====================
|
||||
const queryParams = reactive({
|
||||
pageNo: 1, // 页码
|
||||
pageSize: 10, // 每页条数
|
||||
code: undefined as string | undefined, // 工具编码
|
||||
name: undefined as string | undefined, // 工具名称
|
||||
toolTypeId: undefined as number | undefined, // 工具类型
|
||||
brand: undefined as string | undefined, // 品牌
|
||||
status: undefined as number | undefined // 状态
|
||||
})
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await TmToolApi.getToolPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
await nextTick()
|
||||
applyPreSelection()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 恢复预选状态(当前页可见范围内) */
|
||||
const applyPreSelection = () => {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return
|
||||
}
|
||||
if (props.multiple) {
|
||||
const table = tableRef.value
|
||||
if (!table) {
|
||||
return
|
||||
}
|
||||
list.value.forEach((row) => {
|
||||
if (preSelectedIds.value.includes(row.id)) {
|
||||
table.toggleRowSelection(row, true)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const match = list.value.find((row) => preSelectedIds.value.includes(row.id))
|
||||
if (match) {
|
||||
selectedRadioId.value = match.id
|
||||
currentRadioRow.value = match
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置查询条件 */
|
||||
const resetQuery = () => {
|
||||
queryParams.code = undefined
|
||||
queryParams.name = undefined
|
||||
queryParams.toolTypeId = undefined
|
||||
queryParams.brand = undefined
|
||||
queryParams.status = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 确认选择 */
|
||||
const confirmSelect = () => {
|
||||
if (props.multiple) {
|
||||
if (selectedRows.value.length === 0) {
|
||||
message.warning('请至少选择一条数据')
|
||||
return
|
||||
}
|
||||
emit('selected', selectedRows.value)
|
||||
} else {
|
||||
if (!currentRadioRow.value) {
|
||||
message.warning('请选择一条数据')
|
||||
return
|
||||
}
|
||||
emit('selected', [currentRadioRow.value])
|
||||
}
|
||||
dialogVisible.value = false
|
||||
}
|
||||
|
||||
// ==================== 打开弹窗 ====================
|
||||
|
||||
/** 打开弹窗,可传入已选 ID 用于预选高亮 */
|
||||
const open = async (selectedIds?: number[]) => {
|
||||
dialogVisible.value = true
|
||||
// 重置查询条件 + 页码
|
||||
queryParams.code = undefined
|
||||
queryParams.name = undefined
|
||||
queryParams.toolTypeId = undefined
|
||||
queryParams.brand = undefined
|
||||
queryParams.status = undefined
|
||||
queryParams.pageNo = 1
|
||||
// 清空上一次的选中状态
|
||||
selectedRows.value = []
|
||||
selectedRadioId.value = undefined
|
||||
currentRadioRow.value = undefined
|
||||
preSelectedIds.value = selectedIds ?? []
|
||||
// 多选模式清空跨页缓存的勾选
|
||||
await nextTick()
|
||||
tableRef.value?.clearSelection()
|
||||
await getList()
|
||||
}
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 隐藏 radio 的 label 文字,只保留圆圈 */
|
||||
.radio-no-label {
|
||||
:deep(.el-radio__label) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<!-- MES 工具类型选择器:纯下拉,前端过滤(支持 name、code) -->
|
||||
<template>
|
||||
<el-select
|
||||
v-model="selectValue"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:clearable="clearable"
|
||||
filterable
|
||||
:filter-method="handleFilter"
|
||||
class="!w-1/1"
|
||||
@change="handleChange"
|
||||
>
|
||||
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
||||
<div class="flex items-center gap-8px">
|
||||
<span>{{ item.name }}</span>
|
||||
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
||||
编号: {{ item.code }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
|
||||
|
||||
defineOptions({ name: 'TmToolTypeSelect' })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: number
|
||||
disabled?: boolean
|
||||
clearable?: boolean
|
||||
placeholder?: string
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
clearable: true,
|
||||
placeholder: '请选择工具类型'
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: number | undefined]
|
||||
change: [item: TmToolTypeVO | undefined]
|
||||
}>()
|
||||
|
||||
const allList = ref<TmToolTypeVO[]>([])
|
||||
const filteredList = ref<TmToolTypeVO[]>([])
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
/** 前端过滤(name + code) */
|
||||
const handleFilter = (query: string) => {
|
||||
if (!query) {
|
||||
filteredList.value = allList.value
|
||||
return
|
||||
}
|
||||
const keyword = query.toLowerCase()
|
||||
filteredList.value = allList.value.filter(
|
||||
(item) =>
|
||||
item.name?.toLowerCase().includes(keyword) || item.code?.toLowerCase().includes(keyword)
|
||||
)
|
||||
}
|
||||
|
||||
/** 选中变化 */
|
||||
const handleChange = (val: number | undefined) => {
|
||||
const item = allList.value.find((o) => o.id === val)
|
||||
emit('change', item)
|
||||
}
|
||||
|
||||
/** 加载工具类型列表 */
|
||||
onMounted(async () => {
|
||||
allList.value = await TmToolTypeApi.getToolTypeSimpleList()
|
||||
filteredList.value = allList.value
|
||||
})
|
||||
</script>
|
||||
|
|
@ -1,165 +1,167 @@
|
|||
<!-- MES 工具台账列表 -->
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="工具编码" prop="code">
|
||||
<el-input
|
||||
v-model="queryParams.code"
|
||||
placeholder="请输入工具编码"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="工具名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入工具名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="工具类型" prop="toolTypeId">
|
||||
<TmToolTypeSelect
|
||||
v-model="queryParams.toolTypeId"
|
||||
placeholder="请选择工具类型"
|
||||
clearable
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌" prop="brand">
|
||||
<el-input
|
||||
v-model="queryParams.brand"
|
||||
placeholder="请输入品牌"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="型号规格" prop="spec">
|
||||
<el-input
|
||||
v-model="queryParams.spec"
|
||||
placeholder="请输入型号规格"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.MES_TM_TOOL_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['mes:tm-tool:create']"
|
||||
<el-row :gutter="20">
|
||||
<!-- 左侧分类树 -->
|
||||
<el-col :span="4" :xs="24">
|
||||
<ContentWrap class="h-1/1">
|
||||
<TmToolTypeList @node-click="handleTypeNodeClick" />
|
||||
</ContentWrap>
|
||||
</el-col>
|
||||
<el-col :span="20" :xs="24">
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="100px"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
v-hasPermi="['mes:tm-tool:export']"
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
<el-form-item label="工具编码" prop="code">
|
||||
<el-input
|
||||
v-model="queryParams.code"
|
||||
placeholder="请输入工具编码"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="工具名称" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入工具名称"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌" prop="brand">
|
||||
<el-input
|
||||
v-model="queryParams.brand"
|
||||
placeholder="请输入品牌"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="型号规格" prop="spec">
|
||||
<el-input
|
||||
v-model="queryParams.spec"
|
||||
placeholder="请输入型号规格"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.MES_TM_TOOL_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['mes:tm-tool:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
v-hasPermi="['mes:tm-tool:export']"
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
<el-table-column label="工具编码" align="center" prop="code" width="120">
|
||||
<template #default="scope">
|
||||
<el-link type="primary" @click="openForm('detail', scope.row.id)">
|
||||
{{ scope.row.code }}
|
||||
</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="工具名称" align="center" prop="name" min-width="150" />
|
||||
<el-table-column label="品牌" align="center" prop="brand" width="100" />
|
||||
<el-table-column label="型号规格" align="center" prop="spec" width="120" />
|
||||
<el-table-column label="工具类型" align="center" prop="toolTypeName" width="120" />
|
||||
<el-table-column label="库存数量" align="center" prop="quantity" width="100" />
|
||||
<el-table-column label="可用数量" align="center" prop="availableQuantity" width="100" />
|
||||
<el-table-column label="保养维护类型" align="center" prop="maintenType" width="130">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.MES_TM_MAINTEN_TYPE" :value="scope.row.maintenType" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="下次保养" align="center" width="200">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.maintenType === MesMaintenTypeEnum.REGULAR">
|
||||
{{ scope.row.nextMaintenDate ? formatDate(scope.row.nextMaintenDate) : '-' }}
|
||||
</span>
|
||||
<span v-else-if="scope.row.maintenType === MesMaintenTypeEnum.USAGE">
|
||||
{{ scope.row.nextMaintenPeriod != null ? scope.row.nextMaintenPeriod + ' 次' : '-' }}
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" prop="status" width="100">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.MES_TM_TOOL_STATUS" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="创建时间"
|
||||
align="center"
|
||||
prop="createTime"
|
||||
:formatter="dateFormatter"
|
||||
width="180px"
|
||||
/>
|
||||
<el-table-column label="操作" align="center" width="130">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['mes:tm-tool:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-hasPermi="['mes:tm-tool:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
<el-table-column label="工具编码" align="center" prop="code" width="120">
|
||||
<template #default="scope">
|
||||
<el-link type="primary" @click="openForm('detail', scope.row.id)">
|
||||
{{ scope.row.code }}
|
||||
</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="工具名称" align="center" prop="name" min-width="150" />
|
||||
<el-table-column label="品牌" align="center" prop="brand" width="100" />
|
||||
<el-table-column label="型号规格" align="center" prop="spec" width="120" />
|
||||
<el-table-column label="工具类型" align="center" prop="toolTypeName" width="120" />
|
||||
<el-table-column label="库存数量" align="center" prop="quantity" width="100" />
|
||||
<el-table-column label="可用数量" align="center" prop="availableQuantity" width="100" />
|
||||
<el-table-column label="保养维护类型" align="center" prop="maintenType" width="130">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.MES_TM_MAINTEN_TYPE" :value="scope.row.maintenType" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="下次保养" align="center" width="200">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.maintenType === MesMaintenTypeEnum.REGULAR">
|
||||
{{ scope.row.nextMaintenDate ? formatDate(scope.row.nextMaintenDate) : '-' }}
|
||||
</span>
|
||||
<span v-else-if="scope.row.maintenType === MesMaintenTypeEnum.USAGE">
|
||||
{{ scope.row.nextMaintenPeriod != null ? scope.row.nextMaintenPeriod + ' 次' : '-' }}
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" prop="status" width="100">
|
||||
<template #default="scope">
|
||||
<dict-tag :type="DICT_TYPE.MES_TM_TOOL_STATUS" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="创建时间"
|
||||
align="center"
|
||||
prop="createTime"
|
||||
:formatter="dateFormatter"
|
||||
width="180px"
|
||||
/>
|
||||
<el-table-column label="操作" align="center" width="130">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['mes:tm-tool:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-hasPermi="['mes:tm-tool:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<ToolForm ref="formRef" @success="getList" />
|
||||
|
|
@ -169,7 +171,7 @@
|
|||
import { dateFormatter, formatDate } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
|
||||
import TmToolTypeSelect from './components/TmToolTypeSelect.vue'
|
||||
import TmToolTypeList from './type/components/TmToolTypeList.vue'
|
||||
import ToolForm from './ToolForm.vue'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { MesMaintenTypeEnum } from '@/views/mes/utils/constants'
|
||||
|
|
@ -216,6 +218,13 @@ const handleQuery = () => {
|
|||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value.resetFields()
|
||||
queryParams.toolTypeId = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 处理分类树节点点击 */
|
||||
const handleTypeNodeClick = (row: any) => {
|
||||
queryParams.toolTypeId = row?.id
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
<!--
|
||||
MES 工具类型列表面板(左侧筛选)
|
||||
|
||||
功能:加载工具类型列表 + 关键字过滤 + 点击节点通知父组件
|
||||
用法:<TmToolTypeList @node-click="handleTypeClick" />
|
||||
说明:
|
||||
- 工具类型为扁平列表(非树型),使用 el-tree 单层展示保持与其他模块一致的交互体验
|
||||
- 组件 mount 后自动加载数据,也可通过 ref 调用 loadList() 手动刷新
|
||||
- 支持 toggle:点击已选中节点会取消选中(emit undefined)
|
||||
Events:
|
||||
nodeClick(data: TmToolTypeVO | undefined) — 点击节点时触发;取消选中时为 undefined
|
||||
Expose:
|
||||
loadList() — 手动刷新类型列表
|
||||
clearCurrent() — 清除当前选中节点高亮
|
||||
reset() — 重置整个组件状态(清高亮 + 清搜索词)
|
||||
-->
|
||||
<template>
|
||||
<el-input
|
||||
v-model="filterText"
|
||||
placeholder="搜索分类"
|
||||
clearable
|
||||
class="mb-12px"
|
||||
:prefix-icon="iconSearch"
|
||||
/>
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:data="listData"
|
||||
:props="treeProps"
|
||||
:expand-on-click-node="false"
|
||||
:filter-node-method="filterNode"
|
||||
default-expand-all
|
||||
highlight-current
|
||||
node-key="id"
|
||||
@node-click="handleNodeClick"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
|
||||
import { Search as iconSearch } from '@element-plus/icons-vue'
|
||||
|
||||
defineOptions({ name: 'TmToolTypeList' })
|
||||
|
||||
const emit = defineEmits<{
|
||||
nodeClick: [data: TmToolTypeVO | undefined]
|
||||
}>()
|
||||
|
||||
const treeRef = ref() // 树组件 Ref
|
||||
const filterText = ref('') // 搜索关键字
|
||||
const listData = ref<TmToolTypeVO[]>([]) // 列表数据(扁平,每项是独立根节点)
|
||||
const treeProps = { children: 'children', label: 'name' } // 属性映射
|
||||
let currentNodeId: number | undefined // 当前选中节点 ID(用于 toggle 判断)
|
||||
|
||||
/** 过滤节点(按名称匹配) */
|
||||
const filterNode = (value: string, data: TmToolTypeVO) => {
|
||||
if (!value) {
|
||||
return true
|
||||
}
|
||||
return data.name?.includes(value)
|
||||
}
|
||||
|
||||
/** 监听搜索关键字变化,触发过滤 */
|
||||
watch(filterText, (val) => {
|
||||
treeRef.value?.filter(val)
|
||||
})
|
||||
|
||||
/** 点击节点:支持 toggle(再次点击同一节点取消选中) */
|
||||
const handleNodeClick = (data: TmToolTypeVO) => {
|
||||
if (currentNodeId === data.id) {
|
||||
// 再次点击同一节点:取消选中
|
||||
treeRef.value?.setCurrentKey(undefined)
|
||||
currentNodeId = undefined
|
||||
emit('nodeClick', undefined)
|
||||
} else {
|
||||
// 选中新节点
|
||||
currentNodeId = data.id
|
||||
emit('nodeClick', data)
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载类型列表数据 */
|
||||
const loadList = async () => {
|
||||
// 扁平列表直接赋值(el-tree 每条记录作为独立根节点展示)
|
||||
listData.value = await TmToolTypeApi.getToolTypeSimpleList()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadList()
|
||||
})
|
||||
|
||||
/** 清除当前选中节点高亮 */
|
||||
const clearCurrent = () => {
|
||||
treeRef.value?.setCurrentKey(undefined)
|
||||
currentNodeId = undefined
|
||||
}
|
||||
|
||||
/** 重置整个组件状态(清高亮 + 清搜索词) */
|
||||
const reset = () => {
|
||||
clearCurrent()
|
||||
filterText.value = ''
|
||||
}
|
||||
|
||||
defineExpose({ loadList, clearCurrent, reset })
|
||||
</script>
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
<!-- MES 工具类型选择器:纯下拉,前端过滤(支持 name、code),悬停 tooltip 展示详情 -->
|
||||
<template>
|
||||
<el-tooltip :disabled="!selectedItem" placement="top" :show-after="500">
|
||||
<template #content>
|
||||
<div v-if="selectedItem" class="leading-6">
|
||||
<div>编码:{{ selectedItem.code || '-' }}</div>
|
||||
<div>名称:{{ selectedItem.name || '-' }}</div>
|
||||
<div>编码管理:{{ selectedItem.codeFlag ? '是' : '否' }}</div>
|
||||
<div>备注:{{ selectedItem.remark || '-' }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-select
|
||||
v-model="selectValue"
|
||||
:placeholder="placeholder"
|
||||
:disabled="disabled"
|
||||
:clearable="clearable"
|
||||
filterable
|
||||
:filter-method="handleFilter"
|
||||
class="!w-1/1"
|
||||
@change="handleChange"
|
||||
>
|
||||
<el-option v-for="item in filteredList" :key="item.id" :label="item.name" :value="item.id">
|
||||
<div class="flex items-center gap-8px">
|
||||
<span>{{ item.name }}</span>
|
||||
<el-tag v-if="item.code" size="small" type="info" class="ml-4px">
|
||||
编号: {{ item.code }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
|
||||
|
||||
defineOptions({ name: 'TmToolTypeSelect' })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: number
|
||||
disabled?: boolean
|
||||
clearable?: boolean
|
||||
placeholder?: string
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
clearable: true,
|
||||
placeholder: '请选择工具类型'
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: number | undefined]
|
||||
change: [item: TmToolTypeVO | undefined]
|
||||
}>()
|
||||
|
||||
const allList = ref<TmToolTypeVO[]>([])
|
||||
const filteredList = ref<TmToolTypeVO[]>([])
|
||||
const selectedItem = ref<TmToolTypeVO | undefined>() // 当前选中的类型对象(用于 tooltip 展示)
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
/** 前端过滤(name + code) */
|
||||
const handleFilter = (query: string) => {
|
||||
if (!query) {
|
||||
filteredList.value = allList.value
|
||||
return
|
||||
}
|
||||
const keyword = query.toLowerCase()
|
||||
filteredList.value = allList.value.filter(
|
||||
(item) =>
|
||||
item.name?.toLowerCase().includes(keyword) || item.code?.toLowerCase().includes(keyword)
|
||||
)
|
||||
}
|
||||
|
||||
/** 选中变化 */
|
||||
const handleChange = (val: number | undefined) => {
|
||||
const item = allList.value.find((o) => o.id === val)
|
||||
selectedItem.value = item
|
||||
emit('change', item)
|
||||
}
|
||||
|
||||
/** 根据 modelValue 同步 selectedItem(用于编辑回显) */
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
if (val == null) {
|
||||
selectedItem.value = undefined
|
||||
return
|
||||
}
|
||||
if (selectedItem.value?.id !== val && allList.value.length > 0) {
|
||||
selectedItem.value = allList.value.find((o) => o.id === val)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** 加载工具类型列表 */
|
||||
onMounted(async () => {
|
||||
allList.value = await TmToolTypeApi.getToolTypeSimpleList()
|
||||
filteredList.value = allList.value
|
||||
// 列表加载完成后,回显 selectedItem
|
||||
if (props.modelValue != null) {
|
||||
selectedItem.value = allList.value.find((o) => o.id === props.modelValue)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue