radioGroup.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="radioGroup">
  3. <template v-if="clueOptionList && clueOptionList.length">
  4. <template v-if="clueOptionList[0].answerType == 'dx'">
  5. <van-radio-group v-model="clueOptionList[0].searchValue" @change="radioGroupChange">
  6. <template v-for="(item, index) in clueOptionList[0].customerClueOptionList">
  7. <van-radio :name="item.customerClueOptionId" :key="index" @click="radioClick">
  8. {{ item.customerClueOption }}
  9. </van-radio>
  10. <radioGroup
  11. :clueOptionList="item.customerClueItemList"
  12. :parentOptionList="clueOptionList[0]"
  13. :parentId="item.customerClueOptionId"></radioGroup>
  14. </template>
  15. </van-radio-group>
  16. </template>
  17. <template v-for="(item, index) in clueOptionList" v-if="clueOptionList.length">
  18. <!-- {{ clueOptionList }} -->
  19. <template v-if="item.answerType == 'wb'">
  20. <template v-if="parentOptionList.searchValue == item.itemOptionParentId">
  21. <span class="van-f-red" v-if="item.isMust == 0">*</span>
  22. {{ item.customerClueName }}
  23. <van-field v-model="item.answerValue" :placeholder="item.remark" />
  24. </template>
  25. </template>
  26. </template>
  27. </template>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'radioGroup',
  33. props: {
  34. clueOptionList: {
  35. type: Array,
  36. default: () => [],
  37. },
  38. parentOptionList: {
  39. type: Object,
  40. default: () => {},
  41. },
  42. parentId: {
  43. type: [Number, null],
  44. default: null,
  45. },
  46. },
  47. data() {
  48. return {};
  49. },
  50. created() {
  51. // console.log(this.clueOptionList);
  52. },
  53. methods: {
  54. radioGroupChange(name) {
  55. if (!name) return;
  56. // console.log(name);
  57. // console.log(this.clueOptionList);
  58. // 如果选中的数据有父级,将父级数据修改为选中状态
  59. if (this.parentOptionList && this.parentId) {
  60. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  61. }
  62. // 获取选中数据
  63. let activaRadio = this.clueOptionList[0].customerClueOptionList.find(
  64. (val) => val.customerClueOptionId == name
  65. );
  66. // 修改选中状态
  67. this.$set(activaRadio, 'value', 'Y');
  68. // 过滤未选中的数据
  69. let exceptItself = this.clueOptionList[0].customerClueOptionList.filter(
  70. (val) => val.customerClueOptionId !== name
  71. );
  72. // 删除未选中数据状态兄弟级和子级
  73. // console.log(exceptItself);
  74. this.toggleOtheChildren(exceptItself);
  75. },
  76. toggleOtheChildren(exceptItself) {
  77. if (!exceptItself) return;
  78. exceptItself.forEach((val) => {
  79. this.$set(val, 'value', 'N');
  80. if (val.customerClueItemList && val.customerClueItemList[0]) {
  81. this.$set(val.customerClueItemList[0], 'searchValue', null);
  82. if (
  83. val.customerClueItemList[0] &&
  84. val.customerClueItemList[0].customerClueOptionList.length
  85. ) {
  86. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  87. }
  88. }
  89. });
  90. },
  91. radioClick(event) {
  92. // console.log(event);
  93. },
  94. },
  95. };
  96. </script>
  97. <style lang="scss">
  98. .radioGroup {
  99. padding: 5px;
  100. .van-radio-group {
  101. padding-left: 20px;
  102. }
  103. .van-cell {
  104. padding: 10px 0;
  105. font-size: 14px;
  106. }
  107. .van-cell::after {
  108. border: 0;
  109. }
  110. .van-field {
  111. border: 1px solid #cdc8c8;
  112. padding: 0;
  113. width: 100%;
  114. border-radius: 4px;
  115. overflow: hidden;
  116. background-color: unset;
  117. height: 30px;
  118. line-height: 30px;
  119. margin: 5px 0;
  120. }
  121. .van-field__control {
  122. padding: 0 10px;
  123. }
  124. .van-field__control {
  125. padding: 0 10px;
  126. }
  127. }
  128. </style>