WEB/src/views/storage/receiving/component/DetailsPanel.vue
2026-04-04 18:11:20 +08:00

322 lines
9.2 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.

<template>
<div class="receiving-details-container">
<el-form :model="form" label-width="120px" class="details-form">
<el-row :gutter="30">
<!-- 第一列:收货明细 -->
<el-col :span="12">
<el-form-item
v-for="field in detailpanel"
:key="field.prop"
:label="field.label"
:prop="field.prop"
>
<!-- 特殊处理:货主行,显示下拉并在右侧增加绑定按钮 -->
<template v-if="field.prop === 'store_name'">
<div style="display:flex; gap:8px; align-items:center;">
<el-select
v-model="form.store_id"
:placeholder="'请选择' + field.label"
style="flex:1"
:disabled="field.disabled || storeBound"
filterable
>
<el-option
v-for="item in (availableFields.find(f => f.value === 'store_id')?.options || [])"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-button size="small" type="primary" @click="handleBindStore">货主绑定</el-button>
</div>
</template>
<template v-else-if="field.type === 'select'">
<el-select
v-model="(form as any)[field.prop]"
:placeholder="'请选择' + field.label"
style="width: 100%"
>
<el-option
v-for="item in availableFields.find(f => f.value === field.prop)?.options || []"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</template>
<template v-else>
<el-input
v-model="(form as any)[field.prop]"
:disabled="field.disabled"
:placeholder="'请输入' + field.label"
/>
</template>
</el-form-item>
</el-col>
<!-- 第二列:收货图片 -->
<el-col :span="12">
<div class="receiving-images">
<div v-if="imagesArr.length > 0" class="images-grid">
<div v-for="(src, idx) in imagesArr" :key="idx" class="img-cell" @click="handlePreview(src)">
<el-image :src="src" fit="cover" style="width:100%; height:100%" />
</div>
</div>
<div v-else class="image-placeholder">
<div class="placeholder-content">
<el-icon :size="48" color="#909399"><Picture /></el-icon>
<p>暂无收货图片</p>
</div>
</div>
</div>
</el-col>
</el-row>
</el-form>
<!-- 底部操作按钮 -->
<div class="bottom">
<el-button-group class="toolbar-btn-group">
<el-button type="primary" icon="Check" @click="handleSave" :loading="saveLoading">
保存
</el-button>
<el-button type="danger" icon="Refresh" @click="handleReset">
重置
</el-button>
</el-button-group>
</div>
<!-- 图片预览对话框 -->
<el-dialog v-model="previewVisible" title="图片预览" width="60%" append-to-body>
<img :src="dialogImageUrl" alt="预览" style="width: 100%; max-height: 70vh; object-fit: contain;" />
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, watch, computed } from 'vue'
import { availableFields, detailpanel } from '../receiving-config'
import { ElMessage, ElMessageBox } from 'element-plus'
import * as receivingApi from '@/api/storage/receiving'
import { Picture, Check, Refresh } from '@element-plus/icons-vue'
const props = defineProps<{
id: string | number,
row?: any
}>()
const form = ref({
receiving_number: '',
store_name: '',
store_id: '',
detail_status: '',
creator_name: '',
delivery_method: '',
status: '',
loading_method: '',
total_items: 0,
total_quantity: 0,
total_boxes: 0,
total_pallets: 0,
remark: ''
})
const saveLoading = ref(false)
const handleSave = async () => {
try {
saveLoading.value = true
// 这里可以调用接口保存数据
ElMessage.success('保存成功')
} catch (error) {
ElMessage.error('保存失败')
} finally {
saveLoading.value = false
}
}
const handleReset = () => {
if (props.row) {
form.value = { ...props.row }
// normalize store id/name
form.value.store_id = props.row.store?.id || props.row.store_id || ''
form.value.store_name = props.row.store?.store_remask || props.row.store_name || form.value.store_name
}
ElMessage.info('表单已重置')
}
// 图片预览
const dialogImageUrl = ref('')
const previewVisible = ref(false)
const imagesArr = computed(() => {
const r = props.row || {}
const imgs = r.images || []
if (!Array.isArray(imgs)) return []
return imgs.map((it: any) => {
if (!it) return ''
if (typeof it === 'string') return it
return it.file_url || it.url || it.path || ''
}).filter((s: string) => !!s)
})
// 绑定状态:绑定后不可更改
const storeBound = ref(false)
// 触发绑定流程
const handleBindStore = async () => {
const storeId = form.value.store_id
const receivingId = props.id || props.row?.id
if (!storeId) {
ElMessage.warning('请先选择货主')
return
}
if (!receivingId) {
ElMessage.warning('缺少收货单ID,无法绑定')
return
}
const status = props.row?.status
const hasStore = !!(props.row && (props.row.store || props.row.store_id))
// 拒绝条件:取消状态始终拒绝;收货中/已完成且已有货主也拒绝
if (status === 'cancelled') {
ElMessage.error('取消状态的收货单无法绑定货主')
return
}
if ((status === 'receiving' || status === 'completed') && hasStore) {
ElMessage.error('当前状态下已有货主,无法绑定')
return
}
// 询问确认
try {
await ElMessageBox.confirm(`将货主绑定为:${getStoreLabel(storeId)}?绑定后不可更改。是否继续?`, '确认绑定', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
// 调用后端接口
const payload = { receiving_id: receivingId, store_id: storeId }
const res: any = await receivingApi.bindReceivingStore(payload)
if (res && (res.code === 200 || res.flag === 'success')) {
ElMessage.success(res.message || '绑定成功')
storeBound.value = true
// update local form and optionally props.row
form.value.store_name = getStoreLabel(storeId)
if (props.row) {
props.row.store = props.row.store || {}
props.row.store.id = storeId
props.row.store.store_remask = form.value.store_name
props.row.store_id = storeId
}
} else {
ElMessage.error((res && res.message) || '绑定失败')
}
} catch (e: any) {
// 取消或错误
if (e === 'cancel') return
console.error('bind store error', e)
ElMessage.error('绑定过程中出错')
}
}
const getStoreLabel = (id: any) => {
const opts = (availableFields.find(f => f.value === 'store_id') || {}).options || []
const found = opts.find((o: any) => o.value === id)
return found ? found.label : String(id)
}
const handlePreview = (src: string) => {
dialogImageUrl.value = src
previewVisible.value = true
}
// 监听 row 变化,更新表单数据
watch(() => props.row, (newRow) => {
if (newRow) {
form.value = { ...newRow }
form.value.store_id = newRow.store?.id || newRow.store_id || ''
form.value.store_name = newRow.store?.store_remask || newRow.store_name || form.value.store_name
// 如果后端或数据表明已经绑定,设置 storeBound(保守:如果 row.bound === true)
storeBound.value = !!(newRow.bound === true)
}
}, { immediate: true })
onMounted(() => {
if (props.row) {
form.value = { ...props.row }
}
})
</script>
<style scoped lang="scss">
.receiving-details-container {
height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
background-color: #fff;
}
.details-form {
flex: 1;
overflow-y: auto;
padding: 20px;
width: 100%;
box-sizing: border-box;
/* 隐藏滚动条 */
&::-webkit-scrollbar {
display: none;
}
-ms-overflow-style: none;
scrollbar-width: none;
}
.image-placeholder {
width: 100%;
height: 400px;
background-color: #f5f7fa;
border: 1px dashed #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
.placeholder-content {
text-align: center;
color: #909399;
p {
margin-top: 10px;
font-size: 14px;
}
}
}
.receiving-images {
.images-grid {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.img-cell {
width: 100px;
height: 100px;
border: 1px solid #eef2f6;
border-radius: 4px;
overflow: hidden;
cursor: pointer;
background-color: #fff;
}
}
.bottom {
flex-shrink: 0;
text-align: right;
padding: 0px 20px;
border-top: 1px solid #ebeef5;
background-color: #fff;
z-index: 10;
}
</style>