index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="collspseBox">
  3. <van-row class="collspse_item" v-for="(item, index) in ruleTree" :key="item.id" >
  4. <van-col class="icon" span="2" @click.stop="open(item, index)">
  5. <van-icon v-if="item.child && item.child.length > 0" size="16" :name="item.active ? 'arrow-down' : 'arrow'" />
  6. </van-col>
  7. <van-col span="22" class="title" :class="currentRuleId == item.id ? 'item-active' : 'item-gray'" @click.stop="open(item, index)">
  8. <label style="display: flex; align-items: center;">
  9. <input class="radio_button" type="radio" :checked="currentRuleId == item.id" :value="item.id" name="treeGroup" @change="handleChange(item)">
  10. {{ item.name }}
  11. </label>
  12. </van-col>
  13. <van-col span="24" class="content" v-if="item.child && item.child.length > 0" :style="{ height: item.active ? 'auto' : '0' }">
  14. <collapse :currentRuleId="currentRuleId" :ruleTree="item.child" @open="$emit('open', $event)" />
  15. </van-col>
  16. </van-row>
  17. </div>
  18. </template>
  19. <!-- -->
  20. <script>
  21. export default {
  22. name: "collapse",
  23. props: {
  24. ruleTree: Array,
  25. currentRuleId: {
  26. type: [String, Number],
  27. default: 0
  28. },
  29. },
  30. data() {
  31. return {
  32. selectId: 0,
  33. }
  34. },
  35. methods: {
  36. handleChange(item) {
  37. this.$emit("open", item);
  38. },
  39. open(item, index) {
  40. this.$set(this.ruleTree[index], 'active', !this.ruleTree[index].active);
  41. },
  42. }
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .item-active {
  47. color: #409EFF !important;
  48. }
  49. .item-gray {
  50. color: #323233 !important;
  51. }
  52. .collspseBox {
  53. padding: 14px 10px;
  54. .collspse_item {
  55. background-color: #fff;
  56. padding: 15px 12px;
  57. border-radius: 8px;
  58. overflow: hidden;
  59. margin-bottom: 10px;
  60. box-shadow: 0 0px 6px rgba(100, 101, 102, 0.1);
  61. .icon {
  62. text-align: center;
  63. vertical-align: middle;
  64. color: #d2d2d2;
  65. }
  66. .title {
  67. font-size: 0.32rem;
  68. color: #323233;
  69. display: flex;
  70. align-items: center;
  71. white-space: nowrap;
  72. text-wrap: nowrap;
  73. word-break: keep-all;
  74. overflow: hidden;
  75. text-overflow: ellipsis;
  76. /* 单选框样式 */
  77. .radio_button {
  78. -webkit-appearance: none; /* 移除默认样式 */
  79. appearance: none; /* 移除默认样式 */
  80. outline: none; /* 移除轮廓 */
  81. display: inline-block;
  82. width: 0.3rem; /* 设置宽度 */
  83. height: 0.3rem; /* 设置高度 */
  84. border-radius: 50%; /* 设置为圆形 */
  85. background-color: white; /* 初始背景颜色为白色 */
  86. position: relative; /* 设置相对定位 */
  87. margin: 0 8px 0 0; /* 设置边距 */
  88. border: 1px solid #d2d2d2;
  89. cursor: pointer; /* 设置鼠标指针为手型 */
  90. }
  91. .radio_button:checked {
  92. width: 0.3rem; /* 设置宽度 */
  93. height: 0.3rem; /* 设置高度 */
  94. background-color: #409EFF; /* 选中时中心白色 */
  95. border: none; /* 选中时去掉边框 */
  96. z-index: 2; /* 确保在最上面 */
  97. }
  98. .radio_button:checked::before {
  99. content: "";
  100. position: absolute;
  101. top: 50%; /* 使伪元素垂直居中 */
  102. left: 50%; /* 使伪元素水平居中 */
  103. transform: translate(-50%, -50%); /* 使伪元素水平垂直居中 */
  104. width: 0.12rem;
  105. height: 0.12rem;
  106. border-radius: 50%; /* 使伪元素变成圆形 */
  107. background-color: #ffffff; /* 外部红色 */
  108. z-index: 1; /* 确保伪元素在最前面 */
  109. }
  110. }
  111. .content {
  112. transition: all .5s;
  113. .collspseBox {
  114. padding: 0;
  115. .collspse_item {
  116. padding: 16px 0 0 12px;
  117. margin-bottom: 0;
  118. box-shadow: none;
  119. .title {
  120. display: flex;
  121. align-items: center;
  122. font-size: 0.3rem;
  123. color: #2F3541;
  124. font-family: "PingFang SC";
  125. font-weight: 400;
  126. position: relative;
  127. padding-left: 5px;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. </style>