|
|
|
|
@ -10,33 +10,38 @@
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
<el-form-item label="供应商" prop="supplierId">
|
|
|
|
|
<el-select v-model="formData.supplierId" placeholder="请选择供应商" filterable clearable class="!w-full">
|
|
|
|
|
<el-option v-for="item in supplierList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
|
<el-form-item label="库位" prop="locationId">
|
|
|
|
|
<el-select
|
|
|
|
|
v-model="formData.locationId"
|
|
|
|
|
placeholder="请选择库位"
|
|
|
|
|
filterable
|
|
|
|
|
clearable
|
|
|
|
|
class="!w-full"
|
|
|
|
|
@change="handleLocationChange"
|
|
|
|
|
>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in filteredLocationList"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="formatLocationLabel(item)"
|
|
|
|
|
:value="item.id"
|
|
|
|
|
/>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="仓库" prop="warehouseId">
|
|
|
|
|
<el-select v-model="formData.warehouseId" placeholder="请选择仓库" filterable class="!w-full" @change="handleWarehouseChange">
|
|
|
|
|
<el-option v-for="item in warehouseList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
|
</el-select>
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
<el-form-item label="数量" prop="count">
|
|
|
|
|
<el-input-number v-model="formData.count" :min="1" :precision="0" class="!w-full" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="库区" prop="areaId">
|
|
|
|
|
<el-select v-model="formData.areaId" placeholder="请选择库区" filterable clearable class="!w-full">
|
|
|
|
|
<el-option v-for="item in filteredAreaList" :key="item.id" :label="item.areaName" :value="item.id" />
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
<el-form-item label="单位" prop="unitId">
|
|
|
|
|
<el-select v-model="formData.unitId" placeholder="请选择单位" filterable class="!w-full">
|
|
|
|
|
<el-option v-for="item in sampleUnitOptions" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="8">
|
|
|
|
|
<el-form-item label="数量" prop="count">
|
|
|
|
|
<el-input-number v-model="formData.count" :min="1" :precision="0" class="!w-full" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
<el-form-item label="备注" prop="remark">
|
|
|
|
|
<el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请输入备注" />
|
|
|
|
|
@ -55,48 +60,117 @@
|
|
|
|
|
import { BitWmsApi } from '@/api/erp/bitwms'
|
|
|
|
|
import { WarehouseApi } from '@/api/erp/stock/warehouse'
|
|
|
|
|
import { WarehouseAreaApi } from '@/api/erp/stock/warehousearea'
|
|
|
|
|
import { SupplierApi } from '@/api/erp/purchase/supplier'
|
|
|
|
|
import { WarehouseLocationApi } from '@/api/erp/stock/warehouselocation'
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'ErpBitWmsIn' })
|
|
|
|
|
|
|
|
|
|
const DEFAULT_WAREHOUSE_NAME = '样品仓'
|
|
|
|
|
const DEFAULT_AREA_NAME = '必硕三楼'
|
|
|
|
|
const message = useMessage()
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
const submitLoading = ref(false)
|
|
|
|
|
const sampleList = ref<any[]>([])
|
|
|
|
|
const warehouseList = ref<any[]>([])
|
|
|
|
|
const areaList = ref<any[]>([])
|
|
|
|
|
const supplierList = ref<any[]>([])
|
|
|
|
|
const locationList = ref<any[]>([])
|
|
|
|
|
const formData = reactive<any>({
|
|
|
|
|
productId: undefined,
|
|
|
|
|
warehouseId: undefined,
|
|
|
|
|
areaId: undefined,
|
|
|
|
|
locationId: undefined,
|
|
|
|
|
count: 1,
|
|
|
|
|
supplierId: undefined,
|
|
|
|
|
unitId: undefined,
|
|
|
|
|
remark: undefined
|
|
|
|
|
})
|
|
|
|
|
const formRules = reactive({
|
|
|
|
|
productId: [{ required: true, message: '请选择样品', trigger: 'change' }],
|
|
|
|
|
warehouseId: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
|
|
|
|
count: [{ required: true, message: '请输入数量', trigger: 'blur' }]
|
|
|
|
|
locationId: [{ required: true, message: '请选择库位', trigger: 'change' }],
|
|
|
|
|
count: [{ required: true, message: '请输入数量', trigger: 'blur' }],
|
|
|
|
|
unitId: [{ required: true, message: '请选择单位', trigger: 'change' }]
|
|
|
|
|
})
|
|
|
|
|
const filteredAreaList = computed(() => {
|
|
|
|
|
if (!formData.warehouseId) return areaList.value
|
|
|
|
|
return areaList.value.filter((item) => item.warehouseId === formData.warehouseId)
|
|
|
|
|
const selectedSample = computed(() => sampleList.value.find((item) => item.id === formData.productId))
|
|
|
|
|
const sampleUnitOptions = computed(() => {
|
|
|
|
|
const sample = selectedSample.value
|
|
|
|
|
if (!sample?.unitId) return []
|
|
|
|
|
return [{ id: sample.unitId, name: sample.unitName || '默认单位' }]
|
|
|
|
|
})
|
|
|
|
|
const filteredLocationList = computed(() => {
|
|
|
|
|
if (!formData.warehouseId || !formData.areaId) return []
|
|
|
|
|
return locationList.value.filter((item) => {
|
|
|
|
|
const matchedWarehouse = item.warehouseId === formData.warehouseId
|
|
|
|
|
const matchedArea = item.areaId === formData.areaId
|
|
|
|
|
return matchedWarehouse && matchedArea
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const formatSampleLabel = (item: any) => `${item.barCode || item.code || '-'} / ${item.name || '-'}`
|
|
|
|
|
const handleWarehouseChange = () => {
|
|
|
|
|
formData.areaId = undefined
|
|
|
|
|
const formatLocationLabel = (item: any) => `${item.code || '-'} / ${item.name || '-'}`
|
|
|
|
|
const applyDefaultWarehouseArea = () => {
|
|
|
|
|
const warehouse = warehouseList.value.find((item) => item.name === DEFAULT_WAREHOUSE_NAME)
|
|
|
|
|
if (!warehouse) {
|
|
|
|
|
formData.warehouseId = undefined
|
|
|
|
|
formData.areaId = undefined
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
formData.warehouseId = warehouse.id
|
|
|
|
|
const area = areaList.value.find(
|
|
|
|
|
(item) => item.warehouseId === warehouse.id && item.areaName === DEFAULT_AREA_NAME
|
|
|
|
|
)
|
|
|
|
|
formData.areaId = area?.id
|
|
|
|
|
}
|
|
|
|
|
const handleLocationChange = (locationId?: number) => {
|
|
|
|
|
const location = locationList.value.find((item) => item.id === locationId)
|
|
|
|
|
if (!location) return
|
|
|
|
|
formData.warehouseId = location.warehouseId
|
|
|
|
|
formData.areaId = location.areaId
|
|
|
|
|
}
|
|
|
|
|
const handleSampleChange = () => {
|
|
|
|
|
formData.unitId = selectedSample.value?.unitId
|
|
|
|
|
}
|
|
|
|
|
const resetInnerFormData = () => {
|
|
|
|
|
formData.productId = undefined
|
|
|
|
|
formData.locationId = undefined
|
|
|
|
|
formData.count = 1
|
|
|
|
|
formData.unitId = undefined
|
|
|
|
|
formData.remark = undefined
|
|
|
|
|
applyDefaultWarehouseArea()
|
|
|
|
|
}
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
formRef.value?.resetFields()
|
|
|
|
|
formData.count = 1
|
|
|
|
|
resetInnerFormData()
|
|
|
|
|
}
|
|
|
|
|
const buildSubmitData = () => ({
|
|
|
|
|
productId: formData.productId,
|
|
|
|
|
locationId: formData.locationId,
|
|
|
|
|
warehouseId: formData.warehouseId,
|
|
|
|
|
areaId: formData.areaId,
|
|
|
|
|
count: formData.count,
|
|
|
|
|
unitId: formData.unitId,
|
|
|
|
|
remark: formData.remark
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => formData.productId,
|
|
|
|
|
() => handleSampleChange()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => [formData.warehouseId, formData.areaId],
|
|
|
|
|
() => {
|
|
|
|
|
if (
|
|
|
|
|
formData.locationId &&
|
|
|
|
|
!filteredLocationList.value.some((item) => item.id === formData.locationId)
|
|
|
|
|
) {
|
|
|
|
|
formData.locationId = undefined
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
await formRef.value.validate()
|
|
|
|
|
submitLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
await BitWmsApi.inbound(formData)
|
|
|
|
|
await BitWmsApi.inbound(buildSubmitData())
|
|
|
|
|
message.success('入库成功')
|
|
|
|
|
resetForm()
|
|
|
|
|
} finally {
|
|
|
|
|
@ -105,15 +179,16 @@ const submitForm = async () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
const [samples, warehouses, areas, suppliers] = await Promise.all([
|
|
|
|
|
const [samples, warehouses, areas, locations] = await Promise.all([
|
|
|
|
|
BitWmsApi.getSampleSimpleList(),
|
|
|
|
|
WarehouseApi.getWarehouseSimpleList(),
|
|
|
|
|
WarehouseAreaApi.getWarehouseAreaPage({ pageNo: 1, pageSize: 100 }),
|
|
|
|
|
SupplierApi.getSupplierSimpleList()
|
|
|
|
|
WarehouseLocationApi.getWarehouseLocationPage({ pageNo: 1, pageSize: 100 })
|
|
|
|
|
])
|
|
|
|
|
sampleList.value = samples || []
|
|
|
|
|
warehouseList.value = warehouses || []
|
|
|
|
|
areaList.value = areas.list || []
|
|
|
|
|
supplierList.value = suppliers || []
|
|
|
|
|
locationList.value = locations.list || []
|
|
|
|
|
resetInnerFormData()
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|