radioGroup.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="radioGroup">
  3. <template v-for="(val, ind) in clueOptionList">
  4. <div class="title" v-if="val.customerClueName">
  5. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  6. {{ val.customerClueName }}
  7. </div>
  8. <template v-if="val.answerType == 'dx'">
  9. <van-radio-group v-model="val.searchValue" @change="radioGroupChange">
  10. <template v-for="(item, index) in val.customerClueOptionList">
  11. <van-radio :name="item.customerClueOptionId" :key="index" @click="radioClick">
  12. {{ item.customerClueOption }}
  13. </van-radio>
  14. <radioGroup
  15. :clueOptionList="item.customerClueItemList"
  16. :parentOptionList="val"
  17. :parentId="item.customerClueOptionId"
  18. v-if="val.searchValue == item.customerClueOptionId"></radioGroup>
  19. </template>
  20. </van-radio-group>
  21. </template>
  22. <template v-if="val.answerType == 'wb'">
  23. <template v-if="parentOptionList.searchValue == val.itemOptionParentId">
  24. <van-field v-model="val.answerValue" :placeholder="val.remark" />
  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 clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  64. let activaRadio = clueOptionList.customerClueOptionList.find(
  65. (val) => val.customerClueOptionId == name
  66. );
  67. // 修改选中状态
  68. this.$set(activaRadio, 'value', 'Y');
  69. // 过滤未选中的数据
  70. let exceptItself = clueOptionList.customerClueOptionList.filter(
  71. (val) => val.customerClueOptionId !== name
  72. );
  73. // 删除未选中数据状态兄弟级和子级
  74. // console.log(exceptItself);
  75. this.toggleOtheChildren(exceptItself);
  76. },
  77. toggleOtheChildren(exceptItself) {
  78. if (!exceptItself) return;
  79. exceptItself.forEach((val) => {
  80. this.$set(val, 'value', 'N');
  81. if (val.customerClueItemList && val.customerClueItemList[0]) {
  82. this.$set(val.customerClueItemList[0], 'searchValue', null);
  83. if (
  84. val.customerClueItemList[0] &&
  85. val.customerClueItemList[0].customerClueOptionList.length
  86. ) {
  87. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  88. }
  89. }
  90. });
  91. },
  92. radioClick(event) {
  93. // console.log(event);
  94. },
  95. },
  96. };
  97. </script>
  98. <style lang="scss">
  99. .radioGroup {
  100. font-size: 15px;
  101. .van-radio {
  102. padding: 5px 0;
  103. }
  104. .van-radio-group {
  105. padding-left: 20px;
  106. }
  107. .van-cell {
  108. padding: 10px 0;
  109. /* font-size: 14px; */
  110. }
  111. .van-cell::after {
  112. border: 0;
  113. }
  114. .van-field {
  115. border: 1px solid #cdc8c8;
  116. padding: 0;
  117. width: 100%;
  118. border-radius: 4px;
  119. overflow: hidden;
  120. background-color: unset;
  121. height: 30px;
  122. line-height: 30px;
  123. margin: 5px 0;
  124. }
  125. .van-field__control {
  126. padding: 0 10px;
  127. }
  128. .van-field__control {
  129. padding: 0 10px;
  130. }
  131. .van-radio__label {
  132. /* font-size: 14px; */
  133. }
  134. }
  135. </style>