- 待审核订单增加「含未绑定」开关(默认只显示已绑定),列表与导出条件保持一致 - 店铺商品增加「只看有订单未绑定」筛选与「待处理订单」列;绑定弹窗改为左侧页签 + 右侧可搜索分页列表 - 订单切换仓库改为弹窗选择,新增通用 RecordPickerDialog 组件 - 订单与店铺商品表格改为表体内部滚动,筛选栏与分页固定 - 手工建单必须选择非平台店铺;平台订单编辑时店铺不可修改 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
149 lines
3.9 KiB
Vue
149 lines
3.9 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 通用「列表选择」弹窗
|
||
*
|
||
* 用于批量操作需要指定目标(仓库 / 店铺)的场景:
|
||
* 打开后展示可选项列表(支持关键词过滤),选中一行后确认返回该行数据,
|
||
* 避免之前用输入框让用户手输名称/编码的交互。
|
||
*/
|
||
import { computed, ref, watch } from 'vue'
|
||
import DataTable from '@/components/DataTable.vue'
|
||
|
||
export interface PickerColumn {
|
||
prop: string
|
||
label: string
|
||
width?: number | string
|
||
minWidth?: number | string
|
||
}
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
modelValue: boolean
|
||
title: string
|
||
/** 可选项列表(任意对象,按 columns 展示) */
|
||
options: Array<Record<string, unknown>>
|
||
columns: PickerColumn[]
|
||
/** 行唯一标识字段,默认 id */
|
||
valueKey?: string
|
||
/** 关键词过滤用字段,匹配任一即可 */
|
||
searchProps?: string[]
|
||
/** 当前已选中的值(打开时默认高亮) */
|
||
current?: string | number | null
|
||
confirmText?: string
|
||
emptyText?: string
|
||
}>(),
|
||
{
|
||
valueKey: 'id',
|
||
searchProps: () => [],
|
||
current: null,
|
||
confirmText: '确定',
|
||
emptyText: '暂无可选项',
|
||
},
|
||
)
|
||
|
||
const emit = defineEmits<{
|
||
'update:modelValue': [value: boolean]
|
||
confirm: [row: Record<string, unknown>]
|
||
}>()
|
||
|
||
const keyword = ref('')
|
||
const selected = ref<string | number | null>(null)
|
||
|
||
/** 关键词过滤后的列表 */
|
||
const filtered = computed(() => {
|
||
const text = keyword.value.trim().toLowerCase()
|
||
if (!text) return props.options
|
||
const keys = props.searchProps.length ? props.searchProps : [ props.valueKey ]
|
||
return props.options.filter(row =>
|
||
keys.some(key => String(row[key] ?? '').toLowerCase().includes(text)),
|
||
)
|
||
})
|
||
|
||
watch(
|
||
() => props.modelValue,
|
||
(open) => {
|
||
if (!open) return
|
||
keyword.value = ''
|
||
selected.value = props.current ?? null
|
||
},
|
||
)
|
||
|
||
function close() {
|
||
emit('update:modelValue', false)
|
||
}
|
||
|
||
function onRowClick(row: Record<string, unknown>) {
|
||
selected.value = row[props.valueKey] as string | number
|
||
}
|
||
|
||
function confirm() {
|
||
if (selected.value == null) return
|
||
const hit = props.options.find(row => row[props.valueKey] === selected.value)
|
||
if (!hit) return
|
||
emit('confirm', hit)
|
||
close()
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<el-dialog
|
||
:model-value="modelValue"
|
||
:title="title"
|
||
width="640px"
|
||
top="8vh"
|
||
@update:model-value="emit('update:modelValue', $event)"
|
||
>
|
||
<div class="picker-toolbar">
|
||
<el-input v-model="keyword" placeholder="输入关键词过滤" clearable style="width: 260px" />
|
||
<span class="picker-tip">点击一行选择,或双击直接确认</span>
|
||
</div>
|
||
<DataTable
|
||
:data="filtered"
|
||
height="320"
|
||
highlight-current-row
|
||
@row-click="onRowClick"
|
||
@row-dblclick="(_row: Record<string, unknown>) => { onRowClick(_row); confirm() }"
|
||
>
|
||
<el-table-column label="" width="48" align="center">
|
||
<template #default="{ row }">
|
||
<el-radio :model-value="selected" :value="row[valueKey]" class="picker-radio">
|
||
<span />
|
||
</el-radio>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column
|
||
v-for="col in columns"
|
||
:key="col.prop"
|
||
:prop="col.prop"
|
||
:label="col.label"
|
||
:width="col.width"
|
||
:min-width="col.minWidth"
|
||
show-overflow-tooltip
|
||
/>
|
||
<template #empty>
|
||
<span>{{ emptyText }}</span>
|
||
</template>
|
||
</DataTable>
|
||
<template #footer>
|
||
<el-button @click="close">取消</el-button>
|
||
<el-button type="primary" :disabled="selected == null" @click="confirm">{{ confirmText }}</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.picker-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 10px;
|
||
}
|
||
.picker-tip {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
.picker-radio :deep(.el-radio__label) {
|
||
display: none;
|
||
}
|
||
</style>
|