♻️ refactor(mes): 移除未使用的盘点方案相关代码

清理了不再使用的盘点方案列表获取方法和相关的 API 接口,简化了代码结构,提高了可维护性。
pull/871/MERGE
YunaiV 2026-04-07 09:36:28 +08:00
parent 739725d9f8
commit ee1a7b9003
3 changed files with 464 additions and 40 deletions

View File

@ -29,10 +29,6 @@ export const StockTakingPlanApi = {
return await request.get({ url: '/mes/wm/stocktaking-plan/get?id=' + id })
},
getEnabledConfirmedStockTakingPlanSimpleList: async () => {
return await request.get({ url: '/mes/wm/stocktaking-plan/simple-list' })
},
createStockTakingPlan: async (data: StockTakingPlanVO) => {
return await request.post({ url: '/mes/wm/stocktaking-plan/create', data })
},

View File

@ -1,37 +1,73 @@
<!-- MES 盘点方案选择器纯下拉展示已启用方案支持 codename -->
<!--
MES 盘点方案选择器只读输入框 + 点击弹窗选择
交互显示为只读 el-input点击打开弹窗单选模式进行选择
Props:
modelValue 绑定的盘点方案 IDv-model
disabled 是否禁用
clearable 是否允许清空鼠标悬停时显示清除图标
placeholder 占位文字
Events:
update:modelValue v-model 更新
change(item) 选中盘点方案变化时触发传递完整 StockTakingPlanVO清空时为 undefined
-->
<template>
<el-select
v-model="selectValue"
:placeholder="placeholder"
:disabled="disabled"
:clearable="clearable"
filterable
class="!w-full"
@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="plan in planList"
:key="plan.id"
:label="plan.name || plan.code"
:value="plan.id"
>
<span>{{ plan.code }}</span>
<span class="ml-8px text-[var(--el-text-color-secondary)]">{{ plan.name }}</span>
</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>
盘点类型{{
selectedItem.type != null
? getDictLabel(DICT_TYPE.MES_WM_STOCK_TAKING_TYPE, selectedItem.type)
: '-'
}}
</div>
<div>是否盲盘{{ selectedItem.blindFlag ? '是' : '否' }}</div>
<div>是否冻结库存{{ selectedItem.frozen ? '是' : '否' }}</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 -->
<StockTakingPlanSelectDialog ref="dialogRef" :multiple="false" @selected="handleSelected" />
</template>
<script setup lang="ts">
import { DICT_TYPE, getDictLabel } from '@/utils/dict'
import { Search, CircleClose } from '@element-plus/icons-vue'
import { StockTakingPlanApi, type StockTakingPlanVO } from '@/api/mes/wm/stocktaking/plan/index'
import StockTakingPlanSelectDialog from './StockTakingPlanSelectDialog.vue'
defineOptions({ name: 'StockTakingPlanSelect' })
// div + DialogVue attrs
// div class / style
const attrs = useAttrs()
defineOptions({ name: 'StockTakingPlanSelect', 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,21 +81,98 @@ const emit = defineEmits<{
change: [item: StockTakingPlanVO | undefined]
}>()
const planList = ref<StockTakingPlanVO[]>([])
const dialogRef = ref() // Ref
const hovering = ref(false) //
const selectValue = computed({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val)
// ==================== ====================
const selectedItem = ref<StockTakingPlanVO | undefined>() //
/** 输入框显示文本:只展示方案名称,保持简洁 */
const displayLabel = computed(() => {
return selectedItem.value?.name ?? ''
})
/** 选中变化 */
const handleChange = (val: number | undefined) => {
const item = planList.value.find((o) => o.id === val)
emit('change', item)
/** 是否显示清除图标 */
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
}
if (selectedItem.value?.id === id) {
return
}
try {
selectedItem.value = await StockTakingPlanApi.getStockTakingPlan(id)
} catch (e) {
console.error('[StockTakingPlanSelect] resolveItemById failed:', e)
}
}
/** 加载盘点方案列表 */
onMounted(async () => {
planList.value = await StockTakingPlanApi.getEnabledConfirmedStockTakingPlanSimpleList()
})
/** 监听 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: StockTakingPlanVO[]) => {
if (!rows || rows.length === 0) {
return
}
const item = rows[0]
selectedItem.value = item
emit('update:modelValue', item.id)
emit('change', item)
}
</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>

View File

@ -0,0 +1,315 @@
<!--
MES 盘点方案弹窗选择器支持单选/多选
Props:
multiple true 多选checkboxfalse 单选radio默认 true
Events:
selected(rows: StockTakingPlanVO[]) 确认选择后触发单选时数组长度为 1
Expose:
open(selectedIds?: number[]) 打开弹窗可传入已选 ID 用于预选高亮
-->
<template>
<Dialog title="盘点方案选择" v-model="dialogVisible" width="70%">
<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="盘点类型">
<el-select
v-model="queryParams.type"
placeholder="请选择盘点类型"
clearable
class="!w-220px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.MES_WM_STOCK_TAKING_TYPE)"
: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>
<!-- 数据表格单选 radio / 多选 checkbox 统一在一个 table -->
<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"
>
<!-- 多选checkboxreserve-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="200" />
<el-table-column label="方案名称" align="left" prop="name" min-width="150" />
<el-table-column label="盘点类型" align="center" prop="type" width="120">
<template #default="scope">
<dict-tag :type="DICT_TYPE.MES_WM_STOCK_TAKING_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="开始时间" align="center" prop="startTime" width="180">
<template #default="scope">
<span>{{ formatDate(scope.row.startTime, 'YYYY-MM-DD HH:mm:ss') }}</span>
</template>
</el-table-column>
<el-table-column label="结束时间" align="center" prop="endTime" width="180">
<template #default="scope">
<span>{{ formatDate(scope.row.endTime, 'YYYY-MM-DD HH:mm:ss') }}</span>
</template>
</el-table-column>
<el-table-column label="是否盲盘" align="center" prop="blindFlag" width="100">
<template #default="scope">
<el-tag :type="scope.row.blindFlag ? 'success' : 'info'" size="small">
{{ scope.row.blindFlag ? '是' : '否' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="是否库存冻结" align="center" prop="frozen" width="120">
<template #default="scope">
<el-tag :type="scope.row.frozen ? 'success' : 'info'" size="small">
{{ scope.row.frozen ? '是' : '否' }}
</el-tag>
</template>
</el-table-column>
</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 { CommonStatusEnum } from '@/utils/constants'
import { formatDate } from '@/utils/formatTime'
import { StockTakingPlanApi, type StockTakingPlanVO } from '@/api/mes/wm/stocktaking/plan/index'
defineOptions({ name: 'StockTakingPlanSelectDialog' })
const props = withDefaults(
defineProps<{
multiple?: boolean // true checkboxfalse radio
}>(),
{
multiple: true
}
)
const message = useMessage()
const emit = defineEmits<{
selected: [rows: StockTakingPlanVO[]]
}>()
const dialogVisible = ref(false) //
const loading = ref(false) //
const list = ref<StockTakingPlanVO[]>([]) //
const total = ref(0) //
// ==================== ====================
const tableRef = ref() // Ref
const selectedRows = ref<StockTakingPlanVO[]>([]) //
const selectedRadioId = ref<number>() // ID
const currentRadioRow = ref<StockTakingPlanVO>() //
const preSelectedIds = ref<number[]>([]) // ID
/** 多选checkbox 变化 */
const handleSelectionChange = (rows: StockTakingPlanVO[]) => {
if (props.multiple) {
selectedRows.value = rows
}
}
/** 单选radio 变化 */
const handleRadioChange = (row: StockTakingPlanVO) => {
currentRadioRow.value = row
}
/** 单击行:单选模式下点击整行即选中(降低操作成本),多选不处理(避免和 dblclick 冲突) */
const handleRowClick = (row: StockTakingPlanVO) => {
if (props.multiple) {
return
}
selectedRadioId.value = row.id
currentRadioRow.value = row
}
/** 双击行:多选模式切换勾选,单选模式直接确认 */
const handleRowDblClick = (row: StockTakingPlanVO) => {
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, //
type: undefined as number | undefined, //
status: CommonStatusEnum.ENABLE as number | undefined //
})
/** 查询盘点方案列表 */
const getList = async () => {
loading.value = true
try {
const data = await StockTakingPlanApi.getStockTakingPlanPage(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.type = undefined
queryParams.status = CommonStatusEnum.ENABLE
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.type = undefined
queryParams.status = CommonStatusEnum.ENABLE
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>