| | |
| | | </el-button> |
| | | </el-form-item> |
| | | |
| | | <el-form-item |
| | | label="规格" |
| | | prop="productModelName" |
| | | > |
| | | <el-form-item label="规格" prop="productModelName"> |
| | | <el-input v-model="formState.model" disabled /> |
| | | </el-form-item> |
| | | |
| | | <el-form-item |
| | | label="单位" |
| | | prop="unit" |
| | | > |
| | | <el-form-item label="单位" prop="unit"> |
| | | <el-input v-model="formState.unit" disabled /> |
| | | </el-form-item> |
| | | |
| | | <el-form-item |
| | | label="数量" |
| | | prop="qualitity" |
| | | label="库存类型" |
| | | prop="stockType" |
| | | :rules="[ |
| | | { |
| | | required: true, |
| | | message: '请选择库存类型', |
| | | trigger: 'change', |
| | | } |
| | | ]" |
| | | > |
| | | <el-input-number v-model="formState.qualitity" :step="1" :min="1" :max="maxQuality" style="width: 100%" /> |
| | | <el-select v-model="formState.stockType" placeholder="请选择库存类型" style="width: 100%"> |
| | | <el-option label="合格库存" value="qualified" /> |
| | | <el-option label="不合格库存" value="unqualified" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="数量" prop="qualitity"> |
| | | <el-input-number |
| | | v-model="formState.qualitity" |
| | | :step="0.01" |
| | | :precision="2" |
| | | :min="inputMin" |
| | | :max="maxQuality" |
| | | style="width: 100%" |
| | | /> |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="备注" prop="remark"> |
| | |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <!-- 产品选择弹窗 --> |
| | | <ProductSelectDialog |
| | | v-model="showProductSelectDialog" |
| | | @confirm="handleProductSelect" |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import {ref, computed, getCurrentInstance} from "vue"; |
| | | import { ref, computed, getCurrentInstance, onMounted, watch } from "vue"; |
| | | import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue"; |
| | | import {subtractStockInventory} from "@/api/inventoryManagement/stockInventory.js"; |
| | | import {subtractStockUnInventory} from "@/api/inventoryManagement/stockUninventory.js"; |
| | |
| | | }, |
| | | record: { |
| | | type: Object, |
| | | default: () => {}, |
| | | default: () => ({}), |
| | | }, |
| | | type: { |
| | | type: String, |
| | | required: true, |
| | | default: 'qualified', |
| | | default: "qualified", |
| | | }, |
| | | }); |
| | | |
| | | const emit = defineEmits(['update:visible', 'completed']); |
| | | const emit = defineEmits(["update:visible", "completed"]); |
| | | |
| | | onMounted(() => { |
| | | initFormData() |
| | | }) |
| | | const toNumber = (value) => { |
| | | const num = Number(value); |
| | | return Number.isFinite(num) ? num : 0; |
| | | }; |
| | | |
| | | const maxQuality = computed(() => { |
| | | return props.record.unLockedQuantity ? props.record.unLockedQuantity : 0; |
| | | }) |
| | | const getQualifiedUnLockedStock = (row) => { |
| | | return toNumber( |
| | | row?.qualifiedUnLockedQuantity ?? |
| | | row?.unLockedQuantity ?? |
| | | row?.qualifiedQuantity ?? |
| | | row?.qualitity |
| | | ); |
| | | }; |
| | | |
| | | const initFormData = () => { |
| | | if (props.record) { |
| | | formState.value = { |
| | | ...props.record, |
| | | } |
| | | } |
| | | } |
| | | const getUnqualifiedUnLockedStock = (row) => { |
| | | return toNumber( |
| | | row?.unQualifiedUnLockedQuantity ?? |
| | | row?.unqualifiedUnLockedQuantity ?? |
| | | row?.unQualifiedQuantity ?? |
| | | row?.unqualifiedQuantity |
| | | ); |
| | | }; |
| | | |
| | | // 响应式数据(替代选项式的 data) |
| | | const formState = ref({ |
| | | productId: undefined, |
| | | productModelId: undefined, |
| | | productName: "", |
| | | model: "", |
| | | unit: "", |
| | | qualitity: 0, |
| | | remark: '', |
| | | stockType: "qualified", |
| | | qualitity: 0.01, |
| | | remark: "", |
| | | }); |
| | | |
| | | const maxQuality = computed(() => { |
| | | if (formState.value.stockType === "unqualified") { |
| | | return getUnqualifiedUnLockedStock(props.record); |
| | | } |
| | | return getQualifiedUnLockedStock(props.record); |
| | | }); |
| | | |
| | | const inputMin = computed(() => (maxQuality.value > 0 ? 0.01 : 0)); |
| | | |
| | | const initFormData = () => { |
| | | if (props.record) { |
| | | formState.value = { |
| | | ...props.record, |
| | | stockType: props.type === "unqualified" ? "unqualified" : "qualified", |
| | | qualitity: 0.01, |
| | | }; |
| | | } |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | initFormData(); |
| | | }); |
| | | |
| | | const isShow = computed({ |
| | |
| | | return props.visible; |
| | | }, |
| | | set(val) { |
| | | emit('update:visible', val); |
| | | emit("update:visible", val); |
| | | }, |
| | | }); |
| | | |
| | | const showProductSelectDialog = ref(false); |
| | | watch( |
| | | () => props.record, |
| | | () => { |
| | | initFormData(); |
| | | }, |
| | | { deep: true } |
| | | ); |
| | | |
| | | let { proxy } = getCurrentInstance() |
| | | watch( |
| | | maxQuality, |
| | | (val) => { |
| | | if (val <= 0) { |
| | | formState.value.qualitity = 0; |
| | | return; |
| | | } |
| | | if (!formState.value.qualitity || formState.value.qualitity < 0.01) { |
| | | formState.value.qualitity = 0.01; |
| | | } else if (formState.value.qualitity > val) { |
| | | formState.value.qualitity = val; |
| | | } |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | | |
| | | const showProductSelectDialog = ref(false); |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | const closeModal = () => { |
| | | // 重置表单数据 |
| | | formState.value = { |
| | | productId: undefined, |
| | | productModelId: undefined, |
| | | productName: "", |
| | | productModelName: "", |
| | | description: '', |
| | | stockType: "qualified", |
| | | qualitity: 0.01, |
| | | description: "", |
| | | }; |
| | | isShow.value = false; |
| | | }; |
| | | |
| | | // 产品选择处理 |
| | | const handleProductSelect = async (products) => { |
| | | if (products && products.length > 0) { |
| | | const product = products[0]; |
| | | console.log(product) |
| | | formState.value.productId = product.productId; |
| | | formState.value.productName = product.productName; |
| | | formState.value.productModelName = product.model; |
| | | formState.value.productModelId = product.id; |
| | | formState.value.unit = product.unit; |
| | | showProductSelectDialog.value = false; |
| | | // 触发表单验证更新 |
| | | proxy.$refs["formRef"]?.validateField('productModelId'); |
| | | proxy.$refs["formRef"]?.validateField("productModelId"); |
| | | } |
| | | }; |
| | | |
| | | const handleSubmit = () => { |
| | | proxy.$refs["formRef"].validate(valid => { |
| | | if (valid) { |
| | | // 验证是否选择了产品和规格 |
| | | proxy.$refs["formRef"].validate((valid) => { |
| | | if (!valid) return; |
| | | |
| | | if (!formState.value.productModelId) { |
| | | proxy.$modal.msgError("请选择产品"); |
| | | return; |
| | |
| | | proxy.$modal.msgError("请选择规格"); |
| | | return; |
| | | } |
| | | if (props.type === 'qualified') { |
| | | subtractStockInventory(formState.value).then(res => { |
| | | // 关闭模态框 |
| | | isShow.value = false; |
| | | // 告知父组件已完成 |
| | | emit('completed'); |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | }) |
| | | } else { |
| | | subtractStockUnInventory(formState.value).then(res => { |
| | | // 关闭模态框 |
| | | isShow.value = false; |
| | | // 告知父组件已完成 |
| | | emit('completed'); |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | }) |
| | | if (!formState.value.stockType) { |
| | | proxy.$modal.msgError("请选择库存类型"); |
| | | return; |
| | | } |
| | | if (!formState.value.qualitity || formState.value.qualitity <= 0) { |
| | | proxy.$modal.msgError("领用数量必须大于0"); |
| | | return; |
| | | } |
| | | }) |
| | | }; |
| | | if (formState.value.qualitity > maxQuality.value) { |
| | | proxy.$modal.msgError("领用数量不能超过可用库存"); |
| | | return; |
| | | } |
| | | |
| | | const submitApi = |
| | | formState.value.stockType === "unqualified" ? subtractStockUnInventory : subtractStockInventory; |
| | | submitApi(formState.value).then(() => { |
| | | isShow.value = false; |
| | | emit("completed"); |
| | | proxy.$modal.msgSuccess("提交成功"); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | defineExpose({ |
| | | closeModal, |