| | |
| | | <el-option label="吨" value="吨" /> |
| | | <el-option label="千克" value="千克" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="采购数量" prop="purchaseQuantity"> |
| | | <el-input v-model.number="form.purchaseQuantity" placeholder="请输入" > |
| | | </el-form-item> <el-form-item label="采购数量" prop="purchaseQuantity"> |
| | | <el-input |
| | | v-model.number="form.purchaseQuantity" |
| | | placeholder="请输入" |
| | | @blur="handleQuantityBlur" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">{{form.unit?form.unit:''}}</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item><el-form-item label="税率" prop="taxRate"> |
| | | <el-input |
| | | v-model.number="form.taxRate" |
| | | placeholder="请输入税率" |
| | | @blur="handleTaxRateBlur" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">%</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="单价(不含税)" prop="priceExcludingTax"> |
| | | <el-input v-model.number="form.priceExcludingTax" placeholder="请输入" > |
| | | <el-input |
| | | v-model.number="form.priceExcludingTax" |
| | | placeholder="请输入" |
| | | @blur="handlePriceBlur" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> <el-form-item label="单价(含税)" prop="priceIncludingTax"> |
| | | <el-input |
| | | v-model.number="form.priceIncludingTax" |
| | | placeholder="自动计算" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="总价(不含税)" prop="totalPriceExcludingTax"> |
| | | <el-input v-model.number="form.totalPriceExcludingTax" placeholder="请输入" > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="单价(含税)" prop="priceIncludingTax"> |
| | | <el-input v-model.number="form.priceIncludingTax" placeholder="请输入" > |
| | | <el-input |
| | | v-model.number="form.totalPriceExcludingTax" |
| | | placeholder="自动计算" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="总价(含税)" prop="totalPriceIncludingTax"> |
| | | <el-input v-model.number="form.totalPriceIncludingTax" placeholder="请输入" > |
| | | <el-input |
| | | v-model.number="form.totalPriceIncludingTax" |
| | | placeholder="自动计算" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="税率" prop="taxRate"> |
| | | <el-input v-model="form.taxRate" placeholder="请输入税率" > |
| | | <template v-slot:suffix> |
| | | <i style="font-style:normal;">%</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="登记人" prop="registrantId"> |
| | | <el-input v-model="form.registrantId" disabled placeholder="请输入" /> |
| | |
| | | </template> |
| | | |
| | | <script setup name="ProductionDialog"> |
| | | import { ref, defineProps, watch, onMounted, nextTick } from "vue"; |
| | | import { ref, defineProps, watch, onMounted, nextTick, computed } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import useUserStore from '@/store/modules/user' |
| | | import {addOrEditPR} from "@/api/procureMent"; |
| | |
| | | required: true, |
| | | type: Object, |
| | | }); |
| | | |
| | | const toFixed = (num, precision = 2) => { |
| | | if (isNaN(num) || num === null || num === undefined || num === '') { |
| | | return 0; |
| | | } |
| | | return Math.floor(parseFloat(num) * Math.pow(10, precision)) / Math.pow(10, precision); |
| | | }; |
| | | // 含税单价计算 |
| | | const unitPriceWithTax = computed(() => { |
| | | const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; |
| | | const taxRate = parseFloat(form.value.taxRate) || 0; |
| | | if (!priceExcludingTax || !taxRate) { |
| | | return 0; |
| | | } |
| | | const result = priceExcludingTax * (1 + taxRate / 100); |
| | | return toFixed(result, 2); |
| | | }); |
| | | |
| | | // 含税总价计算 |
| | | const totalUnitPriceWithTax = computed(() => { |
| | | const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; |
| | | const taxRate = parseFloat(form.value.taxRate) || 0; |
| | | const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0; |
| | | |
| | | if (!priceExcludingTax || !taxRate || !purchaseQuantity) { |
| | | return 0; |
| | | } |
| | | |
| | | const unitPriceWithTaxValue = priceExcludingTax * (1 + taxRate / 100); |
| | | const result = unitPriceWithTaxValue * purchaseQuantity; |
| | | return toFixed(result, 2); |
| | | }); |
| | | |
| | | // 不含税总价计算 |
| | | const taxExclusiveTotalPrice = computed(() => { |
| | | const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0; |
| | | const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; |
| | | |
| | | if (!purchaseQuantity || !priceExcludingTax) { |
| | | return 0; |
| | | } |
| | | |
| | | const result = purchaseQuantity * priceExcludingTax; |
| | | return toFixed(result, 2); |
| | | }); |
| | | |
| | | // 监听计算值变化,同步到 form 对象中 |
| | | watch(unitPriceWithTax, (newValue) => { |
| | | form.value.priceIncludingTax = newValue; |
| | | }); |
| | | |
| | | watch(totalUnitPriceWithTax, (newValue) => { |
| | | form.value.totalPriceIncludingTax = newValue; |
| | | }); |
| | | |
| | | watch(taxExclusiveTotalPrice, (newValue) => { |
| | | form.value.totalPriceExcludingTax = newValue; |
| | | }); |
| | | |
| | | const userStore = useUserStore() |
| | | const userInfo = ref({}); |
| | | |
| | | // 处理税率输入框失焦,确保精度 |
| | | const handleTaxRateBlur = () => { |
| | | if (form.value.taxRate !== null && form.value.taxRate !== undefined && form.value.taxRate !== '') { |
| | | form.value.taxRate = toFixed(parseFloat(form.value.taxRate), 2); |
| | | } |
| | | }; |
| | | |
| | | // 处理不含税单价输入框失焦,确保精度 |
| | | const handlePriceBlur = () => { |
| | | if (form.value.priceExcludingTax !== null && form.value.priceExcludingTax !== undefined && form.value.priceExcludingTax !== '') { |
| | | form.value.priceExcludingTax = toFixed(parseFloat(form.value.priceExcludingTax), 2); |
| | | } |
| | | }; |
| | | |
| | | // 处理采购数量输入框失焦,确保精度 |
| | | const handleQuantityBlur = () => { |
| | | if (form.value.purchaseQuantity !== null && form.value.purchaseQuantity !== undefined && form.value.purchaseQuantity !== '') { |
| | | form.value.purchaseQuantity = toFixed(parseFloat(form.value.purchaseQuantity), 3); // 数量保留3位小数 |
| | | } |
| | | }; |
| | | |
| | | onMounted(async () => { |
| | | let res = await userStore.getInfo() |
| | | userInfo.value = res; |
| | |
| | | const formRef = ref(null); |
| | | // 提交表单 |
| | | const handleSubmit = async () => { |
| | | console.log("提交表单", form.value); |
| | | if (!formRef.value) return; |
| | | await formRef.value.validate(async (valid) => { |
| | | if (valid) { |