liufumingren 809d1e9feb feat(shop-product): 店铺商品列表展示平台商品图片,支持点击大图预览
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-06 19:34:38 +08:00

1028 lines
34 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { QuestionFilled } from '@element-plus/icons-vue'
import {
getShopProducts,
bindShopProduct,
batchBindShopProducts,
BIND_TYPES,
type ShopProductItem,
} from '@/api/shopProduct'
import { pullExternalPrintShopProducts } from '@/api/externalPrintAccount'
import { getShops, type ShopItem } from '@/api/shop'
import { getProducts, type ProductItem } from '@/api/product'
import { getComboProducts, type ComboProductItem } from '@/api/comboProduct'
import DataTable from '@/components/DataTable.vue'
import ExportButton from '@/components/ExportButton.vue'
import ListPager from '@/components/ListPager.vue'
import OperationLogPanel from '@/components/OperationLogPanel.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
import VirtualSelect from '@/components/VirtualSelect.vue'
import { platformNameOf } from '@/constants/platform'
import { mediaUrl } from '@/utils/media'
const BIND_TAGS: Record<number, string> = { 0: 'info', 1: 'success', 2: 'warning' }
const BIND_LABELS: Record<number, string> = { 0: '未绑定', 1: '系统商品', 2: '组合商品' }
const shops = ref<ShopItem[]>([])
const query = reactive({
page: 1,
pageSize: DEFAULT_PAGE_SIZE,
shop_id: '' as string | number,
bind_type: '' as string | number,
status: '' as string | number,
keyword: '',
/** 快速筛选:只看有订单但未绑定系统商品的店铺商品 */
has_unbound_order: false,
})
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
query,
fetcher: () => {
const params: Record<string, unknown> = {
page: query.page,
pageSize: query.pageSize,
shop_id: query.shop_id,
bind_type: query.bind_type,
status: query.status,
keyword: query.keyword,
}
if (!params.keyword) delete params.keyword
if (params.shop_id === '') delete params.shop_id
if (params.bind_type === '') delete params.bind_type
if (params.status === '') delete params.status
// 只看有订单未绑定时,绑定状态必然是「未绑定」,避免两个条件互相打架
if (query.has_unbound_order) {
params.has_unbound_order = 1
params.bind_type = 0
}
return getShopProducts(params)
},
})
async function fetchShops() {
try {
const res = await getShops({ page: 1, pageSize: 200 })
shops.value = res.list
} catch {
shops.value = []
}
}
function reset() {
query.shop_id = ''
query.bind_type = ''
query.status = ''
query.keyword = ''
query.has_unbound_order = false
search()
}
/** 切换「有订单未绑定」快速筛选后立即查询 */
function toggleUnboundOrderFilter() {
query.page = 1
search()
}
/** 导出筛选条件(与列表筛选同源) */
const exportFilters = computed(() => ({
shop_id: query.shop_id,
bind_type: query.has_unbound_order ? 0 : query.bind_type,
status: query.status,
keyword: query.keyword.trim(),
has_unbound_order: query.has_unbound_order ? 1 : '',
}))
/* -------------------- 绑定商品 -------------------- */
const bindVisible = ref(false)
const bindSubmitting = ref(false)
const bindId = ref<number | null>(null)
const bindRow = ref<ShopProductItem | null>(null)
const bindTab = ref<'product' | 'combo'>('product')
/** 批量绑定:勾选的店铺商品(空数组表示单条绑定模式) */
const selectedRows = ref<ShopProductItem[]>([])
const batchMode = computed(() => selectedRows.value.length > 0)
const bindTitle = computed(() => (batchMode.value ? `批量绑定(已选 ${selectedRows.value.length} 条)` : '绑定商品'))
/** 弹窗内容区高度:按视口计算,保证表格内部滚动、底部按钮始终可见 */
const bindBodyHeight = ref(420)
function updateBindBodyHeight() {
bindBodyHeight.value = Math.min(560, Math.max(220, Math.round(window.innerHeight * 0.6)))
}
/** 正在绑定的行(`p<id>` / `c<id>`),用于展示行内 loading */
const bindingKey = ref('')
const productQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE, keyword: '', status: '' as string | number })
const productList = ref<ProductItem[]>([])
const productTotal = ref(0)
const productLoading = ref(false)
const productElapsed = ref<number | null>(null)
const comboQuery = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE, keyword: '', status: '' as string | number })
const comboList = ref<ComboProductItem[]>([])
const comboTotal = ref(0)
const comboLoading = ref(false)
const comboElapsed = ref<number | null>(null)
/** 当前店铺商品的绑定信息 */
const currentBindLabel = computed(() => {
const row = bindRow.value
if (!row) return '-'
if (row.bind_type === BIND_TYPES.product) return `系统商品:${row.product?.item_name || `#${row.product_id}`}`
if (row.bind_type === BIND_TYPES.combo) return `组合商品:${row.comboProduct?.name || `#${row.combo_product_id}`}`
return '未绑定'
})
async function loadProducts() {
productLoading.value = true
const started = performance.now()
try {
const params: Record<string, unknown> = { page: productQuery.page, pageSize: productQuery.pageSize }
const keyword = productQuery.keyword.trim()
if (keyword) params.keyword = keyword
if (productQuery.status !== '') params.status = productQuery.status
const res = await getProducts(params)
productList.value = res.list
productTotal.value = res.total
} catch {
productList.value = []
productTotal.value = 0
} finally {
productElapsed.value = Math.round(performance.now() - started)
productLoading.value = false
}
}
async function loadCombos() {
comboLoading.value = true
const started = performance.now()
try {
const params: Record<string, unknown> = { page: comboQuery.page, pageSize: comboQuery.pageSize }
const keyword = comboQuery.keyword.trim()
if (keyword) params.keyword = keyword
if (comboQuery.status !== '') params.status = comboQuery.status
const res = await getComboProducts(params)
comboList.value = res.list
comboTotal.value = res.total
} catch {
comboList.value = []
comboTotal.value = 0
} finally {
comboElapsed.value = Math.round(performance.now() - started)
comboLoading.value = false
}
}
function searchProducts() {
productQuery.page = 1
loadProducts()
}
function resetProductQuery() {
productQuery.keyword = ''
productQuery.status = ''
productQuery.page = 1
loadProducts()
}
function searchCombos() {
comboQuery.page = 1
loadCombos()
}
function resetComboQuery() {
comboQuery.keyword = ''
comboQuery.status = ''
comboQuery.page = 1
loadCombos()
}
function onProductPageChange(page: number) {
productQuery.page = page
loadProducts()
}
function onProductSizeChange(size: number) {
productQuery.pageSize = size
productQuery.page = 1
loadProducts()
}
function onComboPageChange(page: number) {
comboQuery.page = page
loadCombos()
}
function onComboSizeChange(size: number) {
comboQuery.pageSize = size
comboQuery.page = 1
loadCombos()
}
function openBind(row: ShopProductItem) {
selectedRows.value = []
bindId.value = row.id
bindRow.value = row
bindTab.value = row.bind_type === BIND_TYPES.combo ? 'combo' : 'product'
productQuery.keyword = ''
productQuery.status = ''
productQuery.page = 1
comboQuery.keyword = ''
comboQuery.status = ''
comboQuery.page = 1
bindVisible.value = true
loadProducts()
loadCombos()
}
/** 批量绑定:把勾选的多条店铺商品统一绑定到同一个系统商品 / 组合商品 */
function openBatchBind() {
if (!selectedRows.value.length) {
ElMessage.warning('请先勾选要绑定的店铺商品')
return
}
bindId.value = null
bindRow.value = null
bindTab.value = 'product'
productQuery.keyword = ''
productQuery.status = ''
productQuery.page = 1
comboQuery.keyword = ''
comboQuery.status = ''
comboQuery.page = 1
bindVisible.value = true
loadProducts()
loadCombos()
}
/** 表格勾选变化 */
function onSelectionChange(rows: ShopProductItem[]) {
selectedRows.value = rows
}
/** 当前行是否已绑定该商品/组合商品 */
function isBoundProduct(row: ProductItem) {
return bindRow.value?.bind_type === BIND_TYPES.product && Number(bindRow.value.product_id) === Number(row.id)
}
function isBoundCombo(row: ComboProductItem) {
return bindRow.value?.bind_type === BIND_TYPES.combo && Number(bindRow.value.combo_product_id) === Number(row.id)
}
/** 直接把店铺商品(或勾选的一批)绑定到选中的系统商品 / 组合商品 */
async function bindTo(targetType: number, targetId: number) {
if (bindingKey.value) return
if (batchMode.value) {
await batchBind(targetType, targetId)
return
}
if (bindId.value == null) return
bindingKey.value = `${targetType === BIND_TYPES.combo ? 'c' : 'p'}${targetId}`
bindSubmitting.value = true
try {
await bindShopProduct(bindId.value, {
bind_type: targetType,
product_id: targetType === BIND_TYPES.product ? targetId : null,
combo_product_id: targetType === BIND_TYPES.combo ? targetId : null,
})
ElMessage.success('绑定成功')
bindVisible.value = false
await fetchList()
} catch {
// 拦截器已提示
} finally {
bindingKey.value = ''
bindSubmitting.value = false
}
}
/** 批量绑定:统一绑定到同一对象,逐条结果由后端返回 */
async function batchBind(targetType: number, targetId: number) {
const count = selectedRows.value.length
try {
await ElMessageBox.confirm(
`把已勾选的 ${count} 条店铺商品统一绑定到该${targetType === BIND_TYPES.combo ? '组合商品' : '系统商品'}?已有其它绑定的会被覆盖。`,
'批量绑定确认',
{ type: 'warning', confirmButtonText: '确定绑定', cancelButtonText: '取消' },
)
} catch {
return
}
bindingKey.value = `${targetType === BIND_TYPES.combo ? 'c' : 'p'}${targetId}`
bindSubmitting.value = true
try {
const res = await batchBindShopProducts({
ids: selectedRows.value.map(item => item.id),
bind_type: targetType,
product_id: targetType === BIND_TYPES.product ? targetId : null,
combo_product_id: targetType === BIND_TYPES.combo ? targetId : null,
})
const parts = [`已更新 ${res.updated} 条`]
if (res.skipped) parts.push(`跳过 ${res.skipped} 条(原本就是该绑定)`)
if (res.failed.length) parts.push(`失败 ${res.failed.length} 条`)
if (res.order_items_updated) parts.push(`同步订单明细 ${res.order_items_updated} 条`)
if (res.updated) ElMessage.success(parts.join(';'))
else ElMessage.warning(parts.join(';'))
bindVisible.value = false
selectedRows.value = []
await fetchList()
} catch {
// 拦截器已提示
} finally {
bindingKey.value = ''
bindSubmitting.value = false
}
}
/** 批量解绑:把勾选的店铺商品统一解除绑定 */
async function batchUnbind() {
const count = selectedRows.value.length
if (!count) return
try {
await ElMessageBox.confirm(
`确认解除已勾选 ${count} 条店铺商品的绑定?解除后订单明细会还原为平台原样数据。`,
'批量解绑确认',
{ type: 'warning', confirmButtonText: '解绑', cancelButtonText: '取消' },
)
} catch {
return
}
bindSubmitting.value = true
try {
const res = await batchBindShopProducts({
ids: selectedRows.value.map(item => item.id),
bind_type: BIND_TYPES.none,
product_id: null,
combo_product_id: null,
})
const parts = [`已解绑 ${res.updated} 条`]
if (res.skipped) parts.push(`跳过 ${res.skipped} 条(原本就未绑定)`)
if (res.failed.length) parts.push(`失败 ${res.failed.length} 条`)
ElMessage.success(parts.join(';'))
bindVisible.value = false
selectedRows.value = []
await fetchList()
} catch {
// 拦截器已提示
} finally {
bindSubmitting.value = false
}
}
/** 解除当前店铺商品的绑定 */
async function unbind() {
if (bindId.value == null) return
try {
await ElMessageBox.confirm('确认解除当前绑定?', '解绑确认', {
type: 'warning',
confirmButtonText: '解绑',
cancelButtonText: '取消',
})
} catch {
return
}
bindSubmitting.value = true
try {
await bindShopProduct(bindId.value, { bind_type: BIND_TYPES.none, product_id: null, combo_product_id: null })
ElMessage.success('已解绑')
bindVisible.value = false
await fetchList()
} catch {
// 拦截器已提示
} finally {
bindSubmitting.value = false
}
}
/** 已绑定的商品名称 */
function boundName(row: ShopProductItem) {
if (row.bind_type === BIND_TYPES.product) return row.product?.item_name || `商品#${row.product_id}`
if (row.bind_type === BIND_TYPES.combo) return row.comboProduct?.name || `组合#${row.combo_product_id}`
return '-'
}
/* -------------------- 操作记录(点击行后底部展示) -------------------- */
const logRow = ref<ShopProductItem | null>(null)
const logPanelHeight = ref(240)
function onRowClick(row: ShopProductItem, _column?: unknown, event?: Event) {
// 勾选复选框时不打开操作记录面板(避免点选行时误触)
const target = event && (event.target as HTMLElement | null)
if (target && target.closest && target.closest('.el-checkbox, .el-table-column--selection')) return
// 再次点击同一行则收起
if (logRow.value && logRow.value.id === row.id) {
closeLog()
return
}
logRow.value = row
}
function closeLog() {
logRow.value = null
}
/** 日志里展示的商品名(标题 + 平台商品ID) */
const logTargetName = computed(() => {
const row = logRow.value
if (!row) return ''
const name = row.title || row.outer_item_id
const spec = row.outer_sku_id ? `,规格 ${row.outer_sku_id}` : ''
return `${name}(平台商品ID ${row.outer_item_id}${spec})`
})
/* -------------------- 按平台商品ID补拉 -------------------- */
const pullVisible = ref(false)
const pullSubmitting = ref(false)
const pullForm = reactive({
shop_id: '' as string | number,
outer_item_id: '',
outer_sku_id: '',
})
/** 只允许选择外部打单平台商家店铺(其它类型没有平台商品可拉) */
const externalShops = computed(() => shops.value.filter((shop) => Number(shop.type) === 2))
function openPull() {
pullForm.shop_id = query.shop_id !== '' ? query.shop_id : (externalShops.value[0]?.id ?? '')
pullForm.outer_item_id = ''
pullForm.outer_sku_id = ''
pullVisible.value = true
}
async function submitPull() {
const shop = shops.value.find((item) => Number(item.id) === Number(pullForm.shop_id))
const outerItemId = pullForm.outer_item_id.trim()
if (!shop) {
ElMessage.warning('请选择外部打单平台店铺')
return
}
if (!shop.external_print_account_id) {
ElMessage.warning('该店铺未关联外部打单账号,无法拉取商品')
return
}
if (!outerItemId) {
ElMessage.warning('请输入平台商品ID')
return
}
pullSubmitting.value = true
try {
const res = await pullExternalPrintShopProducts(shop.external_print_account_id, shop.id, [
{ outer_item_id: outerItemId, outer_sku_id: pullForm.outer_sku_id.trim() },
])
if (!res.matched) {
const reason = res.missing[0]?.reason || '平台未查询到该商品'
ElMessage.warning(`未拉取到商品:${reason}`)
return
}
ElMessage.success(`拉取成功:新增 ${res.created},更新 ${res.updated},来源 ${res.hosts.join('、')}`)
pullVisible.value = false
await fetchList()
} catch {
// 拦截器已提示
} finally {
pullSubmitting.value = false
}
}
onMounted(async () => {
updateBindBodyHeight()
window.addEventListener('resize', updateBindBodyHeight)
await fetchShops()
await fetchList()
})
onBeforeUnmount(() => {
window.removeEventListener('resize', updateBindBodyHeight)
})
</script>
<template>
<el-card class="shop-product-card">
<template #header>
<div class="page-header">
<span>店铺商品</span>
<div class="header-actions">
<el-button type="warning" plain :disabled="!selectedRows.length" @click="openBatchBind">
批量绑定{{ selectedRows.length ? `(${selectedRows.length})` : '' }}
</el-button>
<el-button @click="openPull">按商品ID拉取</el-button>
<ExportButton type="shop_product" :filters="exportFilters" />
</div>
</div>
</template>
<el-form :inline="true" class="search-bar">
<el-form-item label="店铺">
<VirtualSelect
v-model="query.shop_id"
:options="shops"
label-key="name"
value-key="id"
placeholder="全部"
clearable
style="width: 160px"
/>
</el-form-item>
<el-form-item label="关键词">
<el-input
v-model="query.keyword"
placeholder="标题 / 商家编码 / 平台商品ID"
clearable
@keyup.enter="search"
/>
</el-form-item>
<el-form-item label="绑定状态">
<el-select
v-model="query.bind_type"
placeholder="全部"
clearable
:disabled="query.has_unbound_order"
style="width: 130px"
>
<el-option label="未绑定" :value="0" />
<el-option label="系统商品" :value="1" />
<el-option label="组合商品" :value="2" />
</el-select>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
<el-option label="在售" :value="1" />
<el-option label="下架" :value="0" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="reset">重置</el-button>
</el-form-item>
<el-form-item>
<el-checkbox
v-model="query.has_unbound_order"
class="unbound-filter"
@change="toggleUnboundOrderFilter"
>
只看有订单未绑定
</el-checkbox>
<el-tooltip
content="商品的订单里还有未绑定系统商品的明细,绑定后订单明细会自动关联"
placement="top"
>
<el-icon class="unbound-hint"><QuestionFilled /></el-icon>
</el-tooltip>
</el-form-item>
</el-form>
<div class="list-table-wrap" :class="{ 'list-table-wrap--with-log': !!logRow }">
<DataTable
:loading="loading"
:data="list"
height="100%"
highlight-current-row
@row-click="onRowClick"
@selection-change="onSelectionChange"
>
<el-table-column type="selection" width="44" fixed="left" />
<el-table-column label="店铺" width="140">
<template #default="{ row }">{{ row.shop?.name || '-' }}</template>
</el-table-column>
<el-table-column label="货主" width="140" show-overflow-tooltip>
<template #default="{ row }">{{ row.subsidiary_name || '-' }}</template>
</el-table-column>
<el-table-column label="平台类型" width="110">
<template #default="{ row }">{{ platformNameOf(row.platform_type) }}</template>
</el-table-column>
<el-table-column prop="outer_item_id" label="平台商品ID" width="140" />
<el-table-column prop="outer_sku_id" label="规格ID" width="120">
<template #default="{ row }">{{ row.outer_sku_id || '-' }}</template>
</el-table-column>
<el-table-column label="图片" width="64" align="center">
<template #default="{ row }">
<div v-if="row.image" class="thumb-cell" @click.stop>
<el-image
:src="mediaUrl(row.image)"
:preview-src-list="[ mediaUrl(row.image) ]"
fit="cover"
class="thumb-img"
preview-teleported
hide-on-click-modal
/>
</div>
<span v-else class="muted">-</span>
</template>
</el-table-column>
<el-table-column prop="title" label="商品标题" min-width="180" show-overflow-tooltip />
<el-table-column prop="outer_code" label="商家编码" width="120">
<template #default="{ row }">{{ row.outer_code || '-' }}</template>
</el-table-column>
<el-table-column label="售价" width="100" align="right">
<template #default="{ row }">{{ row.price ?? '-' }}</template>
</el-table-column>
<el-table-column prop="stock" label="库存" width="90" align="right" />
<el-table-column label="绑定" min-width="150">
<template #default="{ row }">
<el-tag :type="BIND_TAGS[row.bind_type]" size="small">
{{ BIND_LABELS[row.bind_type] }}
</el-tag>
<span v-if="row.bind_type !== 0" class="bound-name">{{ boundName(row) }}</span>
</template>
</el-table-column>
<el-table-column label="待处理订单" width="110" align="center">
<template #default="{ row }">
<el-tag v-if="row.unbound_order_count" type="danger" size="small">
{{ row.unbound_order_count }} 单待绑定
</el-tag>
<span v-else class="muted">-</span>
</template>
</el-table-column>
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '在售' : '下架' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="100" fixed="right">
<template #default="{ row }">
<el-button link type="warning" @click="openBind(row)">绑定</el-button>
</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="total"
:elapsed="elapsed"
:page="query.page"
:page-size="query.pageSize"
@page-change="handlePageChange"
@size-change="handleSizeChange"
/>
<!-- 操作记录:点击商品行后在下方展开(采集时间 / 绑定解绑 / 操作人) -->
<div v-if="logRow" class="log-wrap" :style="{ height: `${logPanelHeight}px` }">
<div class="log-head">
<span class="log-name">{{ logTargetName }}</span>
<el-button link size="small" class="log-close" @click="closeLog">收起</el-button>
</div>
<div class="log-body">
<OperationLogPanel
:target-type="'shop_product'"
:target-id="logRow.id"
:table-height="'100%'"
hide-header
/>
</div>
</div>
<el-dialog v-model="pullVisible" title="按平台商品ID拉取" width="520px">
<el-alert
type="info"
:closable="false"
show-icon
title="用于订单明细匹配不到店铺商品时补拉:填平台商品ID(可选规格ID),后端按店铺分区及其它域名查询后写入店铺商品"
class="pull-tip"
/>
<el-form :model="pullForm" label-width="100px">
<el-form-item label="店铺" required>
<VirtualSelect
v-model="pullForm.shop_id"
:options="externalShops"
label-key="name"
value-key="id"
placeholder="请选择外部打单平台店铺"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="平台商品ID" required>
<el-input v-model="pullForm.outer_item_id" placeholder="订单明细的 outer_item_id" clearable />
</el-form-item>
<el-form-item label="平台规格ID">
<el-input v-model="pullForm.outer_sku_id" placeholder="留空则拉取该商品的全部规格" clearable />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="pullVisible = false">取消</el-button>
<el-button type="primary" :loading="pullSubmitting" @click="submitPull">拉取</el-button>
</template>
</el-dialog>
<el-dialog
v-model="bindVisible"
:title="bindTitle"
width="min(1100px, 94vw)"
top="5vh"
class="bind-dialog"
destroy-on-close
>
<el-alert
v-if="batchMode"
type="warning"
:closable="false"
show-icon
class="bind-batch-tip"
:title="`已勾选 ${selectedRows.length} 条店铺商品:选择下面的系统商品或组合商品后,会把这 ${selectedRows.length} 条统一绑定到同一个对象(已有其它绑定的会被覆盖)`"
/>
<div class="bind-layout" :style="{ height: `${bindBodyHeight}px` }">
<el-tabs v-model="bindTab" tab-position="left" class="bind-tabs">
<el-tab-pane label="系统商品" name="product">
<div class="bind-pane">
<div class="bind-filters">
<el-input
v-model="productQuery.keyword"
placeholder="商品编码 / 名称"
clearable
style="width: 240px"
@keyup.enter="searchProducts"
/>
<el-select v-model="productQuery.status" placeholder="状态" clearable style="width: 120px">
<el-option label="上架" :value="1" />
<el-option label="下架" :value="0" />
</el-select>
<el-button type="primary" @click="searchProducts">查询</el-button>
<el-button @click="resetProductQuery">重置</el-button>
</div>
<div class="bind-table">
<DataTable :loading="productLoading" :data="productList" height="100%">
<el-table-column label="图片" width="64" align="center">
<template #default="{ row }">
<el-image
v-if="row.image"
:src="mediaUrl(row.image)"
fit="cover"
style="width: 40px; height: 40px; border-radius: 4px"
:preview-src-list="[ mediaUrl(row.image) ]"
preview-teleported
/>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column prop="item_code" label="商品编码" width="150" />
<el-table-column prop="item_name" label="商品名称" min-width="200" show-overflow-tooltip />
<el-table-column label="货主" width="130" show-overflow-tooltip>
<template #default="{ row }">{{ row.subsidiary_name || '-' }}</template>
</el-table-column>
<el-table-column prop="sku_property" label="SKU规格" width="140">
<template #default="{ row }">{{ row.sku_property || '-' }}</template>
</el-table-column>
<el-table-column prop="barcode" label="条码" width="150">
<template #default="{ row }">{{ row.barcode || '-' }}</template>
</el-table-column>
<el-table-column label="零售价" width="100" align="right">
<template #default="{ row }">{{ row.retail_price ?? '-' }}</template>
</el-table-column>
<el-table-column label="状态" width="80">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '上架' : '下架' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="100" fixed="right">
<template #default="{ row }">
<el-button
link
type="primary"
:disabled="isBoundProduct(row) || !!bindingKey"
:loading="bindingKey === `p${row.id}`"
@click="bindTo(BIND_TYPES.product, row.id)"
>
{{ isBoundProduct(row) ? '已绑定' : '绑定' }}
</el-button>
</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="productTotal"
:elapsed="productElapsed"
:page="productQuery.page"
:page-size="productQuery.pageSize"
@page-change="onProductPageChange"
@size-change="onProductSizeChange"
/>
</div>
</el-tab-pane>
<el-tab-pane label="组合商品" name="combo">
<div class="bind-pane">
<div class="bind-filters">
<el-input
v-model="comboQuery.keyword"
placeholder="组合编码 / 名称"
clearable
style="width: 240px"
@keyup.enter="searchCombos"
/>
<el-select v-model="comboQuery.status" placeholder="状态" clearable style="width: 120px">
<el-option label="上架" :value="1" />
<el-option label="下架" :value="0" />
</el-select>
<el-button type="primary" @click="searchCombos">查询</el-button>
<el-button @click="resetComboQuery">重置</el-button>
</div>
<div class="bind-table">
<DataTable :loading="comboLoading" :data="comboList" height="100%">
<el-table-column prop="code" label="组合编码" width="160" />
<el-table-column prop="name" label="组合名称" min-width="220" show-overflow-tooltip />
<el-table-column label="价格" width="110" align="right">
<template #default="{ row }">{{ row.price }}</template>
</el-table-column>
<el-table-column label="状态" width="80">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '上架' : '下架' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="100" fixed="right">
<template #default="{ row }">
<el-button
link
type="primary"
:disabled="isBoundCombo(row) || !!bindingKey"
:loading="bindingKey === `c${row.id}`"
@click="bindTo(BIND_TYPES.combo, row.id)"
>
{{ isBoundCombo(row) ? '已绑定' : '绑定' }}
</el-button>
</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="comboTotal"
:elapsed="comboElapsed"
:page="comboQuery.page"
:page-size="comboQuery.pageSize"
@page-change="onComboPageChange"
@size-change="onComboSizeChange"
/>
</div>
</el-tab-pane>
</el-tabs>
</div>
<template #footer>
<div class="bind-footer">
<span class="bind-current">
{{ batchMode ? `已勾选 ${selectedRows.length} 条:统一绑定到同一对象` : `当前绑定:${currentBindLabel}` }}
</span>
<div>
<el-button v-if="batchMode" :loading="bindSubmitting" @click="batchUnbind">统一解绑</el-button>
<el-button
v-else-if="bindRow && bindRow.bind_type !== BIND_TYPES.none"
:loading="bindSubmitting"
@click="unbind"
>
解绑
</el-button>
<el-button @click="bindVisible = false">关闭</el-button>
</div>
</div>
</template>
</el-dialog>
</el-card>
</template>
<style scoped>
/* 整页撑满可视区域:头部与筛选固定,只有表格主体滚动,分页固定在底部 */
.shop-product-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.shop-product-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
}
.search-bar {
flex: 0 0 auto;
margin-bottom: 12px;
}
.list-table-wrap {
flex: 1 1 auto;
min-height: 0;
}
/* 底部展开操作记录后,表格让出一部分高度(表格内部仍可滚动) */
.log-wrap {
flex: 0 0 auto;
display: flex;
flex-direction: column;
min-height: 0;
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid var(--el-border-color-lighter);
}
.log-head {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 4px;
}
.log-name {
font-size: 12px;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.log-close {
margin-left: auto;
}
.log-body {
flex: 1 1 auto;
min-height: 0;
}
.bound-name {
margin-left: 8px;
}
.unbound-filter {
font-size: 12px;
}
.unbound-hint {
margin-left: 4px;
font-size: 13px;
color: var(--el-text-color-secondary);
cursor: help;
}
.muted {
color: var(--el-text-color-secondary);
}
/* 列表商品图片:点击打开大图预览,阻止冒泡避免触发行点击(操作记录面板) */
.thumb-cell {
display: inline-flex;
cursor: zoom-in;
}
.thumb-img {
width: 40px;
height: 40px;
border-radius: 4px;
background: var(--el-fill-color-light);
}
.pull-tip {
margin-bottom: 16px;
}
/* 绑定弹窗:左侧页签 + 右侧列表(表格内部滚动,分页固定在底部) */
.bind-layout {
/* 高度由脚本按视口计算(bindBodyHeight),避免小屏溢出 */
overflow: hidden;
}
.bind-tabs {
height: 100%;
}
.bind-tabs :deep(.el-tabs__content) {
height: 100%;
overflow: hidden;
}
.bind-tabs :deep(.el-tab-pane) {
height: 100%;
}
.bind-pane {
display: flex;
flex-direction: column;
height: 100%;
padding-left: 12px;
}
.bind-filters {
flex: 0 0 auto;
display: flex;
gap: 8px;
margin-bottom: 10px;
padding-right: 12px;
}
.bind-table {
flex: 1 1 auto;
min-height: 0;
}
.bind-footer {
display: flex;
align-items: center;
justify-content: space-between;
}
.bind-current {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.bind-batch-tip {
margin-bottom: 8px;
}
</style>