import { defineComponent, onMounted, reactive } from "vue"; import styles from "./index.module.less"; import { Button, showToast } from "vant"; export default defineComponent({ name: "change-subject", props: { subjectList: { type: Array, default: () => [], }, subject: { type: String, default: "", }, }, emits: ["close", "confirm"], setup(props, { emit }) { const state = reactive({ subjectValue: null as any, instrumentCode: null as any, selectList: [] as any, }); // const selectItem = () => { // const i: any = props.subjectList.find((item: any) => item.value === props.subject); // if (i) { // state.subjectValue = i.id; // state.instrumentCode = i.value; // state.selectList = []; // } // const i: any = props.subjectList.find((item: any) => item.value === props.subject); let i: any = {}; props.subjectList.forEach((item: any) => { if (Array.isArray(item.children)) { item.children.forEach((child: any) => { if (child.value === props.subject) { i = { ...child, parentId: item.id, }; state.instrumentCode = child.value; state.subjectValue = item.id; state.selectList = item.children || []; } }); } }); if (!i) { props.subjectList.forEach((item: any) => { if (item.children && item.children.length > 0) { item.children.forEach((child: any) => { if (child.value === props.subject) { state.instrumentCode = child.value; state.subjectValue = item.id; state.selectList = item.children; } }); } }); } }; onMounted(() => { console.log(props.subjectList, "subjectList", props.subject); selectItem(); }); return () => (