164 lines
4.7 KiB
Vue
164 lines
4.7 KiB
Vue
<template>
|
|
<el-dialog
|
|
title="编辑仓位"
|
|
v-model="internalVisible"
|
|
width="500px"
|
|
@close="handleClose"
|
|
>
|
|
<el-form
|
|
ref="formRef"
|
|
:model="formData"
|
|
:rules="rules"
|
|
label-width="100px"
|
|
size="small"
|
|
>
|
|
<el-form-item label="仓位编码">
|
|
<el-input v-model="formData.space_code" disabled />
|
|
</el-form-item>
|
|
|
|
<el-form-item label="位置">
|
|
<div class="position-display">
|
|
列{{ props.space.column_no }} 层{{ props.space.row_no }} 格{{ props.space.level_no }}
|
|
</div>
|
|
</el-form-item>
|
|
|
|
<el-form-item label="尺寸">
|
|
<div class="dimension-display">
|
|
<div>长: {{ props.space.length || '未设置' }}cm</div>
|
|
<div>宽: {{ props.space.width || '未设置' }}cm</div>
|
|
<div>高: {{ props.space.height || '未设置' }}cm</div>
|
|
</div>
|
|
</el-form-item>
|
|
|
|
<el-form-item label="仓位状态" prop="space_status">
|
|
<el-select
|
|
v-model="formData.space_status"
|
|
placeholder="请选择状态"
|
|
style="width: 100%"
|
|
>
|
|
<el-option
|
|
v-for="item in statusOptions"
|
|
:key="item.value"
|
|
:label="item.label"
|
|
:value="item.value"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
|
|
<el-form-item label="是否启用" prop="is_enabled">
|
|
<el-switch
|
|
v-model="formData.is_enabled"
|
|
:active-value="1"
|
|
:inactive-value="0"
|
|
/>
|
|
</el-form-item>
|
|
|
|
<el-form-item label="自定义名称">
|
|
<el-input
|
|
v-model="formData.custom_name"
|
|
placeholder="可选"
|
|
maxlength="100"
|
|
/>
|
|
</el-form-item>
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
<el-button @click="handleClose">取消</el-button>
|
|
<el-button type="primary" @click="handleSubmit" :loading="saving">保存</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, reactive, watch } from 'vue'
|
|
import * as spaceApi from '@/api/warehouse/warehouse'
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
const props = defineProps({
|
|
visible: { type: Boolean, default: false },
|
|
space: { type: Object, required: true }
|
|
})
|
|
|
|
const emit = defineEmits(['close', 'saved'])
|
|
|
|
const internalVisible = ref(props.visible)
|
|
|
|
watch(() => props.visible, (nv) => { internalVisible.value = nv }, { immediate: true })
|
|
watch(internalVisible, (v) => { if (!v) emit('close') })
|
|
|
|
const formRef = ref(null)
|
|
const saving = ref(false)
|
|
|
|
const formData = reactive<any>({
|
|
id: null,
|
|
space_code: '',
|
|
custom_name: '',
|
|
custom_barcode: '',
|
|
space_status: 'AVAILABLE',
|
|
is_enabled: 1
|
|
})
|
|
|
|
const rules = {
|
|
space_status: [
|
|
{ required: true, message: '请选择状态', trigger: 'change' }
|
|
]
|
|
}
|
|
|
|
const statusOptions = [
|
|
{ value: 'AVAILABLE', label: '可用' },
|
|
{ value: 'OCCUPIED', label: '已占用' },
|
|
{ value: 'RESERVED', label: '已预留' },
|
|
{ value: 'MAINTENANCE', label: '维护中' },
|
|
{ value: 'DISABLED', label: '已禁用' }
|
|
]
|
|
|
|
watch(() => props.space, (newSpace) => {
|
|
if (newSpace) {
|
|
formData.id = newSpace.id
|
|
formData.space_code = newSpace.space_code
|
|
formData.custom_name = newSpace.custom_name || ''
|
|
formData.custom_barcode = newSpace.custom_barcode || ''
|
|
formData.space_status = newSpace.space_status
|
|
formData.is_enabled = newSpace.is_enabled ? 1 : 0
|
|
}
|
|
}, { immediate: true })
|
|
|
|
function handleClose() { emit('close') }
|
|
|
|
async function handleSubmit() {
|
|
try {
|
|
const valid = await (formRef.value as any).validate().catch(() => false)
|
|
if (!valid) return
|
|
|
|
saving.value = true
|
|
const response: any = await spaceApi.update(formData, formData.id)
|
|
if (response.code === 200) {
|
|
ElMessage.success('保存成功')
|
|
emit('saved')
|
|
} else {
|
|
ElMessage.error(response.message || '保存失败')
|
|
}
|
|
} catch (error) {
|
|
ElMessage.error('保存失败')
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.position-display {
|
|
display: flex;
|
|
gap: 16px;
|
|
font-size: 14px;
|
|
color: #606266;
|
|
}
|
|
|
|
.dimension-display {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
font-size: 14px;
|
|
color: #606266;
|
|
}
|
|
</style> |