♻️ refactor(mes): 移除无用的到货通知单相关接口和组件
parent
6e6e65a22c
commit
bf586e57b8
|
|
@ -43,12 +43,5 @@ export const WmArrivalNoticeLineApi = {
|
|||
// 删除到货通知单行
|
||||
deleteArrivalNoticeLine: async (id: number) => {
|
||||
return await request.delete({ url: '/mes/wm/arrival-notice-line/delete?id=' + id })
|
||||
},
|
||||
|
||||
// 查询到货通知单行列表(按通知单编号)
|
||||
getArrivalNoticeLineListByNoticeId: async (noticeId: number) => {
|
||||
return await request.get({
|
||||
url: '/mes/wm/arrival-notice-line/list-by-notice-id?noticeId=' + noticeId
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +1,71 @@
|
|||
<!-- MES 到货通知单行选择器:纯下拉,前端过滤(支持 itemCode、itemName),支持按到货通知单筛选 -->
|
||||
<!--
|
||||
MES 到货通知单行选择器:只读输入框 + 点击弹窗选择
|
||||
|
||||
交互:显示为只读 el-input,点击打开弹窗(单选模式)进行选择
|
||||
Props:
|
||||
modelValue — 绑定的到货通知单行 ID(v-model)
|
||||
noticeId — 到货通知单编号(透传给 Dialog,限制可选范围)
|
||||
disabled — 是否禁用
|
||||
clearable — 是否允许清空(鼠标悬停时显示清除图标)
|
||||
placeholder — 占位文字
|
||||
Events:
|
||||
update:modelValue — v-model 更新
|
||||
change(item) — 选中行变化时触发,传递完整 WmArrivalNoticeLineVO(清空时为 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.itemCode} - ${item.itemName}`"
|
||||
:value="item.id"
|
||||
>
|
||||
<div class="flex items-center gap-8px">
|
||||
<span>{{ item.itemCode }}</span>
|
||||
<span class="text-gray-500">{{ item.itemName }}</span>
|
||||
</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.itemCode }}</div>
|
||||
<div>物料名称:{{ selectedItem.itemName }}</div>
|
||||
<div>规格型号:{{ selectedItem.specification || '-' }}</div>
|
||||
<div>到货数量:{{ selectedItem.arrivalQuantity ?? '-' }}</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 -->
|
||||
<WmArrivalNoticeLineSelectDialog
|
||||
ref="dialogRef"
|
||||
:notice-id="noticeId"
|
||||
@selected="handleSelected"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { WmArrivalNoticeLineApi, WmArrivalNoticeLineVO } from '@/api/mes/wm/arrivalnotice/line'
|
||||
import { Search, CircleClose } from '@element-plus/icons-vue'
|
||||
import WmArrivalNoticeLineSelectDialog from './WmArrivalNoticeLineSelectDialog.vue'
|
||||
|
||||
defineOptions({ name: 'WmArrivalNoticeLineSelect' })
|
||||
// 组件有两个根节点(div + Dialog),Vue 不会自动继承 attrs;
|
||||
// 手动透传到外层 div,确保父组件传入的 class / style 等生效
|
||||
const attrs = useAttrs()
|
||||
|
||||
defineOptions({ name: 'WmArrivalNoticeLineSelect', inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: number
|
||||
noticeId?: number
|
||||
disabled?: boolean
|
||||
clearable?: boolean
|
||||
placeholder?: string
|
||||
modelValue?: number // 绑定的到货通知单行 ID
|
||||
noticeId?: number // 到货通知单编号
|
||||
disabled?: boolean // 是否禁用
|
||||
clearable?: boolean // 是否允许清空
|
||||
placeholder?: string // 占位文字
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
|
|
@ -49,56 +79,115 @@ const emit = defineEmits<{
|
|||
change: [item: WmArrivalNoticeLineVO | undefined]
|
||||
}>()
|
||||
|
||||
const allList = ref<WmArrivalNoticeLineVO[]>([])
|
||||
const filteredList = ref<WmArrivalNoticeLineVO[]>([])
|
||||
const dialogRef = ref() // 弹窗 Ref
|
||||
const hovering = ref(false) // 鼠标是否悬停
|
||||
|
||||
const selectValue = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
// ==================== 名称回显 ====================
|
||||
const selectedItem = ref<WmArrivalNoticeLineVO | undefined>() // 当前选中的行对象
|
||||
|
||||
/** 输入框显示文本:展示物料编码 - 物料名称 */
|
||||
const displayLabel = computed(() => {
|
||||
if (!selectedItem.value) {
|
||||
return ''
|
||||
}
|
||||
return `${selectedItem.value.itemCode} - ${selectedItem.value.itemName}`
|
||||
})
|
||||
|
||||
/** 前端过滤(itemCode + itemName) */
|
||||
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.itemCode?.toLowerCase().includes(keyword) ||
|
||||
item.itemName?.toLowerCase().includes(keyword)
|
||||
)
|
||||
}
|
||||
|
||||
/** 选中变化 */
|
||||
const handleChange = (val: number | undefined) => {
|
||||
const item = allList.value.find((o) => o.id === val)
|
||||
emit('change', item)
|
||||
}
|
||||
|
||||
/** 加载列表 */
|
||||
const loadList = async () => {
|
||||
if (!props.noticeId) {
|
||||
allList.value = []
|
||||
filteredList.value = []
|
||||
if (selectedItem.value?.id === id) {
|
||||
return
|
||||
}
|
||||
allList.value = await WmArrivalNoticeLineApi.getArrivalNoticeLineListByNoticeId(props.noticeId)
|
||||
filteredList.value = allList.value
|
||||
try {
|
||||
selectedItem.value = await WmArrivalNoticeLineApi.getArrivalNoticeLine(id)
|
||||
} catch (e) {
|
||||
console.error('[WmArrivalNoticeLineSelect] resolveItemById failed:', e)
|
||||
}
|
||||
}
|
||||
|
||||
/** 监听 noticeId 变化,重新加载列表 */
|
||||
/** 监听 modelValue 变化,触发回显 */
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
resolveItemById(val)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
/** 监听 noticeId 变化,清空选中 */
|
||||
watch(
|
||||
() => props.noticeId,
|
||||
async () => {
|
||||
selectValue.value = undefined
|
||||
await loadList()
|
||||
() => {
|
||||
selectedItem.value = undefined
|
||||
emit('update:modelValue', undefined)
|
||||
emit('change', undefined)
|
||||
}
|
||||
)
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
await loadList()
|
||||
})
|
||||
// ==================== 点击交互 ====================
|
||||
|
||||
/** 点击组件:清除或打开弹窗 */
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
if (props.disabled) {
|
||||
return
|
||||
}
|
||||
// noticeId 为空时,不允许打开弹窗
|
||||
if (!props.noticeId) {
|
||||
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: WmArrivalNoticeLineVO[]) => {
|
||||
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>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,183 @@
|
|||
<!--
|
||||
MES 到货通知单行弹窗选择器(单选模式)
|
||||
|
||||
对齐 KTG noticeSelect/lineSingle.vue:
|
||||
展示字段:物料编码、物料名称、规格型号、单位、到货数量、是否检验、合格数量、检验单号、备注
|
||||
|
||||
Props:
|
||||
noticeId — 到货通知单编号(必传,按此筛选行数据)
|
||||
Events:
|
||||
selected(rows: WmArrivalNoticeLineVO[]) — 确认选择后触发,数组长度为 1
|
||||
Expose:
|
||||
open(selectedIds?: number[]) — 打开弹窗,可传入已选 ID 用于预选高亮
|
||||
-->
|
||||
<template>
|
||||
<Dialog title="到货通知单行选择" v-model="dialogVisible" width="70%">
|
||||
<ContentWrap>
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
:stripe="true"
|
||||
:show-overflow-tooltip="true"
|
||||
row-key="id"
|
||||
highlight-current-row
|
||||
@row-click="handleRowClick"
|
||||
@row-dblclick="handleRowDblClick"
|
||||
>
|
||||
<!-- 单选:radio -->
|
||||
<el-table-column 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="itemCode" width="120" />
|
||||
<el-table-column label="物料名称" align="center" prop="itemName" min-width="150" />
|
||||
<el-table-column label="规格型号" align="center" prop="specification" min-width="120" />
|
||||
<el-table-column label="单位" align="center" prop="unitMeasureName" width="80" />
|
||||
<el-table-column label="到货数量" align="center" prop="arrivalQuantity" width="100" />
|
||||
<el-table-column label="是否检验" align="center" prop="iqcCheckFlag" width="90">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.iqcCheckFlag ? 'success' : 'info'" size="small">
|
||||
{{ scope.row.iqcCheckFlag ? '是' : '否' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="合格数量" align="center" prop="qualifiedQuantity" width="100" />
|
||||
<el-table-column label="检验单号" align="center" prop="iqcCode" width="140" />
|
||||
<el-table-column label="备注" align="center" prop="remark" min-width="120" />
|
||||
</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 { WmArrivalNoticeLineApi, WmArrivalNoticeLineVO } from '@/api/mes/wm/arrivalnotice/line'
|
||||
|
||||
defineOptions({ name: 'WmArrivalNoticeLineSelectDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
noticeId?: number // 到货通知单编号
|
||||
}>()
|
||||
|
||||
const message = useMessage()
|
||||
const emit = defineEmits<{
|
||||
selected: [rows: WmArrivalNoticeLineVO[]]
|
||||
}>()
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗是否展示
|
||||
const loading = ref(false) // 列表加载中
|
||||
const list = ref<WmArrivalNoticeLineVO[]>([]) // 列表
|
||||
const total = ref(0) // 总条数
|
||||
|
||||
// ==================== 选中状态 ====================
|
||||
const tableRef = ref() // 表格 Ref
|
||||
const selectedRadioId = ref<number>() // 单选模式:选中 ID
|
||||
const currentRadioRow = ref<WmArrivalNoticeLineVO>() // 单选模式:选中行对象
|
||||
const preSelectedIds = ref<number[]>([]) // 打开弹窗时传入的已选 ID
|
||||
|
||||
/** 单选:radio 变化 */
|
||||
const handleRadioChange = (row: WmArrivalNoticeLineVO) => {
|
||||
currentRadioRow.value = row
|
||||
}
|
||||
|
||||
/** 单击行:点击整行即选中 */
|
||||
const handleRowClick = (row: WmArrivalNoticeLineVO) => {
|
||||
selectedRadioId.value = row.id
|
||||
currentRadioRow.value = row
|
||||
}
|
||||
|
||||
/** 双击行:直接确认 */
|
||||
const handleRowDblClick = (row: WmArrivalNoticeLineVO) => {
|
||||
selectedRadioId.value = row.id
|
||||
currentRadioRow.value = row
|
||||
confirmSelect()
|
||||
}
|
||||
|
||||
// ==================== 查询 ====================
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
noticeId: undefined as number | undefined
|
||||
})
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
if (!props.noticeId) {
|
||||
list.value = []
|
||||
total.value = 0
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
queryParams.noticeId = props.noticeId
|
||||
const data = await WmArrivalNoticeLineApi.getArrivalNoticeLinePage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
await nextTick()
|
||||
applyPreSelection()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 恢复预选状态(当前页可见范围内) */
|
||||
const applyPreSelection = () => {
|
||||
if (preSelectedIds.value.length === 0) {
|
||||
return
|
||||
}
|
||||
const match = list.value.find((row) => preSelectedIds.value.includes(row.id))
|
||||
if (match) {
|
||||
selectedRadioId.value = match.id
|
||||
currentRadioRow.value = match
|
||||
}
|
||||
}
|
||||
|
||||
/** 确认选择 */
|
||||
const confirmSelect = () => {
|
||||
if (!currentRadioRow.value) {
|
||||
message.warning('请选择一条数据')
|
||||
return
|
||||
}
|
||||
emit('selected', [currentRadioRow.value])
|
||||
dialogVisible.value = false
|
||||
}
|
||||
|
||||
// ==================== 打开弹窗 ====================
|
||||
|
||||
/** 打开弹窗,可传入已选 ID 用于预选高亮 */
|
||||
const open = async (selectedIds?: number[]) => {
|
||||
dialogVisible.value = true
|
||||
queryParams.pageNo = 1
|
||||
// 清空上一次的选中状态
|
||||
selectedRadioId.value = undefined
|
||||
currentRadioRow.value = undefined
|
||||
preSelectedIds.value = selectedIds ?? []
|
||||
await getList()
|
||||
}
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 隐藏 radio 的 label 文字,只保留圆圈 */
|
||||
.radio-no-label {
|
||||
:deep(.el-radio__label) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue