1002 lines
28 KiB
Vue
1002 lines
28 KiB
Vue
<template>
|
||
<div class="product-details">
|
||
<div class="header-actions">
|
||
<div class="left-actions">
|
||
<el-button size="small" @click="loadProductData">刷新</el-button>
|
||
<el-radio-group v-model="matchFilter" size="small" style="margin: 0 12px;">
|
||
<el-radio-button label="all">全部</el-radio-button>
|
||
<el-radio-button label="matched">已匹配</el-radio-button>
|
||
<el-radio-button label="unmatched">未匹配</el-radio-button>
|
||
</el-radio-group>
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
size="small"
|
||
:disabled="multipleSelection.length > 1"
|
||
@click="openAddDrawer"
|
||
>添加商品</el-button>
|
||
<el-button size="small" type="primary" disabled>批量操作</el-button>
|
||
<!-- <el-button size="small" disabled>导出</el-button> -->
|
||
</div>
|
||
<div class="right-actions">
|
||
<!-- 可以在这里添加搜索框或其他操作 -->
|
||
</div>
|
||
</div>
|
||
|
||
<div class="left-col">
|
||
<UpperTable
|
||
:data="filteredTableData"
|
||
:columns="productquick"
|
||
:show-selection="true"
|
||
:pagination="pagination"
|
||
:query-time="queryTime"
|
||
@selection-change="handleSelectionChange"
|
||
@row-click="handleRowClick"
|
||
@page-size-change="handlePageSizeChange"
|
||
@page-change="handlePageChange"
|
||
@row-contextmenu="handleContextMenu"
|
||
>
|
||
<template #column-images="{ row }">
|
||
<div class="image-slot" style="display: flex; gap: 4px; flex-wrap: wrap;">
|
||
<template v-if="row.images && row.images.length > 0">
|
||
<el-image
|
||
v-for="(img, index) in row.images"
|
||
:key="img.id || index"
|
||
style="width: 40px; height: 40px"
|
||
:src="img.url"
|
||
:preview-src-list="row.images.map((i: any) => i.url)"
|
||
:initial-index="index"
|
||
fit="cover"
|
||
preview-teleported
|
||
/>
|
||
</template>
|
||
<el-image
|
||
v-else-if="row.image"
|
||
style="width: 40px; height: 40px"
|
||
:src="row.image"
|
||
:preview-src-list="[row.image]"
|
||
fit="cover"
|
||
preview-teleported
|
||
/>
|
||
<span v-else>--</span>
|
||
</div>
|
||
</template>
|
||
|
||
<template #column-storage_status="{ row }">
|
||
<el-tag
|
||
:type="formatProductStorageStatus(row.storage_status).config.tagType"
|
||
size="small"
|
||
effect="light"
|
||
>
|
||
{{ formatProductStorageStatus(row.storage_status).text }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-match_status="{ row }">
|
||
<el-tag
|
||
:type="row.system_product_id ? 'success' : 'info'"
|
||
size="small"
|
||
effect="light"
|
||
>
|
||
{{ row.system_product_id ? '已匹配' : '未匹配' }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<el-button
|
||
type="primary"
|
||
link
|
||
size="small"
|
||
@click.stop="handleQuickLink(row)"
|
||
>
|
||
快速关联
|
||
</el-button>
|
||
<!-- <el-button
|
||
type="primary"
|
||
plain
|
||
size="small"
|
||
style="margin-left:8px"
|
||
@click="openAddDrawer"
|
||
>添加商品</el-button> -->
|
||
</template>
|
||
</UpperTable>
|
||
</div>
|
||
|
||
<!-- 快速关联弹窗 -->
|
||
<div v-if="quickLinkVisible" class="modal-backdrop" @click.stop></div>
|
||
<div v-if="quickLinkVisible" class="product-window quick-link-window" :class="{ 'is-fullscreen': isQuickFullscreen }" :style="quickLinkStyle">
|
||
<div class="window-header" @mousedown="startQuickDrag">
|
||
<span class="window-title">快速关联 - {{ currentRow?.item_name || currentRow?.product_name }}</span>
|
||
<div class="window-actions">
|
||
<el-button link :icon="isQuickFullscreen ? CopyDocument : FullScreen" @click="isQuickFullscreen = !isQuickFullscreen" :title="isQuickFullscreen ? '还原' : '最大化'" />
|
||
<el-button link :icon="Close" @click="quickLinkVisible = false" title="关闭" />
|
||
</div>
|
||
</div>
|
||
<div class="window-body">
|
||
<div class="window-content">
|
||
<div class="quick-link-content">
|
||
<!-- 这里可以放置商品搜索和选择列表 -->
|
||
<div class="search-section">
|
||
<el-form label-position="left" :inline="true" class="search-form">
|
||
<el-form-item label="货主">
|
||
<el-input :value="quickLinkStore?.name || quickLinkStore?.store_remask || quickLinkStore?.store_name" disabled style="width: 200px" />
|
||
</el-form-item>
|
||
<el-form-item label="快速搜索">
|
||
<el-input v-model="quickSearchQuery" placeholder="输入商品名称或条码搜索" class="search-input" style="width: 300px">
|
||
<template #append>
|
||
<el-button :icon="Search" @click="() => performQuickSearch(1)">搜索</el-button>
|
||
</template>
|
||
</el-input>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
<div class="system-product-list" style="display:flex; flex-direction:column; flex: 1; min-height: 0;">
|
||
<UpperTable
|
||
:data="quickSearchResults"
|
||
v-loading="quickSearchLoading"
|
||
:columns="[
|
||
{ prop: 'id', label: 'ID', width: 80 },
|
||
{ prop: 'item_name', label: '名称' },
|
||
{ prop: 'barcodes', label: '条码', width: 160 },
|
||
{ prop: 'store_name', label: '货主', width: 150 }
|
||
]"
|
||
:pagination="{
|
||
currentPage: quickResultPagination.page,
|
||
pageSize: quickResultPagination.pageSize,
|
||
total: quickResultPagination.total
|
||
}"
|
||
:show-selection="true"
|
||
:multiple-selection="multipleQuickSelection"
|
||
@selection-change="handleQuickSelectionChange"
|
||
@row-click="handleQuickRowClick"
|
||
@page-change="performQuickSearch"
|
||
@page-size-change="onQuickPageSizeChange"
|
||
style="height: 100%;"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="window-footer">
|
||
<el-button size="small" @click="quickLinkVisible = false">取消</el-button>
|
||
<el-button size="small" type="primary" @click="confirmQuickLink" :disabled="multipleQuickSelection.length !== 1">完成关联</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 添加商品抽屉(复用 stock add.vue) -->
|
||
<el-drawer v-model="addDrawerVisible" title="添加商品" :append-to-body="true" size="800px">
|
||
<AddProduct ref="addCompRef" :initialStore="addDrawerStore" :storeDisabled="true" />
|
||
</el-drawer>
|
||
|
||
<!-- 右键菜单 -->
|
||
<div v-if="menuVisible" :style="{ top: menuTop + 'px', left: menuLeft + 'px' }" class="context-menu">
|
||
<div class="menu-item" @click="handleProductDetail">货品详情</div>
|
||
</div>
|
||
|
||
<!-- 货品详情弹窗 -->
|
||
<div v-if="windowVisible" class="product-window detail-window" :class="{ 'is-fullscreen': isFullscreen }" :style="windowStyle">
|
||
<div class="window-header" @mousedown="startDrag">
|
||
<span class="window-title">货品详情 - {{ currentRow?.item_name }}</span>
|
||
<div class="window-actions">
|
||
<el-button link :icon="isFullscreen ? CopyDocument : FullScreen" @click="toggleFullscreen" :title="isFullscreen ? '还原' : '最大化'" />
|
||
<el-button link :icon="Close" @click="windowVisible = false" title="关闭" />
|
||
</div>
|
||
</div>
|
||
<div class="window-body">
|
||
<div class="window-tabs">
|
||
<div
|
||
v-for="tab in windowtopbar"
|
||
:key="tab.key"
|
||
class="tab-item"
|
||
:class="{ active: activeWindowTab === tab.key }"
|
||
@click="activeWindowTab = tab.key"
|
||
>
|
||
{{ tab.label }}
|
||
</div>
|
||
</div>
|
||
<div class="window-content">
|
||
<KeepAlive>
|
||
<component
|
||
:is="currentWindowComponent"
|
||
:row="currentRow"
|
||
ref="basicRef"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
<div class="window-footer">
|
||
<el-button size="small" @click="resetForm" disabled>重置</el-button>
|
||
<el-button size="small" type="primary" @click="saveProductDetail" disabled>保存</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- <aside class="right-col">
|
||
<div class="right-panel">
|
||
<div class="panel-actions">
|
||
<el-button disabled>重置</el-button>
|
||
<el-button type="primary" @click="handleSave" :loading="saveLoading" disabled>
|
||
保存
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</aside> -->
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, onMounted, onUnmounted, computed, reactive, watch, nextTick } from 'vue'
|
||
import { productdetail, productquick, productsnapshop, windowtopbar, formatProductStorageStatus } from '../receiving-config'
|
||
import { ElMessage } from 'element-plus'
|
||
import { FullScreen, Close, CopyDocument, Search } from '@element-plus/icons-vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import AddProduct from '@/views/stock/stock/component/add.vue'
|
||
import * as receivingApi from '@/api/storage/receiving'
|
||
import * as stockApi from '@/api/stock'
|
||
import { buildStockQuery } from '@/utils/stockQueryBuilder'
|
||
|
||
import basic from '../window/basic.vue'
|
||
import log from '../window/log.vue'
|
||
import product from '../window/product.vue'
|
||
|
||
const props = defineProps<{
|
||
id?: string | number,
|
||
productData?: any[],
|
||
loading?: boolean,
|
||
productTotal?: number,
|
||
row?: any
|
||
}>()
|
||
|
||
const tableData = ref<any[]>([])
|
||
const multipleSelection = ref<any[]>([])
|
||
const saveLoading = ref(false)
|
||
const matchFilter = ref('all')
|
||
|
||
const filteredTableData = computed(() => {
|
||
if (matchFilter.value === 'matched') {
|
||
return tableData.value.filter(item => !!item.system_product_id)
|
||
} else if (matchFilter.value === 'unmatched') {
|
||
return tableData.value.filter(item => !item.system_product_id)
|
||
}
|
||
return tableData.value
|
||
})
|
||
|
||
// 分页相关
|
||
const pagination = reactive({
|
||
currentPage: 1,
|
||
pageSize: 20,
|
||
total: 0
|
||
})
|
||
|
||
const queryTime = ref(0)
|
||
|
||
// 监听外部数据变化
|
||
watch(() => props.productData, (newVal) => {
|
||
// 始终将父组件传入的数据同步到表格,空数组也应清空表格数据
|
||
if (Array.isArray(newVal)) {
|
||
tableData.value = [...newVal]
|
||
pagination.total = props.productTotal ?? newVal.length
|
||
} else {
|
||
tableData.value = []
|
||
pagination.total = props.productTotal ?? 0
|
||
}
|
||
}, { immediate: true })
|
||
|
||
const emit = defineEmits(['page-change', 'page-size-change', 'refresh-product'])
|
||
|
||
const handlePageSizeChange = (val: number) => {
|
||
pagination.pageSize = val
|
||
emit('page-size-change', val)
|
||
}
|
||
|
||
const handlePageChange = (val: number) => {
|
||
pagination.currentPage = val
|
||
emit('page-change', val)
|
||
}
|
||
|
||
const loadProductData = () => {
|
||
// 请求父组件刷新商品数据
|
||
emit('refresh-product')
|
||
}
|
||
|
||
async function fetchReceivingDetail() {
|
||
try {
|
||
const params = {
|
||
id: props.id,
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize }
|
||
}
|
||
const res: any = await receivingApi.getReceivingDetail(params)
|
||
if (res && res.code === 200 && res.data) {
|
||
const receivingData = res.data.receiving || {}
|
||
if (Array.isArray(receivingData.details)) {
|
||
tableData.value = receivingData.details
|
||
pagination.total = receivingData.pagination?.total || receivingData.details.length || 0
|
||
} else {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
}
|
||
} else {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
}
|
||
} catch (e) {
|
||
console.error('加载商品明细失败', e)
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('加载商品明细失败')
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
// 监听 props.loading
|
||
watch(() => props.loading, (val) => {
|
||
if (!val && (!props.productData || props.productData.length === 0)) {
|
||
// tableData.value = [...mockProductData]
|
||
// pagination.total = mockProductData.length
|
||
}
|
||
})
|
||
|
||
// 监听 props.productTotal
|
||
watch(() => props.productTotal, (val) => {
|
||
if (val !== undefined) {
|
||
pagination.total = val
|
||
}
|
||
})
|
||
|
||
const handleRowClick = (row: any) => {
|
||
currentRow.value = row
|
||
}
|
||
|
||
// 标签页相关
|
||
const activeWindowTab = ref('basic')
|
||
const windowComponentMap: Record<string, any> = {
|
||
basic: basic,
|
||
// product: product,
|
||
logs: log
|
||
}
|
||
|
||
const currentWindowComponent = computed(() => windowComponentMap[activeWindowTab.value])
|
||
|
||
const basicRef = ref<any>(null)
|
||
|
||
// 右键菜单相关
|
||
const menuVisible = ref(false)
|
||
const menuTop = ref(0)
|
||
const menuLeft = ref(0)
|
||
const currentRow = ref<any>(null)
|
||
|
||
// 窗口控制
|
||
const windowVisible = ref(false)
|
||
const isFullscreen = ref(false)
|
||
const position = ref({ x: 350, y: 250 })
|
||
const isDragging = ref(false)
|
||
const dragOffset = ref({ x: 0, y: 0 })
|
||
|
||
// 快速关联弹窗控制
|
||
const quickLinkVisible = ref(false)
|
||
const isQuickFullscreen = ref(false)
|
||
const quickPosition = ref({ x: 250, y: 150 })
|
||
const isQuickDragging = ref(false)
|
||
const quickDragOffset = ref({ x: 0, y: 0 })
|
||
const quickSearchQuery = ref('')
|
||
const quickLinkStore = ref<any>(null)
|
||
// 快速关联搜索结果状态
|
||
const quickSearchResults = ref<any[]>([])
|
||
const quickSearchLoading = ref(false)
|
||
const quickResultPagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
||
const selectedSystemProduct = ref<any>(null)
|
||
const multipleQuickSelection = ref<any[]>([])
|
||
|
||
// 添加商品抽屉
|
||
const addDrawerVisible = ref(false)
|
||
const addDrawerStore = ref<any>(null)
|
||
const addCompRef = ref<any>(null)
|
||
|
||
const windowStyle = computed(() => {
|
||
if (isFullscreen.value) return {}
|
||
return {
|
||
top: `${position.value.y}px`,
|
||
left: `${position.value.x}px`,
|
||
}
|
||
})
|
||
|
||
const quickLinkStyle = computed(() => {
|
||
if (isQuickFullscreen.value) return {}
|
||
return {
|
||
top: `${quickPosition.value.y}px`,
|
||
left: `${quickPosition.value.x}px`
|
||
}
|
||
})
|
||
|
||
const openAddDrawer = () => {
|
||
// row here is product row, but store info comes from parent receiving row (props.row)
|
||
addDrawerStore.value = props.row?.store || { id: props.row?.store_id, name: props.row?.store_name }
|
||
addDrawerVisible.value = true
|
||
// allow child to initialize with store after mount
|
||
setTimeout(() => {
|
||
if (addCompRef.value) {
|
||
if (typeof addCompRef.value.resetForm === 'function') {
|
||
addCompRef.value.resetForm()
|
||
}
|
||
const formData = addCompRef.value.formData
|
||
if (!formData) return
|
||
|
||
if (addDrawerStore.value) {
|
||
formData.store_id = addDrawerStore.value.id || addDrawerStore.value.store_id || addDrawerStore.value.storeId
|
||
}
|
||
|
||
// 如果勾选了一个商品,自动填充相关字段
|
||
if (multipleSelection.value.length === 1) {
|
||
const item = multipleSelection.value[0]
|
||
formData.item_name = item.item_name || item.product_name || ''
|
||
const barcode = item.barcodes || item.barcode || ''
|
||
formData.barcode = barcode
|
||
formData.item_code = barcode || item.item_code || ''
|
||
|
||
// 解析可能存在的规格/属性 snapshot
|
||
if (item.product_snapshot) {
|
||
try {
|
||
const snap = typeof item.product_snapshot === 'string' ? JSON.parse(item.product_snapshot) : item.product_snapshot
|
||
if (snap.spec) formData.sku_property = snap.spec
|
||
if (snap.brand) formData.brand_name = snap.brand
|
||
} catch (e) {}
|
||
}
|
||
|
||
// 尝试填充箱规或体积(如果明细存在)
|
||
if (item.box_length) formData.length = item.box_length
|
||
if (item.box_width) formData.width = item.box_width
|
||
if (item.box_height) formData.height = item.box_height
|
||
if (item.weight) formData.gross_weight = item.weight
|
||
}
|
||
}
|
||
}, 100)
|
||
}
|
||
|
||
const handleSelectionChange = (val: any[]) => {
|
||
multipleSelection.value = val
|
||
}
|
||
|
||
const handleContextMenu = (row: any, column: any, event: MouseEvent) => {
|
||
event.preventDefault()
|
||
currentRow.value = row
|
||
menuTop.value = event.clientY
|
||
menuLeft.value = event.clientX
|
||
menuVisible.value = true
|
||
}
|
||
|
||
const closeMenu = () => {
|
||
menuVisible.value = false
|
||
}
|
||
|
||
const handleProductDetail = () => {
|
||
if (currentRow.value) {
|
||
windowVisible.value = true
|
||
// 重置为居中位置
|
||
isFullscreen.value = false
|
||
// 以样式中定义的默认窗口大小居中(width:1250, height:700)
|
||
const winW = 1250
|
||
const winH = 700
|
||
const x = Math.max(0, Math.floor((window.innerWidth - winW) / 2))
|
||
const y = Math.max(0, Math.floor((window.innerHeight - winH) / 2))
|
||
position.value = { x, y }
|
||
}
|
||
closeMenu()
|
||
}
|
||
|
||
// 快速关联逻辑
|
||
const handleQuickLink = (row: any) => {
|
||
currentRow.value = row
|
||
quickLinkVisible.value = true
|
||
// 将快速关联窗口居中显示
|
||
isQuickFullscreen.value = false
|
||
const winW = 1250
|
||
const winH = 700
|
||
const qx = Math.max(0, Math.floor((window.innerWidth - winW) / 2))
|
||
const qy = Math.max(0, Math.floor((window.innerHeight - winH) / 2))
|
||
quickPosition.value = { x: qx, y: qy }
|
||
quickSearchQuery.value = row.product_name || row.item_name || ''
|
||
multipleQuickSelection.value = []
|
||
selectedSystemProduct.value = null
|
||
// 优先使用商品行中可能包含的收货单货主(例如 row.receiving.store),
|
||
// 否则使用父组件传入的收货单(props.row)信息作为回退
|
||
const storeFromDetail = row?.receiving?.store || row?.store || (row && (row.store_id || row.store_name) ? { id: row.store_id, name: row.store_name } : null)
|
||
const storeFromParent = props.row?.store || (props.row && (props.row.store_id || props.row.store_name) ? { id: props.row.store_id, name: props.row.store_name } : null)
|
||
quickLinkStore.value = storeFromDetail || storeFromParent || null
|
||
// 打开弹窗后立即搜索一次(如果有关键字或货主)
|
||
performQuickSearch(1)
|
||
}
|
||
|
||
const handleQuickSelectionChange = (val: any[]) => {
|
||
multipleQuickSelection.value = val
|
||
if (val.length === 1) {
|
||
selectedSystemProduct.value = val[0]
|
||
} else {
|
||
selectedSystemProduct.value = null
|
||
}
|
||
}
|
||
|
||
const handleQuickRowClick = (row: any) => {
|
||
// 点击行时切换选中状态,这里如果是单选逻辑,可以清空其他再选中当前
|
||
// 或者直接赋值给 multipleQuickSelection 模拟单选
|
||
multipleQuickSelection.value = [row]
|
||
selectedSystemProduct.value = row
|
||
}
|
||
|
||
const onSystemProductChange = (row: any) => {
|
||
selectedSystemProduct.value = row
|
||
}
|
||
|
||
const tableRowClassName = (row: any) => {
|
||
return 'clickable-row'
|
||
}
|
||
|
||
const onQuickPageSizeChange = (size: number) => {
|
||
quickResultPagination.pageSize = size
|
||
performQuickSearch(1)
|
||
}
|
||
|
||
const performQuickSearch = async (page = 1) => {
|
||
quickSearchLoading.value = true
|
||
try {
|
||
const paginationParam = { page, pageSize: quickResultPagination.pageSize }
|
||
// 构造符合后端期望的 where,对关键字智能判断使用条码或名称模糊匹配
|
||
const params: any = {}
|
||
if (quickLinkStore.value && (quickLinkStore.value.id || quickLinkStore.value.store_id)) {
|
||
params.store_id = quickLinkStore.value.id || quickLinkStore.value.store_id
|
||
}
|
||
if (quickSearchQuery.value) {
|
||
const q = String(quickSearchQuery.value).trim()
|
||
// 如果看起来像条码(全数字且长度>=6),优先按条码搜索,否则按名称模糊搜索
|
||
if (/^\d{6,}$/.test(q)) {
|
||
params.barcodes = { operator: 'like', value: q }
|
||
} else {
|
||
params.item_name = { operator: 'like', value: q }
|
||
}
|
||
}
|
||
const where = buildStockQuery(params)
|
||
const res: any = await stockApi.stockWarehouse(paginationParam, where)
|
||
if (res && res.data) {
|
||
quickSearchResults.value = res.data.list || []
|
||
quickResultPagination.total = res.data.pagination?.total || res.data.total || quickSearchResults.value.length
|
||
quickResultPagination.page = page
|
||
} else {
|
||
quickSearchResults.value = []
|
||
quickResultPagination.total = 0
|
||
}
|
||
} catch (e) {
|
||
console.error('快速关联搜索失败', e)
|
||
ElMessage.error('搜索失败')
|
||
quickSearchResults.value = []
|
||
quickResultPagination.total = 0
|
||
} finally {
|
||
quickSearchLoading.value = false
|
||
}
|
||
}
|
||
|
||
const confirmQuickLink = async () => {
|
||
if (!selectedSystemProduct.value) {
|
||
ElMessage.warning('请先选择一个系统商品')
|
||
return
|
||
}
|
||
|
||
const detailId = currentRow.value?.id
|
||
const systemProductId = selectedSystemProduct.value?.id
|
||
|
||
if (!detailId || !systemProductId) {
|
||
ElMessage.warning('缺少关联必要信息')
|
||
return
|
||
}
|
||
|
||
saveLoading.value = true
|
||
try {
|
||
const res: any = await receivingApi.bindDetailProduct({
|
||
detail_id: detailId,
|
||
system_product_id: systemProductId
|
||
})
|
||
|
||
if (res && (res.code === 200 || res.flag === 'success')) {
|
||
ElMessage.success(res.message || '关联成功')
|
||
quickLinkVisible.value = false
|
||
// 触发刷新列表
|
||
loadProductData()
|
||
} else {
|
||
ElMessage.error(res?.message || '关联失败')
|
||
}
|
||
} catch (e) {
|
||
console.error('confirmQuickLink error:', e)
|
||
ElMessage.error('关联过程中出错')
|
||
} finally {
|
||
saveLoading.value = false
|
||
}
|
||
}
|
||
|
||
const toggleFullscreen = () => {
|
||
isFullscreen.value = !isFullscreen.value
|
||
}
|
||
|
||
// 拖拽逻辑
|
||
const startDrag = (e: MouseEvent) => {
|
||
if (isFullscreen.value) return
|
||
isDragging.value = true
|
||
dragOffset.value = {
|
||
x: e.clientX - position.value.x,
|
||
y: e.clientY - position.value.y
|
||
}
|
||
window.addEventListener('mousemove', onDrag)
|
||
window.addEventListener('mouseup', stopDrag)
|
||
}
|
||
|
||
const onDrag = (e: MouseEvent) => {
|
||
if (!isDragging.value) return
|
||
position.value = {
|
||
x: Math.max(0, e.clientX - dragOffset.value.x),
|
||
y: Math.max(0, e.clientY - dragOffset.value.y)
|
||
}
|
||
}
|
||
|
||
const stopDrag = () => {
|
||
isDragging.value = false
|
||
window.removeEventListener('mousemove', onDrag)
|
||
window.removeEventListener('mouseup', stopDrag)
|
||
}
|
||
|
||
// 快速关联弹窗拖拽
|
||
const startQuickDrag = (e: MouseEvent) => {
|
||
if (isQuickFullscreen.value) return
|
||
isQuickDragging.value = true
|
||
quickDragOffset.value = {
|
||
x: e.clientX - quickPosition.value.x,
|
||
y: e.clientY - quickPosition.value.y
|
||
}
|
||
window.addEventListener('mousemove', onQuickDrag)
|
||
window.addEventListener('mouseup', stopQuickDrag)
|
||
}
|
||
|
||
const onQuickDrag = (e: MouseEvent) => {
|
||
if (!isQuickDragging.value) return
|
||
quickPosition.value = {
|
||
x: Math.max(0, e.clientX - quickDragOffset.value.x),
|
||
y: Math.max(0, e.clientY - quickDragOffset.value.y)
|
||
}
|
||
}
|
||
|
||
const stopQuickDrag = () => {
|
||
isQuickDragging.value = false
|
||
window.removeEventListener('mousemove', onQuickDrag)
|
||
window.removeEventListener('mouseup', stopQuickDrag)
|
||
}
|
||
|
||
const resetForm = () => {
|
||
if (activeWindowTab.value === 'basic' && basicRef.value) {
|
||
basicRef.value.reset?.()
|
||
}
|
||
}
|
||
|
||
const saveProductDetail = async () => {
|
||
if (activeWindowTab.value === 'basic' && basicRef.value) {
|
||
const updatedData = basicRef.value.getFormData?.()
|
||
if (updatedData) {
|
||
// 模拟本地修改 tableData
|
||
const index = tableData.value.findIndex(item => item.id === updatedData.id)
|
||
if (index !== -1) {
|
||
tableData.value[index] = { ...updatedData }
|
||
ElMessage.success('本地模拟修改成功')
|
||
windowVisible.value = false
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
const handleSave = async () => {
|
||
try {
|
||
saveLoading.value = true
|
||
// 模拟保存逻辑
|
||
await new Promise(resolve => setTimeout(resolve, 500))
|
||
ElMessage.success('保存成功')
|
||
} catch (error) {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saveLoading.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
if (props.productData && props.productData.length > 0) {
|
||
tableData.value = [...props.productData]
|
||
pagination.total = props.productTotal || props.productData.length
|
||
} else if (!props.loading) {
|
||
// 如果父组件没有传入商品数据且提供了 id,则尝试通过接口加载
|
||
if (props.id) {
|
||
fetchReceivingDetail()
|
||
}
|
||
}
|
||
window.addEventListener('click', closeMenu)
|
||
})
|
||
|
||
onUnmounted(() => {
|
||
window.removeEventListener('click', closeMenu)
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.product-details {
|
||
padding: 10px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
overflow: hidden;
|
||
background: #fff;
|
||
position: relative;
|
||
}
|
||
|
||
.product-window {
|
||
position: fixed;
|
||
z-index: 2000;
|
||
width: 1250px;
|
||
height: 700px;
|
||
background: #fff;
|
||
border: 1px solid #ebeef5;
|
||
box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.1);
|
||
border-radius: 4px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.product-window.is-fullscreen {
|
||
top: 0 !important;
|
||
left: 0 !important;
|
||
width: 100vw !important;
|
||
height: 100vh !important;
|
||
border-radius: 0;
|
||
z-index: 3000;
|
||
}
|
||
|
||
/* 遮罩层:阻止快速关联弹窗打开时对下层页面的交互 */
|
||
.modal-backdrop {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100vw;
|
||
height: 100vh;
|
||
background: rgba(0,0,0,0.18);
|
||
z-index: 2400;
|
||
}
|
||
|
||
/* 确保快速关联弹窗高于遮罩层 */
|
||
.product-window.quick-link-window {
|
||
z-index: 2500;
|
||
}
|
||
|
||
.window-header {
|
||
padding: 8px 12px;
|
||
background: #f5f7fa;
|
||
border-bottom: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
cursor: move;
|
||
user-select: none;
|
||
}
|
||
|
||
.window-title {
|
||
font-size: 14px;
|
||
font-weight: bold;
|
||
color: #303133;
|
||
}
|
||
|
||
.window-actions {
|
||
display: flex;
|
||
gap: 4px;
|
||
}
|
||
|
||
.window-body {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.window-tabs {
|
||
display: flex;
|
||
height: 40px;
|
||
background: #f5f7fa;
|
||
border-bottom: 1px solid #ebeef5;
|
||
padding: 0 10px;
|
||
}
|
||
|
||
.window-tabs .tab-item {
|
||
padding: 0 20px;
|
||
height: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
position: relative;
|
||
}
|
||
|
||
.window-tabs .tab-item:hover {
|
||
color: #409eff;
|
||
}
|
||
|
||
.window-tabs .tab-item.active {
|
||
color: #409eff;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.window-tabs .tab-item.active::after {
|
||
content: '';
|
||
position: absolute;
|
||
bottom: 0;
|
||
left: 0;
|
||
right: 0;
|
||
height: 2px;
|
||
background: #409eff;
|
||
}
|
||
|
||
.window-content {
|
||
display: flex;
|
||
flex: 1;
|
||
overflow: auto;
|
||
padding: 20px;
|
||
}
|
||
|
||
.window-footer {
|
||
height: 52px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
padding: 0 20px;
|
||
background: #fff;
|
||
border-top: 1px solid #ebeef5;
|
||
gap: 12px;
|
||
}
|
||
|
||
.quick-link-content {
|
||
padding: 20px;
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.search-section {
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.system-product-list {
|
||
flex: 1;
|
||
border: 1px solid #ebeef5;
|
||
border-radius: 4px;
|
||
background-color: #fafafa;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.clickable-row {
|
||
cursor: pointer;
|
||
}
|
||
|
||
.context-menu {
|
||
position: fixed;
|
||
z-index: 3000;
|
||
background: #fff;
|
||
border: 1px solid #ebeef5;
|
||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||
border-radius: 4px;
|
||
padding: 5px 0;
|
||
}
|
||
|
||
.menu-item {
|
||
padding: 8px 16px;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
cursor: pointer;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.menu-item:hover {
|
||
background-color: #f5f7fa;
|
||
color: #409eff;
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 8px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.left-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.left-col {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
padding-right: 8px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.left-col :deep(.upper-table-container) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.left-col :deep(.table-container) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: auto !important;
|
||
}
|
||
|
||
.left-col :deep(.pagination-container) {
|
||
flex-shrink: 0;
|
||
padding: 8px 0;
|
||
}
|
||
|
||
.right-col {
|
||
grid-column: 2 / 3;
|
||
grid-row: 2 / 3;
|
||
height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.right-panel {
|
||
position: sticky;
|
||
top: 20px;
|
||
background: #fff;
|
||
border-radius: 4px;
|
||
padding: 12px;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||
}
|
||
|
||
.panel-actions {
|
||
text-align: right;
|
||
}
|
||
|
||
.image-slot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
/* 商品入库状态样式 */
|
||
:deep(.el-table) {
|
||
.storage-status-tag {
|
||
font-weight: 500;
|
||
padding: 2px 8px;
|
||
border-radius: 3px;
|
||
display: inline-block;
|
||
}
|
||
|
||
/* 全部入库 - 绿色 */
|
||
.storage-status-all {
|
||
background-color: #f0f9ff;
|
||
color: #67C23A;
|
||
border: 1px solid #c6e2ff;
|
||
}
|
||
|
||
/* 部分入库 - 橙色 */
|
||
.storage-status-partial {
|
||
background-color: #fdf6ec;
|
||
color: #E6A23C;
|
||
border: 1px solid #f5dab1;
|
||
}
|
||
|
||
/* 未入库 - 灰色 */
|
||
.storage-status-none {
|
||
background-color: #f5f7fa;
|
||
color: #909399;
|
||
border: 1px solid #ebeef5;
|
||
}
|
||
}
|
||
</style>
|