| | |
| | | <template> |
| | | <div> |
| | | <el-dialog |
| | | v-model="dialogFormVisible" |
| | | :title="title" |
| | | width="600" |
| | | :close-on-click-modal="false" |
| | | @close="handleClose" |
| | | v-model="dialogFormVisible" |
| | | :title="title" |
| | | width="600" |
| | | :close-on-click-modal="false" |
| | | @close="handleClose" |
| | | > |
| | | <el-form |
| | | ref="formRef" |
| | | :model="form" |
| | | :rules="rules" |
| | | label-width="auto" |
| | | class="production-form" |
| | | label-position="right" |
| | | style="max-width: 400px; margin: 0 auto" |
| | | ref="formRef" |
| | | :model="form" |
| | | :rules="rules" |
| | | label-width="auto" |
| | | class="production-form" |
| | | label-position="right" |
| | | style="max-width: 400px; margin: 0 auto" |
| | | > |
| | | <el-form-item label="供应商名称" prop="supplierId"> |
| | | <el-select v-model="form.supplierId" placeholder="请选择供应商" :disabled="isViewMode"> |
| | | <el-option :label="item.label" v-for="item in supplyList" :key="item.value" :value="item.value"/> |
| | | <el-select |
| | | v-model="form.supplierId" |
| | | placeholder="请选择供应商" |
| | | :disabled="isViewMode" |
| | | > |
| | | <el-option |
| | | :label="item.label" |
| | | v-for="item in supplyList" |
| | | :key="item.value" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="煤种" prop="coalId"> |
| | | <el-select v-model="form.coalId" placeholder="请选择煤种" :disabled="isViewMode"> |
| | | <el-option :label="item.label" v-for="item in coalList" :key="item.value" :value="item.value"/> |
| | | <el-select |
| | | v-model="form.coalId" |
| | | placeholder="请选择煤种" |
| | | :disabled="isViewMode" |
| | | > |
| | | <el-option |
| | | :label="item.label" |
| | | v-for="item in coalList" |
| | | :key="item.value" |
| | | :value="item.value" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="采购数量" prop="purchaseQuantity"> |
| | | <el-input |
| | | v-model.number="form.purchaseQuantity" |
| | | placeholder="请输入" |
| | | @blur="handleQuantityBlur" |
| | | :disabled="isViewMode" |
| | | v-model.number="form.purchaseQuantity" |
| | | placeholder="请输入" |
| | | @blur="handleQuantityBlur" |
| | | :disabled="isViewMode" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">吨</i> |
| | |
| | | </el-form-item> |
| | | <el-form-item label="税率" prop="taxRate"> |
| | | <el-input |
| | | v-model.number="form.taxRate" |
| | | placeholder="请输入税率" |
| | | @blur="handleTaxRateBlur" |
| | | :disabled="isViewMode" |
| | | v-model.number="form.taxRate" |
| | | placeholder="请输入税率" |
| | | @blur="handleTaxRateBlur" |
| | | :disabled="isViewMode" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">%</i> |
| | |
| | | </el-form-item> |
| | | <el-form-item label="单价(含税)" prop="priceIncludingTax"> |
| | | <el-input |
| | | v-model.number="form.priceIncludingTax" |
| | | placeholder="请输入含税单价" |
| | | @blur="handlePriceBlur" |
| | | :disabled="isViewMode" |
| | | v-model.number="form.priceIncludingTax" |
| | | placeholder="请输入含税单价" |
| | | @blur="handlePriceBlur" |
| | | :disabled="isViewMode" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">元</i> |
| | |
| | | </el-form-item> |
| | | <el-form-item label="单价(不含税)" prop="priceExcludingTax"> |
| | | <el-input |
| | | v-model.number="form.priceExcludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | v-model.number="form.priceExcludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">元</i> |
| | |
| | | </el-form-item> |
| | | <el-form-item label="总价(不含税)" prop="totalPriceExcludingTax"> |
| | | <el-input |
| | | v-model.number="form.totalPriceExcludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | v-model.number="form.totalPriceExcludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">元</i> |
| | |
| | | </el-form-item> |
| | | <el-form-item label="总价(含税)" prop="totalPriceIncludingTax"> |
| | | <el-input |
| | | v-model.number="form.totalPriceIncludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | v-model.number="form.totalPriceIncludingTax" |
| | | placeholder="自动计算" |
| | | disabled |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">元</i> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="运费" prop="freight"> |
| | | <!-- 默认为0 --> |
| | | <el-input |
| | | type="number" |
| | | :precision="2" |
| | | v-model.number="form.freight" |
| | | placeholder="请输入运费" |
| | | :disabled="isViewMode" |
| | | > |
| | | <template v-slot:suffix> |
| | | <i style="font-style: normal">元</i> |
| | |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="登记人" prop="registrantId"> |
| | | <el-input :value="match(form.registrantId)" v-model.number="form.registrantId" disabled placeholder="请输入"/> |
| | | <el-input |
| | | :value="match(form.registrantId)" |
| | | v-model.number="form.registrantId" |
| | | disabled |
| | | placeholder="请输入" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="登记日期" prop="registrationDate"> |
| | | <el-date-picker |
| | | disabled |
| | | v-model="form.registrationDate" |
| | | type="date" |
| | | placeholder="YYYY-MM-DD" |
| | | style="width: 100%" |
| | | value-format="YYYY-MM-DD" |
| | | disabled |
| | | v-model="form.registrationDate" |
| | | type="date" |
| | | placeholder="YYYY-MM-DD" |
| | | style="width: 100%" |
| | | value-format="YYYY-MM-DD" |
| | | /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <!-- 重置和取消 --> |
| | | <el-button @click="handleClose" v-if="title.includes('新增') || title.includes('查看')" |
| | | >取消 |
| | | </el-button |
| | | > |
| | | <el-button |
| | | @click="handleClose" |
| | | v-if="title.includes('新增') || title.includes('查看')" |
| | | >取消 |
| | | </el-button> |
| | | <el-button @click="handleReset" v-if="title.includes('编辑')" |
| | | >重置 |
| | | </el-button |
| | | >重置 |
| | | </el-button> |
| | | <el-button type="primary" v-if="!isViewMode" @click="handleSubmit" |
| | | >确认</el-button |
| | | > |
| | | <el-button type="primary" v-if="!isViewMode" @click="handleSubmit">确认</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | </template> |
| | | |
| | | <script setup name="ProductionDialog"> |
| | | import {ref, defineProps, watch, onMounted, nextTick, computed} from "vue"; |
| | | import {ElMessage} from "element-plus"; |
| | | import { ref, defineProps, watch, onMounted, nextTick, computed } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | import {addOrEditPR, getSupplyList, getCoalInfoList} from "@/api/procureMent"; |
| | | import { addOrEditPR, getSupplyList, getCoalInfoList } from "@/api/procureMent"; |
| | | |
| | | const props = defineProps({ |
| | | title: { |
| | |
| | | if (isNaN(num) || num === null || num === undefined || num === "") { |
| | | return 0; |
| | | } |
| | | return Number((Math.floor(parseFloat(num) * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision)); |
| | | return Number( |
| | | ( |
| | | Math.floor(parseFloat(num) * Math.pow(10, precision)) / |
| | | Math.pow(10, precision) |
| | | ).toFixed(precision) |
| | | ); |
| | | }; |
| | | |
| | | // 安全获取数值 |
| | |
| | | |
| | | // 1. 根据含税单价和税率计算不含税单价 |
| | | // 不含税单价 = 含税单价 / (1 + 税率/100) |
| | | const priceExcludingTax = priceIncludingTax && taxRate |
| | | ? parseFloat((priceIncludingTax / (1 + taxRate / 100)).toFixed(2)) |
| | | : 0; |
| | | const priceExcludingTax = |
| | | priceIncludingTax && taxRate |
| | | ? parseFloat((priceIncludingTax / (1 + taxRate / 100)).toFixed(2)) |
| | | : 0; |
| | | |
| | | // 2. 计算不含税总价 = 不含税单价 × 数量 |
| | | const totalPriceExcludingTax = priceExcludingTax && quantity |
| | | ? toFixed(priceExcludingTax * quantity, 2) |
| | | : 0; |
| | | const totalPriceExcludingTax = |
| | | priceExcludingTax && quantity |
| | | ? toFixed(priceExcludingTax * quantity, 2) |
| | | : 0; |
| | | |
| | | // 3. 计算含税总价 = 含税单价 × 数量 |
| | | const totalPriceIncludingTax = priceIncludingTax && quantity |
| | | ? toFixed(priceIncludingTax * quantity, 2) |
| | | : 0; |
| | | const totalPriceIncludingTax = |
| | | priceIncludingTax && quantity |
| | | ? toFixed(priceIncludingTax * quantity, 2) |
| | | : 0; |
| | | |
| | | // 保证显示为两位小数(如88.5显示为88.50) |
| | | form.value.priceExcludingTax = priceExcludingTax.toFixed(2); |
| | |
| | | |
| | | // 监听表单对象变化,用于处理编辑模式下的数据加载和实时计算 |
| | | watch( |
| | | () => [form.value.priceIncludingTax, form.value.taxRate, form.value.purchaseQuantity], |
| | | () => [ |
| | | form.value.priceIncludingTax, |
| | | form.value.taxRate, |
| | | form.value.purchaseQuantity, |
| | | ], |
| | | () => { |
| | | // 防抖处理,避免频繁计算 |
| | | nextTick(() => { |
| | |
| | | }; |
| | | // 处理税率输入框失焦事件 |
| | | const handleTaxRateBlur = () => { |
| | | if (form.value.taxRate !== null && form.value.taxRate !== undefined && form.value.taxRate !== "") { |
| | | if ( |
| | | form.value.taxRate !== null && |
| | | form.value.taxRate !== undefined && |
| | | form.value.taxRate !== "" |
| | | ) { |
| | | form.value.taxRate = toFixed(parseFloat(form.value.taxRate), 2); |
| | | // watch 会自动触发 calculatePrices,不需要手动调用 |
| | | } |
| | |
| | | |
| | | // 处理含税单价输入框失焦事件 |
| | | const handlePriceBlur = () => { |
| | | if (form.value.priceIncludingTax !== null && form.value.priceIncludingTax !== undefined && form.value.priceIncludingTax !== "") { |
| | | form.value.priceIncludingTax = toFixed(parseFloat(form.value.priceIncludingTax), 2); |
| | | if ( |
| | | form.value.priceIncludingTax !== null && |
| | | form.value.priceIncludingTax !== undefined && |
| | | form.value.priceIncludingTax !== "" |
| | | ) { |
| | | form.value.priceIncludingTax = toFixed( |
| | | parseFloat(form.value.priceIncludingTax), |
| | | 2 |
| | | ); |
| | | // watch 会自动触发 calculatePrices,不需要手动调用 |
| | | } |
| | | }; |
| | | |
| | | // 处理采购数量输入框失焦事件 |
| | | const handleQuantityBlur = () => { |
| | | if (form.value.purchaseQuantity !== null && form.value.purchaseQuantity !== undefined && form.value.purchaseQuantity !== "") { |
| | | form.value.purchaseQuantity = toFixed(parseFloat(form.value.purchaseQuantity), 3); // 数量保留3位小数 |
| | | if ( |
| | | form.value.purchaseQuantity !== null && |
| | | form.value.purchaseQuantity !== undefined && |
| | | form.value.purchaseQuantity !== "" |
| | | ) { |
| | | form.value.purchaseQuantity = toFixed( |
| | | parseFloat(form.value.purchaseQuantity), |
| | | 3 |
| | | ); // 数量保留3位小数 |
| | | // watch 会自动触发 calculatePrices,不需要手动调用 |
| | | } |
| | | }; |
| | |
| | | }); |
| | | const rules = { |
| | | supplierName: [ |
| | | {required: true, message: "请输入供应商名称", trigger: "blur"}, |
| | | { required: true, message: "请输入供应商名称", trigger: "blur" }, |
| | | ], |
| | | coal: [{required: true, message: "请输入煤种", trigger: "blur"}], |
| | | coal: [{ required: true, message: "请输入煤种", trigger: "blur" }], |
| | | purchaseQuantity: [ |
| | | {required: true, message: "请输入采购数量", trigger: "blur"}, |
| | | {type: "number", message: "采购数量必须为数字", trigger: "blur"}, |
| | | { required: true, message: "请输入采购数量", trigger: "blur" }, |
| | | { type: "number", message: "采购数量必须为数字", trigger: "blur" }, |
| | | ], |
| | | priceExcludingTax: [ |
| | | {required: true, message: "请输入单价", trigger: "blur"}, |
| | | { required: true, message: "请输入单价", trigger: "blur" }, |
| | | ], |
| | | priceIncludingTax: [ |
| | | {required: true, message: "请输入含税单价", trigger: "blur"}, |
| | | { required: true, message: "请输入含税单价", trigger: "blur" }, |
| | | ], |
| | | taxRate:[ |
| | | {required: true, message: "请输入税率", trigger: "blur"}, |
| | | {type: "number", message: "税率必须为数字", trigger: "blur"}, |
| | | ] |
| | | taxRate: [ |
| | | { required: true, message: "请输入税率", trigger: "blur" }, |
| | | { type: "number", message: "税率必须为数字", trigger: "blur" }, |
| | | ], |
| | | }; |
| | | // 关闭弹窗 |
| | | const handleClose = () => { |