|
@@ -0,0 +1,78 @@
|
|
|
+<template>
|
|
|
+ <div :style="{ marginLeft: level * 20 + 'px' }">
|
|
|
+ <template v-for="(question, questionIndex) in data">
|
|
|
+ <div>{{ questionIndex + 1 }}、{{ question.conditionname }}</div>
|
|
|
+ <template v-if="question.optiontype === 'single'">
|
|
|
+ <template v-for="(answer, answerIndex) in question.children">
|
|
|
+ <div
|
|
|
+ class="__hover flex w-fit items-center px-2"
|
|
|
+ @click="question.__answer = answer.id"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ class="my-2 mr-2 size-5 rounded-full border"
|
|
|
+ :class="
|
|
|
+ answer.id === question.__answer
|
|
|
+ ? 'bg-[var(--czr-main-color)]'
|
|
|
+ : ''
|
|
|
+ "
|
|
|
+ />
|
|
|
+ {{ answer.conditionname }}
|
|
|
+ </div>
|
|
|
+ <template v-if="answer.id === question.__answer">
|
|
|
+ <treeNode
|
|
|
+ :data="answer.children"
|
|
|
+ :parentIndex="questionIndex"
|
|
|
+ :level="level + 1"
|
|
|
+ ref="ref_treeNode"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <div>{{ question.optiontype }}</div>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { reactive, ref } from 'vue'
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ data: { default: () => [] },
|
|
|
+ level: { default: 0 },
|
|
|
+ parentIndex: { default: 0 },
|
|
|
+})
|
|
|
+const state: any = reactive({})
|
|
|
+const ref_treeNode = ref()
|
|
|
+
|
|
|
+const getAnswer = () => {
|
|
|
+ const arr: any = []
|
|
|
+ console.log(ref_treeNode)
|
|
|
+ props.data.forEach((question, questionIndex) => {
|
|
|
+ arr.push([question.__answer])
|
|
|
+ })
|
|
|
+ ref_treeNode.value?.forEach((v, i) => {
|
|
|
+ console.log(v.getAnswer())
|
|
|
+ v.getAnswer().forEach((a) => {
|
|
|
+ a.forEach((b) => {
|
|
|
+ arr[v.parentIndex].push(b)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return arr
|
|
|
+}
|
|
|
+defineExpose({
|
|
|
+ getAnswer,
|
|
|
+ parentIndex: props.parentIndex,
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+:deep(.el-radio-group) {
|
|
|
+ flex-direction: column;
|
|
|
+ .el-radio {
|
|
|
+ margin: 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|