| | |
| | | <el-col :span="12"> |
| | | <el-form-item label="油品" |
| | | prop="oilProduct" |
| | | :rules="isOilProduct ? [ |
| | | { |
| | | required: true, |
| | | message: '请选择油品', |
| | | trigger: 'change', |
| | | } |
| | | ] : []"> |
| | | <el-input v-if="isOilProduct" |
| | | :model-value="formState.oilProduct" |
| | | :rules="[{ required: true, message: '请选择油品', trigger: 'change' }]"> |
| | | <el-input :model-value="formState.oilProduct" |
| | | readonly |
| | | placeholder="--" /> |
| | | <el-select v-else |
| | | v-model="formState.oilProduct" |
| | | placeholder="请选择" |
| | | disabled |
| | | style="width: 100%" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | |
| | | import { allOilDepot } from "@/api/basicData/oilDepot.js"; |
| | | import { allTankInfo } from "@/api/basicData/tankInfo.js"; |
| | | import { listCustomer } from "@/api/basicData/customer.js"; |
| | | import { productTreeList } from "@/api/basicData/product.js"; |
| | | |
| | | const props = defineProps({ |
| | | visible: { |
| | |
| | | const oilDepotList = ref([]); |
| | | const tankList = ref([]); |
| | | const customerList = ref([]); |
| | | const oilProductOptions = ref([]); |
| | | |
| | | const isShow = computed({ |
| | | get() { |
| | | return props.visible; |
| | |
| | | emit("update:visible", val); |
| | | }, |
| | | }); |
| | | |
| | | // 在产品树中查找"油品"分类节点 |
| | | const findOilNode = nodes => { |
| | | for (const node of nodes || []) { |
| | | if (node.productName === "油品") { |
| | | return node; |
| | | } |
| | | if (node.children && node.children.length) { |
| | | const found = findOilNode(node.children); |
| | | if (found) { |
| | | return found; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | }; |
| | | |
| | | // 所选商品名称命中的油品选项(油品节点子项,来自产品维护模块) |
| | | const matchedOilOption = computed(() => |
| | | oilProductOptions.value.find( |
| | | item => item.productName === formState.value.productName |
| | | ) |
| | | ); |
| | | |
| | | // 只有选中油品字段选项里有的具体油品才启用油品字段;"油品"大类本身不启用 |
| | | const isOilProduct = computed(() => !!matchedOilOption.value); |
| | | |
| | | // 净重(吨) = 毛重 - 皮重 |
| | | const netWeight = computed(() => { |
| | |
| | | formState.value.productModelName = product.model; |
| | | formState.value.productModelId = product.id; |
| | | formState.value.unit = product.unit; |
| | | // 油品选项与商品名称同步:命中油品选项则自动带出该油品,未命中则清空并禁用 |
| | | formState.value.oilProduct = matchedOilOption.value |
| | | ? product.productName |
| | | : undefined; |
| | | // 本租户「油品」就是产品名称(库存明细/出库台账的油品列绑的都是 productName), |
| | | // 直接取所选产品名,不再去产品树里比对,避免比对不上时油品栏空白 |
| | | formState.value.oilProduct = product.productName || undefined; |
| | | showProductSelectDialog.value = false; |
| | | // 触发表单验证更新 |
| | | proxy.$refs["formRef"]?.validateField("productModelId"); |
| | |
| | | }); |
| | | listCustomer({ current: 1, size: 1000, type: 0 }).then(res => { |
| | | customerList.value = res?.data?.records || []; |
| | | }); |
| | | productTreeList().then(res => { |
| | | const oilNode = findOilNode(res); |
| | | oilProductOptions.value = oilNode?.children || []; |
| | | }); |
| | | }); |
| | | </script> |