• js多级嵌套选中效果代码实现-vue


    多级嵌套选中

    1. <script lang="ts">
    2. import { defineComponent, ref } from 'vue';
    3. import CommonUtils from '@utils/common-utils';
    4. export default defineComponent({
    5. setup() {
    6. const infoArr = ref([
    7. {
    8. id: 1,
    9. checked: true,
    10. drug: [
    11. { id: 1.1, drugDetail: [{ checked: true }, { checked: false }] },
    12. { id: 1.2, drugDetail: [{ checked: false }, { checked: false }] },
    13. ],
    14. },
    15. {
    16. id: 2,
    17. checked: false,
    18. drug: [
    19. { id: 2.1, drugDetail: [{ checked: false }, { checked: false }] },
    20. { id: 2.2, drugDetail: [{ checked: true }, { checked: false }] },
    21. ],
    22. },
    23. ]);
    24. const checkedDrug = (index: number, pharmacy: boolean, littleIndex?: number, indexValue?: number) => {
    25. if (pharmacy) {
    26. for (let i = 0; i < infoArr.value.length; i++) {
    27. if (i === index) {
    28. infoArr.value[i].checked = !infoArr.value[i].checked;
    29. } else {
    30. infoArr.value[i].checked = false;
    31. }
    32. }
    33. } else {
    34. for (let i = 0; i < infoArr.value.length; i++) {
    35. if (i === index) {
    36. for (let s = 0; s < infoArr.value[i].drug.length; s++) {
    37. if (s === littleIndex) {
    38. for (let x = 0; x < infoArr.value[i].drug[s].drugDetail.length; x++) {
    39. if (x === indexValue) {
    40. infoArr.value[i].drug[s].drugDetail[x].checked = !infoArr.value[i].drug[s].drugDetail[x].checked;
    41. } else {
    42. infoArr.value[i].drug[s].drugDetail[x].checked = false;
    43. }
    44. }
    45. }
    46. }
    47. }
    48. }
    49. }
    50. };
    51. return { getImage: CommonUtils.getImageSrc, infoArr, checkedDrug };
    52. },
    53. });
    54. script>
    55. <style lang="scss" scoped>
    56. .box-unfold {
    57. background: linear-gradient(332deg, #8796ff 0%, #93b1ff 100%);
    58. border-radius: 8px 8px 0px 0px;
    59. opacity: 1;
    60. padding: 2rem;
    61. padding-bottom: 1rem;
    62. }
    63. .drug-name {
    64. width: 100%;
    65. line-height: 3rem;
    66. & span:first-child {
    67. float: left;
    68. font-size: 17px;
    69. font-family: PingFang SC-Bold, PingFang SC;
    70. font-weight: bold;
    71. color: #ffffff;
    72. background: url('../../assets/images/medication/checked_no.png') left center no-repeat;
    73. background-size: 2.4rem;
    74. padding-left: 3rem;
    75. }
    76. & span:last-child {
    77. float: right;
    78. font-size: 15px;
    79. font-family: PingFang SC-Medium, PingFang SC;
    80. font-weight: 500;
    81. color: #f2f3f5;
    82. padding: 1rem 1.5rem;
    83. text-align: center;
    84. line-height: 2rem;
    85. opacity: 1;
    86. border: 1px solid #f2f3f5;
    87. border-radius: 2.8rem;
    88. }
    89. }
    90. .number-show {
    91. width: 100%;
    92. line-height: 3rem;
    93. font-size: 14px;
    94. font-family: PingFang SC-Medium, PingFang SC;
    95. font-weight: 500;
    96. color: #ffffff;
    97. span {
    98. font-size: 17px;
    99. font-weight: bold;
    100. }
    101. }
    102. .its-address {
    103. margin-top: 1rem;
    104. font-size: 14px;
    105. font-family: PingFang SC-Medium, PingFang SC;
    106. font-weight: 500;
    107. color: #ffffff;
    108. width: 100%;
    109. line-height: 2rem;
    110. }
    111. .drug-info-loop {
    112. line-height: 2.5rem;
    113. padding: 1rem 2rem;
    114. }
    115. .name-part {
    116. font-size: 15px;
    117. font-family: PingFang SC-Bold, PingFang SC;
    118. font-weight: bold;
    119. color: #7891ec;
    120. }
    121. .data-export {
    122. margin-top: 1rem;
    123. font-size: 14px;
    124. font-family: PingFang SC-Medium, PingFang SC;
    125. font-weight: 500;
    126. display: flex;
    127. justify-content: space-between;
    128. align-items: center;
    129. .left-img {
    130. width: 20px;
    131. height: 20px;
    132. img {
    133. width: 100%;
    134. height: 100%;
    135. }
    136. }
    137. .right-text {
    138. width: 90%;
    139. }
    140. p:first-child {
    141. color: #333333;
    142. }
    143. p:last-of-type {
    144. color: #666666;
    145. }
    146. }
    147. .over-checked {
    148. background: linear-gradient(180deg, #dde4ff 0%, #ffffff 72%) !important;
    149. .drug-name {
    150. & span:first-child {
    151. color: #2b2b2b;
    152. background: url('../../assets/images/medication/checked_over.png') left center no-repeat;
    153. background-size: 2.4rem;
    154. padding-left: 3rem;
    155. }
    156. & span:last-child {
    157. background: linear-gradient(332deg, #8796ff 0%, #93b1ff 100%);
    158. color: #fff;
    159. }
    160. }
    161. .number-show {
    162. color: #333;
    163. span {
    164. color: #ff8c3f;
    165. }
    166. }
    167. .its-address {
    168. color: #333;
    169. }
    170. }
    171. style>

  • 相关阅读:
    Unity开发元宇宙多人交互XR应用
    Chrome、Edge 合力“围剿“,Safari 夹缝求生?
    Kubernetes的service详解
    OPEN数据 | 新库上线 | CnOpenDataA股上市公司社会责任报告数据
    没有对象怎么面向对象编程呢?这份风趣幽默的图解面向对象编程你值得拥有!
    根据面积均分球面 & c++示意代码
    数据库约束
    工程管理系统简介 工程管理系统源码 java工程管理系统 工程管理系统功能设计
    HP打印机一点击打印就出现Windows资源管理器已停止工作问题解决
    离子液体[C2MIm]SbF6/cas:305370-81-4/1-乙基-3-甲基咪唑六氟锑酸盐的密度值
  • 原文地址:https://blog.csdn.net/aZHANGJIANZHENa/article/details/126106322