| | |
| | | <script setup lang="ts"> |
| | | import { onMounted, ref, reactive } from "vue"; |
| | | import { onMounted, ref, reactive, computed } from "vue"; |
| | | import ReCol from "@/components/ReCol"; |
| | | import { formRules } from "./utils/rule"; |
| | | import { FormProps } from "./utils/types"; |
| | |
| | | import { getCaigoufangshiList } from "@/api/item/index"; |
| | | |
| | | const { state, nowRole } = useDept(ref({})); |
| | | // 递归查找label的函数 |
| | | const findLabelsByValues = (values, options, currentLabels = []) => { |
| | | if (!values.length || !options) return currentLabels; |
| | | |
| | | const [firstValue, ...restValues] = values; |
| | | const matched = options.find(item => item.code === firstValue); |
| | | |
| | | if (matched) { |
| | | currentLabels.push(matched.name); |
| | | // 继续查找下一级 |
| | | return findLabelsByValues(restValues, matched.regions, currentLabels); |
| | | } |
| | | return currentLabels; |
| | | }; |
| | | // 计算属性:根据selectedValue动态获取label |
| | | const selectedLabels = computed(() => { |
| | | return findLabelsByValues( |
| | | newFormInline.value.xingzhengquyu, |
| | | state.regionList |
| | | ).join(""); |
| | | }); |
| | | const props = withDefaults(defineProps<FormProps>(), { |
| | | formInline: () => ({ |
| | | id: "", |
| | |
| | | return ruleFormRef.value; |
| | | } |
| | | const handleChange = value => { |
| | | console.log(value); |
| | | newFormInline.value.xingzhengquyuName = selectedLabels.value; |
| | | }; |
| | | const selectChange = value => { |
| | | let obj = state.caigoufangshiList.find(item => { |