1043 lines
30 KiB
Vue
1043 lines
30 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 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.stop="openAddDrawer(row)"
|
||
>添加商品</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="quick-link-content">
|
||
<el-alert title="请选择需要关联的系统商品" type="info" :closable="false" show-icon style="margin-bottom: 15px;" />
|
||
<!-- 这里可以放置商品搜索和选择列表 -->
|
||
<div class="search-section">
|
||
<el-form label-position="left" label-width="60px" class="search-form">
|
||
<el-form-item label="货主">
|
||
<el-input :value="quickLinkStore?.name || quickLinkStore?.store_remask || quickLinkStore?.store_name" disabled />
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-input v-model="quickSearchQuery" placeholder="输入商品名称或条码搜索" class="search-input">
|
||
<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;">
|
||
<el-table
|
||
:data="quickSearchResults"
|
||
v-loading="quickSearchLoading"
|
||
highlight-current-row
|
||
stripe
|
||
size="small"
|
||
:row-key="(row: { id: any }) => row.id"
|
||
@current-change="onSystemProductChange"
|
||
@row-click="onSystemProductChange"
|
||
:height="360"
|
||
style="width:100%"
|
||
:row-class-name="tableRowClassName"
|
||
>
|
||
<el-table-column prop="id" label="ID" width="80" />
|
||
<el-table-column prop="item_name" label="名称" show-overflow-tooltip />
|
||
<el-table-column prop="barcodes" label="条码" width="160" show-overflow-tooltip />
|
||
<el-table-column prop="store_name" label="货主" width="150" show-overflow-tooltip />
|
||
<template #empty>
|
||
<div style="padding:24px; text-align:center; color:#909399;">暂无系统商品数据,请搜索或关联</div>
|
||
</template>
|
||
</el-table>
|
||
|
||
<div class="pagination-container" style="padding:8px; text-align:right;">
|
||
<el-pagination
|
||
background
|
||
small
|
||
:current-page="quickResultPagination.page"
|
||
:page-size="quickResultPagination.pageSize"
|
||
:total="quickResultPagination.total"
|
||
@current-change="performQuickSearch"
|
||
@size-change="onQuickPageSizeChange"
|
||
layout="prev, pager, next, sizes, total"
|
||
:page-sizes="[10,20,50,100]"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="window-body-bottom">
|
||
<el-button size="small" @click="quickLinkVisible = false">取消</el-button>
|
||
<el-button size="small" type="primary" @click="confirmQuickLink" :disabled="!selectedSystemProduct">完成关联</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" :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-body-top">
|
||
<div
|
||
v-for="tab in windowtopbar"
|
||
:key="tab.key"
|
||
class="window-tab-item"
|
||
:class="{ active: activeWindowTab === tab.key }"
|
||
@click="activeWindowTab = tab.key"
|
||
>
|
||
{{ tab.label }}
|
||
</div>
|
||
</div>
|
||
<div class="window-body-middle">
|
||
<KeepAlive>
|
||
<component
|
||
:is="currentWindowComponent"
|
||
:row="currentRow"
|
||
ref="basicRef"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
<div class="window-body-bottom">
|
||
<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 mockProductData = [
|
||
// {
|
||
// id: 1,
|
||
// receiving_number: 'RCV202601180001',
|
||
// item_name: '商品A - 测试商品',
|
||
// barcodes: '6901234567890',
|
||
// product_snapshot: '{"id": null, "name": "商品A - 测试商品", "barcode": "6901234567890", "spec": "500g/袋"}',
|
||
// system_product_id: null,
|
||
// actual_quantity: 20,
|
||
// box_quantity: 2,
|
||
// boxes_per_pallet: 10,
|
||
// pallet_quantity: 0,
|
||
// receiving_time: '2026-01-18 22:43:42',
|
||
// receiving_status_display: '已完成',
|
||
// storage_status: '未入库',
|
||
// stored_quantity: 0,
|
||
// batch_number: 'BATCH20231215A',
|
||
// production_date: '2023-12-01',
|
||
// expiry_date: '2024-12-01',
|
||
// remark: '商品A测试明细 - 未匹配',
|
||
// box_length: 40,
|
||
// box_width: 30,
|
||
// box_height: 25,
|
||
// weight: 10.5,
|
||
// space_id: 'A-01-01',
|
||
// creator_id: 'EMP001',
|
||
// updated_at_display: '2026-01-18 22:43:42',
|
||
// created_at_display: '2026-01-18 22:43:42'
|
||
// },
|
||
// {
|
||
// id: 2,
|
||
// receiving_number: 'RCV202601180001',
|
||
// item_name: '商品B - 进口商品',
|
||
// barcodes: '8801234567890',
|
||
// product_snapshot: '{"id": null, "name": "商品B - 进口商品", "barcode": "8801234567890", "origin": "日本", "spec": "1kg/盒"}',
|
||
// system_product_id: null,
|
||
// actual_quantity: 15,
|
||
// box_quantity: 1,
|
||
// boxes_per_pallet: 15,
|
||
// pallet_quantity: 1,
|
||
// receiving_time: '2026-01-18 22:43:42',
|
||
// receiving_status_display: '已完成',
|
||
// storage_status: '未入库',
|
||
// stored_quantity: 0,
|
||
// batch_number: 'BATCH20231215B',
|
||
// production_date: '2023-11-15',
|
||
// expiry_date: '2024-11-15',
|
||
// remark: '商品B测试明细 - 未匹配',
|
||
// box_length: 50,
|
||
// box_width: 40,
|
||
// box_height: 30,
|
||
// weight: 15.0,
|
||
// space_id: 'B-02-05',
|
||
// creator_id: 'EMP001',
|
||
// updated_at_display: '2026-01-18 22:43:42',
|
||
// created_at_display: '2026-01-18 22:43:42'
|
||
// },
|
||
// {
|
||
// id: 3,
|
||
// receiving_number: 'RCV202601180001',
|
||
// item_name: '商品C - 电子商品',
|
||
// barcodes: '4901234567890',
|
||
// product_snapshot: '{"id": null, "name": "商品C - 电子商品", "barcode": "4901234567890", "brand": "索尼", "model": "X-100"}',
|
||
// system_product_id: 152656,
|
||
// actual_quantity: 15,
|
||
// box_quantity: 2,
|
||
// boxes_per_pallet: 8,
|
||
// pallet_quantity: 1,
|
||
// receiving_time: '2026-01-18 21:43:42',
|
||
// receiving_status_display: '已完成',
|
||
// storage_status: '部分入库',
|
||
// stored_quantity: 5,
|
||
// batch_number: 'BATCH20231215C',
|
||
// production_date: '2023-10-01',
|
||
// expiry_date: '2025-10-01',
|
||
// remark: '商品C测试明细 - 未匹配',
|
||
// box_length: 30,
|
||
// box_width: 20,
|
||
// box_height: 15,
|
||
// weight: 5.2,
|
||
// space_id: 'C-01-12',
|
||
// creator_id: 'EMP001',
|
||
// updated_at_display: '2026-01-18 22:43:42',
|
||
// created_at_display: '2026-01-18 22:43:42'
|
||
// },
|
||
// {
|
||
// id: 48,
|
||
// receiving_number: 'RCV2026020100002',
|
||
// item_name: 'MOODAMOR绮梦茉莉香型香水',
|
||
// barcodes: '6942233906190',
|
||
// product_snapshot: '{"store_id":1000166,"store_name":"花颜物语","updated_at":"2026-02-02T08:37:06.691Z"}',
|
||
// system_product_id: null,
|
||
// actual_quantity: 1000,
|
||
// box_quantity: 10,
|
||
// boxes_per_pallet: 100,
|
||
// pallet_quantity: 20,
|
||
// receiving_time: '2026-02-02 07:10:26',
|
||
// receiving_status_display: '收货中',
|
||
// storage_status: '未入库',
|
||
// stored_quantity: 0,
|
||
// batch_number: '20260202',
|
||
// production_date: '2025-12-01',
|
||
// expiry_date: '2028-12-01',
|
||
// remark: '1561534',
|
||
// box_length: 45,
|
||
// box_width: 35,
|
||
// box_height: 30,
|
||
// weight: 12.8,
|
||
// space_id: 'D-05-01',
|
||
// creator_id: 'EMP030',
|
||
// updated_at_display: '2026-02-02 13:24:43',
|
||
// created_at_display: '2026-02-02 07:10:26'
|
||
// }
|
||
// ]
|
||
|
||
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 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: any) => {
|
||
// 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
|
||
nextTick(() => {
|
||
if (addCompRef.value && addDrawerStore.value) {
|
||
try {
|
||
addCompRef.value.formData && (addCompRef.value.formData.store_id = addDrawerStore.value.id || addDrawerStore.value.store_id || addDrawerStore.value.storeId)
|
||
} catch (e) {}
|
||
}
|
||
})
|
||
}
|
||
|
||
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
|
||
// 重置位置或保持原位
|
||
position.value = { x: 350, y: 250 }
|
||
isFullscreen.value = false
|
||
}
|
||
closeMenu()
|
||
}
|
||
|
||
// 快速关联逻辑
|
||
const handleQuickLink = (row: any) => {
|
||
currentRow.value = row
|
||
quickLinkVisible.value = true
|
||
quickPosition.value = { x: 300, y: 150 }
|
||
isQuickFullscreen.value = false
|
||
quickSearchQuery.value = row.product_name || row.item_name || ''
|
||
// 优先使用商品行中可能包含的收货单货主(例如 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 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 = () => {
|
||
if (!selectedSystemProduct.value) {
|
||
ElMessage.warning('请先选择一个系统商品')
|
||
return
|
||
}
|
||
try {
|
||
// 将选择的系统商品信息写回当前行(仅本地映射,真实业务可能需要调用接口)
|
||
currentRow.value.system_product_id = selectedSystemProduct.value.id
|
||
currentRow.value.system_product = selectedSystemProduct.value
|
||
ElMessage.success('关联成功')
|
||
quickLinkVisible.value = false
|
||
} catch (e) {
|
||
console.error(e)
|
||
ElMessage.error('关联失败')
|
||
}
|
||
}
|
||
|
||
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: 650px;
|
||
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;
|
||
overflow: auto;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.window-body-top {
|
||
display: flex;
|
||
flex-direction: row;
|
||
justify-content: flex-start;
|
||
background-color: #f5f7fa;
|
||
width: 100%;
|
||
height: 35px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
}
|
||
|
||
.window-tab-item {
|
||
padding: 0 20px;
|
||
height: 100%;
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
border-right: 1px solid transparent;
|
||
}
|
||
|
||
.window-tab-item:hover {
|
||
color: #409eff;
|
||
background-color: #ecf5ff;
|
||
}
|
||
|
||
.window-tab-item.active {
|
||
color: #409eff;
|
||
background-color: #fff;
|
||
font-weight: bold;
|
||
border-right: 1px solid #ebeef5;
|
||
border-left: 1px solid #ebeef5;
|
||
}
|
||
|
||
.window-tab-item.active:first-child {
|
||
border-left: none;
|
||
}
|
||
|
||
.window-body-middle {
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
overflow: auto;
|
||
padding: 15px;
|
||
/* background-color: yellow; */
|
||
}
|
||
.window-body-bottom {
|
||
display: flex;
|
||
flex-direction: row;
|
||
width: 100%;
|
||
height: 40px;
|
||
background-color: rgb(235, 235, 235);
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.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>
|