813 lines
27 KiB
Vue
813 lines
27 KiB
Vue
<template>
|
||
<div class="upper-table-container">
|
||
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px" :disabled="loading">
|
||
<!-- 货主 -->
|
||
<el-form-item label="货主" prop="store_id" title="商品归属货主">
|
||
<el-select v-model="formData.store_id" filterable clearable style="width: 100%;" placeholder="请选择货主">
|
||
<el-option v-for="option in stores" :key="option.value" :label="option.label" :value="option.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
|
||
<!-- 商品名称 -->
|
||
<el-form-item label="商品名称" prop="item_name">
|
||
<el-input v-model="formData.item_name" placeholder="请输入商品名称" clearable />
|
||
</el-form-item>
|
||
|
||
<!-- 商品编码 -->
|
||
<el-form-item label="商品编码" prop="item_code" title="外部系统唯一商品编码,推送商品资料时一致自动绑定">
|
||
<el-input v-model="formData.item_code" placeholder="请输入商品编码" clearable />
|
||
</el-form-item>
|
||
|
||
<el-form-item label="条码" prop="barcode">
|
||
<el-input v-model="formData.barcode" placeholder="请输入条码" clearable />
|
||
</el-form-item>
|
||
|
||
<!-- 品牌 -->
|
||
<el-form-item label="品牌" prop="brand_name">
|
||
<el-input v-model="formData.brand_name" placeholder="请输入商品品牌" clearable />
|
||
</el-form-item>
|
||
|
||
<!-- SKU规格 -->
|
||
<el-form-item label="SKU规格" prop="sku_property" title="方便拣货快速按特征找货">
|
||
<el-input v-model="formData.sku_property" placeholder="颜色/容量" clearable />
|
||
</el-form-item>
|
||
|
||
<!-- 违禁品类型 -->
|
||
<el-form-item label="违禁品类型" prop="prohibited_id">
|
||
<div class="select-with-button">
|
||
<el-select v-model="formData.prohibited_id" filterable clearable style="width: 100%;" placeholder="请选择违禁品类型"
|
||
@change="handleCustomChange">
|
||
<el-option v-for="option in prohibitedTypes" :key="option.value" :label="option.label"
|
||
:value="option.value" />
|
||
</el-select>
|
||
<el-button :icon="Plus" circle size="small" @click="openProhibitedDrawer" title="管理违禁品类型" />
|
||
</div>
|
||
</el-form-item>
|
||
|
||
<!-- 库存单位 -->
|
||
<el-form-item label="库存单位" prop="stock_unit">
|
||
<div class="select-with-button">
|
||
<el-select v-model="formData.stock_unit" filterable clearable style="width: 100%;" placeholder="请选择库存单位">
|
||
<el-option v-for="unit in stockUnits" :key="unit.value" :label="unit.label" :value="unit.value" />
|
||
</el-select>
|
||
<el-button :icon="Plus" circle size="small" @click="openUnitDrawer" title="管理库存单位" />
|
||
</div>
|
||
</el-form-item>
|
||
|
||
<!-- 价格信息 -->
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="标价(¥)" prop="tag_price">
|
||
<el-input-number v-model="formData.tag_price" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="零售价(¥)" prop="retail_price">
|
||
<el-input-number v-model="formData.retail_price" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 重量信息 -->
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="毛重(g)" prop="gross_weight">
|
||
<el-input-number v-model="formData.gross_weight" :min="0" :precision="0" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="净重(g)" prop="net_weight">
|
||
<el-input-number v-model="formData.net_weight" :min="0" :precision="0" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 管理标识 -->
|
||
<el-form-item label="管理标识">
|
||
<el-checkbox-group v-model="formData.managementFlags" class="management-flags">
|
||
<el-checkbox label="is_sn_mgmt" title="开启后商品执行一物一码出库,不能进团购波次,打包需要扫描商品SN码">序列号管理</el-checkbox>
|
||
<el-checkbox label="is_shelf_life_mgmt">保质期管理</el-checkbox>
|
||
<el-checkbox label="is_batch_mgmt">批次管理</el-checkbox>
|
||
</el-checkbox-group>
|
||
</el-form-item>
|
||
|
||
<!-- 尺寸信息卡片 -->
|
||
<div class="info-card">
|
||
<div class="card-header">
|
||
<h4>尺寸信息</h4>
|
||
</div>
|
||
|
||
<el-row :gutter="10">
|
||
<el-col :span="8">
|
||
<el-form-item label="长度(cm)" prop="length">
|
||
<el-input-number v-model="formData.length" :min="0" :precision="2" :controls="false" style="width: 100%"
|
||
@change="calculateVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="宽度(cm)" prop="width">
|
||
<el-input-number v-model="formData.width" :min="0" :precision="2" :controls="false" style="width: 100%"
|
||
@change="calculateVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="高度(cm)" prop="height">
|
||
<el-input-number v-model="formData.height" :min="0" :precision="2" :controls="false" style="width: 100%"
|
||
@change="calculateVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-form-item label="体积(cm³)" prop="volume">
|
||
<el-input-number v-model="formData.volume" :min="0" :precision="0" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<!-- 箱规信息卡片 -->
|
||
<div class="info-card">
|
||
<div class="card-header">
|
||
<h4>箱规信息</h4>
|
||
<el-tooltip content="箱规信息用于整箱入库、出库和库存管理" placement="top">
|
||
<el-icon>
|
||
<InfoFilled />
|
||
</el-icon>
|
||
</el-tooltip>
|
||
</div>
|
||
|
||
<!-- 是否启用箱规 -->
|
||
<el-form-item label="启用箱规" prop="enable_box_spec">
|
||
<el-switch v-model="formData.enable_box_spec" active-text="是" inactive-text="否"
|
||
@change="handleBoxSpecToggle" />
|
||
</el-form-item>
|
||
|
||
<div v-if="formData.enable_box_spec">
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="每箱数量" prop="quantity_per_box">
|
||
<el-input-number v-model="formData.quantity_per_box" :min="1" :precision="0" :controls="false"
|
||
style="width: 100%" placeholder="每箱数量" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 箱规重量 -->
|
||
<el-row :gutter="10">
|
||
<el-col :span="12">
|
||
<el-form-item label="箱毛重(g)" prop="box_gross_weight">
|
||
<el-input-number v-model="formData.box_gross_weight" :min="0" :precision="0" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="箱净重(g)" prop="box_net_weight">
|
||
<el-input-number v-model="formData.box_net_weight" :min="0" :precision="0" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 箱规尺寸 -->
|
||
<el-row :gutter="10">
|
||
<el-col :span="8">
|
||
<el-form-item label="箱长(cm)" prop="box_length">
|
||
<el-input-number v-model="formData.box_length" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" @change="calculateBoxVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="箱宽(cm)" prop="box_width">
|
||
<el-input-number v-model="formData.box_width" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" @change="calculateBoxVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="箱高(cm)" prop="box_height">
|
||
<el-input-number v-model="formData.box_height" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" @change="calculateBoxVolume" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 箱体积 -->
|
||
<el-form-item label="箱体积(m³)" prop="box_volume">
|
||
<el-input-number v-model="formData.box_volume" :min="0" :precision="2" :controls="false"
|
||
style="width: 100%" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 打包要求卡片 -->
|
||
<div class="info-card">
|
||
<div class="card-header">
|
||
<h4>打包要求</h4>
|
||
<el-tooltip content="复核流程和打包流程可见包装要求" placement="top">
|
||
<el-icon>
|
||
<InfoFilled />
|
||
</el-icon>
|
||
</el-tooltip>
|
||
</div>
|
||
|
||
<el-form-item prop="packing_requirements" label-width="0">
|
||
<el-input v-model="formData.packing_requirements" type="textarea" :rows="4" placeholder="请输入打包要求" clearable />
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
|
||
<!-- 底部操作按钮 -->
|
||
<div class="bottom">
|
||
<el-button-group class="toolbar-btn-group">
|
||
<el-button type="primary" size="small" :icon="Check" @click="handleSave" title="保存">保存</el-button>
|
||
<el-button type="danger" size="small" :icon="Refresh" @click="resetForm" title="重置">重置</el-button>
|
||
</el-button-group>
|
||
</div>
|
||
|
||
<!-- 单位管理抽屉 -->
|
||
<el-drawer v-model="unitDrawerVisible" title="单位管理" :append-to-body="true" size="500px">
|
||
<div class="drawer-content">
|
||
<div class="input-box" style="margin-bottom: 20px; display: flex; gap: 10px;">
|
||
<el-input v-model="newUnitName" placeholder="请输入单位名称" clearable @keyup.enter="addUnit" />
|
||
<el-button type="primary" @click="addUnit">添加</el-button>
|
||
</div>
|
||
<el-table :data="unitList" style="width: 100%" height="400px" border stripe>
|
||
<el-table-column prop="name" label="单位名称" />
|
||
<el-table-column label="操作" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-button type="danger" link size="small" @click="deleteUnit(row.id)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-drawer>
|
||
|
||
<!-- 违禁品管理抽屉 -->
|
||
<el-drawer v-model="prohibitedDrawerVisible" title="违禁品类型管理" :append-to-body="true" size="500px">
|
||
<div class="drawer-content">
|
||
<div class="input-box" style="margin-bottom: 20px; display: flex; flex-direction: column; gap: 10px;">
|
||
<el-input v-model="newProhibitedName" placeholder="请输入违禁品类型名称" clearable />
|
||
<el-select v-model="newProhibitedLevel" placeholder="请选择危险等级">
|
||
<el-option label="一级" :value="1" />
|
||
<el-option label="二级" :value="2" />
|
||
<el-option label="三级" :value="3" />
|
||
</el-select>
|
||
<el-button type="primary" @click="addProhibited">添加</el-button>
|
||
</div>
|
||
<el-table :data="prohibitedList" style="width: 100%" height="400px" border stripe>
|
||
<el-table-column prop="name" label="类型名称" />
|
||
<el-table-column prop="danger_level" label="危险等级" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.danger_level === 3 ? 'danger' : row.danger_level === 2 ? 'warning' : 'info'">
|
||
{{ getDangerLevelText(row.danger_level) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-button type="danger" link size="small" @click="deleteProhibited(row.id)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-drawer>
|
||
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, watch, onMounted, nextTick } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Check, Refresh, InfoFilled, Plus } from '@element-plus/icons-vue'
|
||
import * as stockApi from '@/api/stock'
|
||
|
||
const props = defineProps({
|
||
id: {
|
||
type: Number,
|
||
default: null
|
||
},
|
||
prohibited_type: {
|
||
type: Array as () => any[],
|
||
default: () => []
|
||
},
|
||
stores: {
|
||
type: Array as () => any[],
|
||
default: () => []
|
||
}
|
||
})
|
||
|
||
const emit = defineEmits(['saved', 'update-prohibited-types'])
|
||
|
||
// Refs
|
||
const formRef = ref()
|
||
|
||
// State
|
||
const loading = ref(false)
|
||
const prohibitedTypes = ref<any[]>([])
|
||
const stockUnits = ref<any[]>([])
|
||
const unitDrawerVisible = ref(false)
|
||
const prohibitedDrawerVisible = ref(false)
|
||
const unitList = ref<any[]>([])
|
||
const prohibitedList = ref<any[]>([])
|
||
const newUnitName = ref('')
|
||
const newProhibitedName = ref('')
|
||
const newProhibitedLevel = ref(1)
|
||
|
||
const formData = reactive({
|
||
item_code: '',
|
||
store_id: undefined as number | undefined,
|
||
barcode: '',
|
||
item_name: '',
|
||
sku_property: '',
|
||
stock_unit: '',
|
||
packing_requirements: '',
|
||
length: 0.00,
|
||
width: 0.00,
|
||
height: 0.00,
|
||
volume: 0.00,
|
||
gross_weight: 0,
|
||
net_weight: 0,
|
||
tag_price: 0.00,
|
||
retail_price: 0.00,
|
||
is_sn_mgmt: 'N',
|
||
is_shelf_life_mgmt: 'N',
|
||
is_batch_mgmt: 'N',
|
||
prohibited_id: undefined as number | undefined,
|
||
brand_name: '',
|
||
managementFlags: [] as string[],
|
||
// Box specs
|
||
enable_box_spec: false,
|
||
quantity_per_box: 0,
|
||
box_gross_weight: 0,
|
||
box_net_weight: 0,
|
||
box_length: 0.00,
|
||
box_width: 0.00,
|
||
box_height: 0.00,
|
||
box_volume: 0.00,
|
||
box_unit: ''
|
||
})
|
||
|
||
const originalData = reactive({})
|
||
|
||
// Validators
|
||
const lastItemCode = ref('')
|
||
const itemCodeError = ref('')
|
||
|
||
const validateItemCode = async (rule: any, value: any, callback: any) => {
|
||
if (value === lastItemCode.value) {
|
||
if (itemCodeError.value) {
|
||
callback(new Error(itemCodeError.value))
|
||
} else {
|
||
callback()
|
||
}
|
||
return
|
||
}
|
||
|
||
lastItemCode.value = value
|
||
|
||
if (!value || value.trim() === '') {
|
||
itemCodeError.value = "商品编码不能为空"
|
||
callback(new Error(itemCodeError.value))
|
||
return
|
||
}
|
||
|
||
const pattern = /^[A-Za-z0-9_-]+$/
|
||
if (!pattern.test(value)) {
|
||
itemCodeError.value = "商品编码只能包含字母、数字、下划线和短横线"
|
||
callback(new Error(itemCodeError.value))
|
||
return
|
||
}
|
||
|
||
if (value.length > 20) {
|
||
itemCodeError.value = "条码长度不能超过20个字符"
|
||
callback(new Error(itemCodeError.value))
|
||
return
|
||
}
|
||
|
||
if (!formData.store_id) {
|
||
// Store ID required for uniqueness check usually, but let's proceed or wait
|
||
}
|
||
|
||
try {
|
||
const response = await stockApi.checkItemCodeUnique({
|
||
store_id: formData.store_id,
|
||
item_code: formData.item_code.trim()
|
||
})
|
||
|
||
if (response && (response as any).code == 200) {
|
||
const data = (response as any).data
|
||
if (data.isUnique) {
|
||
itemCodeError.value = ""
|
||
callback()
|
||
} else {
|
||
itemCodeError.value = data.message || "条码已存在"
|
||
callback(new Error(itemCodeError.value))
|
||
}
|
||
} else {
|
||
itemCodeError.value = "检测条码唯一性失败"
|
||
callback(new Error(itemCodeError.value))
|
||
}
|
||
} catch (e) {
|
||
itemCodeError.value = "检测条码唯一性失败"
|
||
callback(new Error(itemCodeError.value))
|
||
}
|
||
}
|
||
|
||
const formRules = {
|
||
store_id: [{ required: true, message: '货主不能为空', trigger: 'change' }],
|
||
barcode: [{ required: true, message: '条码不能为空', trigger: 'blur' }],
|
||
item_code: [{ validator: validateItemCode, trigger: 'blur' }],
|
||
item_name: [{ required: true, message: '商品名称不能为空', trigger: 'blur' }],
|
||
stock_unit: [{ required: true, message: '库存单位不能为空', trigger: 'change' }],
|
||
gross_weight: [
|
||
{ required: true, message: '毛重不能为空', trigger: 'blur' },
|
||
{
|
||
validator: (rule: any, value: any, callback: any) => {
|
||
if (value < 0) callback(new Error('毛重不能小于0'))
|
||
else callback()
|
||
},
|
||
trigger: 'blur'
|
||
}
|
||
],
|
||
quantity_per_box: [
|
||
{
|
||
validator: (rule: any, value: any, callback: any) => {
|
||
if (formData.enable_box_spec && (!value || value <= 0)) {
|
||
callback(new Error('每箱数量必须大于0'))
|
||
} else {
|
||
callback()
|
||
}
|
||
},
|
||
trigger: 'blur'
|
||
}
|
||
]
|
||
}
|
||
|
||
// Methods
|
||
const totalVolume = (length: number, width: number, height: number) => {
|
||
return parseFloat(((length * width * height) / 1000000).toFixed(6)) // Assuming input in cm, output in m3? Or input cm output cm3?
|
||
// Vue 2 code: (this.formData.length / 100) * (this.formData.width / 100) * (this.formData.height / 100) => cubic meters
|
||
// But precision is 2? Let's follow Vue 2 logic exactly.
|
||
}
|
||
|
||
const calculateVolume = () => {
|
||
if (formData.length && formData.width && formData.height) {
|
||
const volume = (formData.length / 100) * (formData.width / 100) * (formData.height / 100)
|
||
formData.volume = parseFloat(volume.toFixed(6)) // Vue 2 used toFixed(2) but that seems too small for m3 if dimensions are small
|
||
}
|
||
}
|
||
|
||
const calculateBoxVolume = () => {
|
||
if (formData.box_length && formData.box_width && formData.box_height) {
|
||
const volume = (formData.box_length / 100) * (formData.box_width / 100) * (formData.box_height / 100)
|
||
formData.box_volume = parseFloat(volume.toFixed(6))
|
||
}
|
||
}
|
||
|
||
const updateManagementFlags = () => {
|
||
const flags = []
|
||
if (formData.is_sn_mgmt === 'Y') flags.push('is_sn_mgmt')
|
||
if (formData.is_shelf_life_mgmt === 'Y') flags.push('is_shelf_life_mgmt')
|
||
if (formData.is_batch_mgmt === 'Y') flags.push('is_batch_mgmt')
|
||
formData.managementFlags = flags
|
||
}
|
||
|
||
const handleBoxSpecToggle = (value: any) => {
|
||
if (value) {
|
||
if (!formData.box_unit) formData.box_unit = '箱'
|
||
if (!formData.quantity_per_box) formData.quantity_per_box = 1
|
||
} else {
|
||
nextTick(() => {
|
||
formData.box_unit = ''
|
||
formData.quantity_per_box = 0
|
||
formData.box_gross_weight = 0
|
||
formData.box_net_weight = 0
|
||
formData.box_length = 0.00
|
||
formData.box_width = 0.00
|
||
formData.box_height = 0.00
|
||
formData.box_volume = 0.00
|
||
})
|
||
}
|
||
}
|
||
|
||
const prepareSaveData = () => {
|
||
const data = { ...formData }
|
||
if (!data.enable_box_spec) {
|
||
data.box_unit = ''
|
||
data.quantity_per_box = 0
|
||
data.box_gross_weight = 0
|
||
data.box_net_weight = 0
|
||
data.box_length = 0.00
|
||
data.box_width = 0.00
|
||
data.box_height = 0.00
|
||
data.box_volume = 0.00
|
||
}
|
||
return data
|
||
}
|
||
|
||
const handleSave = async () => {
|
||
if (!formRef.value) return
|
||
|
||
await formRef.value.validate(async (valid: boolean) => {
|
||
if (valid) {
|
||
loading.value = true
|
||
try {
|
||
const saveData = prepareSaveData()
|
||
const response = await stockApi.createWarehouseStock(saveData)
|
||
if (response && (response as any).code == 200) {
|
||
ElMessage.success('保存成功')
|
||
emit('saved')
|
||
resetForm()
|
||
} else {
|
||
throw new Error((response as any).message || '请求失败')
|
||
}
|
||
} catch (error: any) {
|
||
console.error('保存商品信息失败:', error)
|
||
ElMessage.error(error.message || '保存商品信息失败')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
} else {
|
||
ElMessage.warning('请检查表单填写是否正确')
|
||
}
|
||
})
|
||
}
|
||
|
||
const resetForm = () => {
|
||
lastItemCode.value = ''
|
||
if (formRef.value) {
|
||
formRef.value.resetFields()
|
||
}
|
||
// Reset non-form fields if any or complex reset logic
|
||
formData.managementFlags = []
|
||
formData.enable_box_spec = false
|
||
handleBoxSpecToggle(false)
|
||
|
||
// Restore original data if needed (Vue 2 logic had originalData)
|
||
// Object.assign(formData, originalData)
|
||
ElMessage.info('表单已重置')
|
||
}
|
||
|
||
const handleCustomChange = (value: any) => {
|
||
console.log('违禁品类型变更:', value)
|
||
}
|
||
|
||
// Unit Management
|
||
const loadStockUnits = async () => {
|
||
try {
|
||
const response = await stockApi.getStockUnits() // Vue 2 had { warehouse_id: null, include_system: true }
|
||
if (response && (response as any).code === 200) {
|
||
stockUnits.value = (response as any).data.map((item: any) => ({
|
||
value: item.name,
|
||
label: item.name
|
||
}))
|
||
}
|
||
} catch (error) {
|
||
console.error('加载库存单位失败:', error)
|
||
stockUnits.value = [
|
||
{ value: '个', label: '个' },
|
||
{ value: '件', label: '件' },
|
||
{ value: '箱', label: '箱' },
|
||
{ value: '盒', label: '盒' },
|
||
{ value: '包', label: '包' },
|
||
{ value: '瓶', label: '瓶' },
|
||
{ value: '袋', label: '袋' },
|
||
{ value: '套', label: '套' },
|
||
{ value: '台', label: '台' },
|
||
{ value: '只', label: '只' }
|
||
]
|
||
}
|
||
}
|
||
|
||
const openUnitDrawer = () => {
|
||
unitDrawerVisible.value = true
|
||
newUnitName.value = ''
|
||
refreshUnitList()
|
||
}
|
||
|
||
const refreshUnitList = async () => {
|
||
try {
|
||
const response = await stockApi.getUnitList()
|
||
if (response && (response as any).code === 200) {
|
||
unitList.value = (response as any).data
|
||
loadStockUnits()
|
||
}
|
||
} catch (error) {
|
||
console.error('加载单位列表失败:', error)
|
||
unitList.value = []
|
||
}
|
||
}
|
||
|
||
const addUnit = async () => {
|
||
const name = newUnitName.value.trim()
|
||
if (!name) {
|
||
ElMessage.warning('请输入单位名称')
|
||
return
|
||
}
|
||
try {
|
||
const response = await stockApi.createUnit({ name })
|
||
if (response && (response as any).code === 200) {
|
||
ElMessage.success('添加成功')
|
||
newUnitName.value = ''
|
||
refreshUnitList()
|
||
} else {
|
||
ElMessage.error((response as any).message || '添加失败')
|
||
}
|
||
} catch (error) {
|
||
ElMessage.error('添加单位失败')
|
||
}
|
||
}
|
||
|
||
const deleteUnit = async (id: any) => {
|
||
try {
|
||
await ElMessageBox.confirm('确定要删除这个单位吗?', '提示', { type: 'warning' })
|
||
const response = await stockApi.deleteUnit({ id }) // API check needed: usually expects ID or object?
|
||
// Vue 2: await stockApi.deleteUnit(id)
|
||
// Let's check api/stock.ts for deleteUnit signature.
|
||
// export function deleteUnit(data: any) { ... data: data }
|
||
// So if I pass id, it sends { id } ? No, it sends data as body.
|
||
// If Vue 2 sent id directly, maybe API expects {id: id} or just id?
|
||
// Vue 2 code: deleteUnit(id) -> request({ data: data }) -> so it sends scalar?
|
||
// Wait, in Vue 2 api: export function deleteUnit(data) { return request({ data }) }
|
||
// If I pass scalar ID, it sends scalar.
|
||
// In Vue 3 api/stock.ts: export function deleteUnit(data: any) { ... data: data }
|
||
// I should probably pass { id } if the backend expects an object, or just id if it expects scalar.
|
||
// Most frameworks expect object { id: ... }. I'll assume object { id } is safer or check usage.
|
||
// Vue 2 usage: deleteUnit(row.id).
|
||
// Let's pass { id } just in case, or stick to what Vue 2 did if I knew the backend.
|
||
// Given the previous call `createUnit({ name })`, it seems to use objects.
|
||
// I'll try passing { id }.
|
||
|
||
if (response && (response as any).code === 200) {
|
||
ElMessage.success('删除成功')
|
||
refreshUnitList()
|
||
} else {
|
||
ElMessage.error((response as any).message || '删除失败')
|
||
}
|
||
} catch (error) {
|
||
if (error !== 'cancel') {
|
||
ElMessage.error('删除单位失败')
|
||
}
|
||
}
|
||
}
|
||
|
||
// Prohibited Management
|
||
const openProhibitedDrawer = () => {
|
||
prohibitedDrawerVisible.value = true
|
||
newProhibitedName.value = ''
|
||
newProhibitedLevel.value = 1
|
||
refreshProhibitedList()
|
||
}
|
||
|
||
const refreshProhibitedList = async () => {
|
||
try {
|
||
const response = await stockApi.getProhibitedList()
|
||
if (response && (response as any).code === 200) {
|
||
prohibitedList.value = (response as any).data
|
||
emit('update-prohibited-types', (response as any).data.map((item: any) => ({
|
||
value: item.id,
|
||
label: item.name
|
||
})))
|
||
}
|
||
} catch (error) {
|
||
console.error('加载违禁品类型列表失败:', error)
|
||
prohibitedList.value = []
|
||
}
|
||
}
|
||
|
||
const getDangerLevelText = (level: number) => {
|
||
const map: Record<number, string> = {
|
||
1: '一级',
|
||
2: '二级',
|
||
3: '三级'
|
||
}
|
||
return map[level] || '未知'
|
||
}
|
||
|
||
const addProhibited = async () => {
|
||
const name = newProhibitedName.value.trim()
|
||
if (!name) {
|
||
ElMessage.warning('请输入违禁品类型名称')
|
||
return
|
||
}
|
||
try {
|
||
const data = {
|
||
name: name,
|
||
danger_level: newProhibitedLevel.value
|
||
}
|
||
const response = await stockApi.createProhibited(data)
|
||
if (response && (response as any).code === 200) {
|
||
ElMessage.success('添加成功')
|
||
newProhibitedName.value = ''
|
||
refreshProhibitedList()
|
||
} else {
|
||
ElMessage.error((response as any).message || '添加失败')
|
||
}
|
||
} catch (error) {
|
||
ElMessage.error('添加违禁品类型失败')
|
||
}
|
||
}
|
||
|
||
const deleteProhibited = async (id: any) => {
|
||
try {
|
||
await ElMessageBox.confirm('确定要删除这个违禁品类型吗?', '提示', { type: 'warning' })
|
||
const response = await stockApi.deleteProhibited({ id })
|
||
if (response && (response as any).code === 200) {
|
||
ElMessage.success('删除成功')
|
||
refreshProhibitedList()
|
||
} else {
|
||
ElMessage.error((response as any).message || '删除失败')
|
||
}
|
||
} catch (error) {
|
||
if (error !== 'cancel') {
|
||
ElMessage.error('删除违禁品类型失败')
|
||
}
|
||
}
|
||
}
|
||
|
||
// Watchers
|
||
watch(() => formData.managementFlags, (newFlags) => {
|
||
if (newFlags) {
|
||
formData.is_sn_mgmt = newFlags.includes('is_sn_mgmt') ? 'Y' : 'N'
|
||
formData.is_shelf_life_mgmt = newFlags.includes('is_shelf_life_mgmt') ? 'Y' : 'N'
|
||
formData.is_batch_mgmt = newFlags.includes('is_batch_mgmt') ? 'Y' : 'N'
|
||
}
|
||
})
|
||
|
||
watch(() => props.prohibited_type, (newVal) => {
|
||
prohibitedTypes.value = newVal
|
||
}, { immediate: true })
|
||
|
||
// Lifecycle
|
||
onMounted(() => {
|
||
loadStockUnits()
|
||
// Object.assign(originalData, JSON.parse(JSON.stringify(formData)))
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.upper-table-container {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 20px;
|
||
|
||
.el-form {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding-bottom: 20px;
|
||
}
|
||
}
|
||
|
||
.bottom {
|
||
height: 40px;
|
||
background-color: #fff;
|
||
border-top: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
margin-top: 10px;
|
||
}
|
||
|
||
.info-card {
|
||
background-color: #f8f9fa;
|
||
border-radius: 8px;
|
||
padding: 15px;
|
||
border: 1px solid #e4e7ed;
|
||
margin-bottom: 20px;
|
||
|
||
&:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 15px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 1px solid #e4e7ed;
|
||
|
||
h4 {
|
||
margin: 0;
|
||
color: #409eff;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
}
|
||
}
|
||
}
|
||
|
||
.select-with-button {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
width: 100%;
|
||
}
|
||
|
||
.management-flags {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 10px;
|
||
}
|
||
</style> |