联调
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
<template>
|
||||
<Dialog title="发起采购" v-model="dialogVisible" width="800px">
|
||||
<el-form :model="form" ref="addForm" :rules="rules" label-width="100px">
|
||||
<el-form :model="form" ref="formRef" :rules="rules" label-width="100px">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="产品" prop="product">
|
||||
<el-select v-model="form.product" placeholder="请选择" filterable style="width: 100%">
|
||||
<el-form-item label="产品" prop="productId">
|
||||
<el-select v-model="form.productId" placeholder="请选择" filterable style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in productOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
v-for="item in props.opts.product"
|
||||
:key="item.productId"
|
||||
:label="item.productName"
|
||||
:value="item.productId"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="规格" prop="specs">
|
||||
<el-select v-model="form.specs" placeholder="请选择" filterable style="width: 100%">
|
||||
<el-form-item label="规格" prop="specsId">
|
||||
<el-select v-model="form.specsId" placeholder="请选择" filterable style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in specsOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
v-for="item in specOptions"
|
||||
:key="item.specsId"
|
||||
:label="item.specsName"
|
||||
:value="item.specsId"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -30,34 +30,41 @@
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="供应商" prop="supplier">
|
||||
<el-input v-model="form.supplier" placeholder="请输入" />
|
||||
<el-select v-model="form.supplier" placeholder="选择供应商" filterable>
|
||||
<el-option
|
||||
v-for="item in opts.supplier"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="采购数量" prop="purchaseCount">
|
||||
<el-input-number
|
||||
:min="1"
|
||||
v-model="form.purchaseCount"
|
||||
placeholder="请输入"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<el-form-item label="采购数量" prop="num">
|
||||
<el-input-number :min="1" v-model="form.num" placeholder="请输入" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="采购单价" prop="price">
|
||||
<el-form-item label="采购单价" prop="unitPrice">
|
||||
<el-input-number
|
||||
:min="0"
|
||||
v-model="form.price"
|
||||
v-model="form.unitPrice"
|
||||
placeholder="请输入"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" :offset="0">
|
||||
<el-form-item label="存放仓库" prop="warehouse">
|
||||
<el-select v-model="form.warehouse" placeholder="请选择" filterable style="width: 100%">
|
||||
<el-form-item label="存放仓库" prop="warehouseId">
|
||||
<el-select
|
||||
v-model="form.warehouseId"
|
||||
placeholder="请选择"
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in warehouseOptions"
|
||||
:key="item.value"
|
||||
@@ -86,13 +93,42 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import * as PurchaseApi from '@/api/mall/purchase'
|
||||
const props = defineProps({
|
||||
opts: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {
|
||||
product: [],
|
||||
spec: [],
|
||||
supplier: []
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const specOptions = computed(() => {
|
||||
if (form.value.productId) {
|
||||
return (
|
||||
props.opts.product.find((it) => it.productId == form.value.productId)?.productSpecList || []
|
||||
)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
|
||||
const form = ref()
|
||||
const rules = ref({})
|
||||
const form = ref({})
|
||||
const rules = {
|
||||
productId: { required: true, message: '产品不可为空', trigger: 'change' },
|
||||
specsId: { required: true, message: '规格不可为空', trigger: 'change' },
|
||||
supplier: { required: true, message: '供应商不可为空', trigger: 'change' },
|
||||
warehouseId: { required: true, message: '仓库不可为空', trigger: 'change' },
|
||||
num: { required: true, message: '采购数量不可为空', trigger: 'change,blur' },
|
||||
unitPrice: { required: true, message: '采购单价不可为空', trigger: 'change,blur' }
|
||||
}
|
||||
|
||||
const productOptions = ref([])
|
||||
const specsOptions = ref([])
|
||||
const warehouseOptions = ref([
|
||||
{ label: '自营仓', value: 1 },
|
||||
{ label: '供应商仓', value: 2 }
|
||||
@@ -100,19 +136,37 @@ const warehouseOptions = ref([
|
||||
|
||||
const open = (val) => {
|
||||
dialogVisible.value = true
|
||||
form.value = val || {
|
||||
product: '',
|
||||
specs: '',
|
||||
supplier: '',
|
||||
purchaseCount: 1,
|
||||
warehouse: 1,
|
||||
remark: ''
|
||||
form.value = { ...val } || {
|
||||
productId: undefined,
|
||||
specsId: undefined,
|
||||
supplier: undefined,
|
||||
num: undefined,
|
||||
unitPrice: undefined,
|
||||
warehouseId: undefined,
|
||||
remark: undefined
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
function handleSave() {
|
||||
console.log('保存')
|
||||
const formRef = ref()
|
||||
const formLoading = ref(false)
|
||||
|
||||
async function handleSave() {
|
||||
// 校验表单
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
await PurchaseApi.createPurchase(form.value)
|
||||
message.success(t('common.createSuccess'))
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user