radioGroup.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. <!-- 回答类型:wb-文本,sz-数字,rq-日期,zp-照片,dx -->
  23. <template v-if="val.answerType == 'wb'">
  24. <template v-if="parentOptionList.searchValue == val.itemOptionParentId">
  25. <van-field
  26. v-model="val.answerValue"
  27. :placeholder="val.remark"
  28. :minTextLength="val.minTextLength"
  29. :error-message="val.remark"
  30. :class="{
  31. fieldInput: true,
  32. rulesClass: val.answerValue != null && val.answerValue.length < val.minTextLength,
  33. }" />
  34. <span
  35. class="rulesErrorMessage"
  36. v-if="val.answerValue != null && val.answerValue.length < val.minTextLength">
  37. {{ val.remark }}
  38. </span>
  39. </template>
  40. </template>
  41. <template v-if="val.answerType == 'sz'">
  42. <van-field
  43. class="fieldInput"
  44. v-model="val.answerValue"
  45. :placeholder="val.remark"
  46. :minTextLength="val.minTextLength"
  47. :error-message="val.remark"
  48. type="number"></van-field>
  49. </template>
  50. </template>
  51. </div>
  52. </template>
  53. <script>
  54. export default {
  55. name: 'radioGroup',
  56. props: {
  57. clueOptionList: {
  58. type: Array,
  59. default: () => [],
  60. },
  61. parentOptionList: {
  62. type: Object,
  63. default: () => {},
  64. },
  65. parentId: {
  66. type: [Number, null],
  67. default: null,
  68. },
  69. },
  70. data() {
  71. return {};
  72. },
  73. created() {
  74. // console.log(this.clueOptionList);
  75. },
  76. methods: {
  77. radioGroupChange(name) {
  78. if (!name) return;
  79. // console.log(name);
  80. // console.log(this.clueOptionList);
  81. // 如果选中的数据有父级,将父级数据修改为选中状态
  82. if (this.parentOptionList && this.parentId) {
  83. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  84. }
  85. // 获取选中数据
  86. let clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  87. let activaRadio = clueOptionList.customerClueOptionList.find(
  88. (val) => val.customerClueOptionId == name
  89. );
  90. // 修改选中状态
  91. this.$set(activaRadio, 'value', 'Y');
  92. // 过滤未选中的数据
  93. let exceptItself = clueOptionList.customerClueOptionList.filter(
  94. (val) => val.customerClueOptionId !== name
  95. );
  96. // 删除未选中数据状态兄弟级和子级
  97. // console.log(exceptItself);
  98. this.toggleOtheChildren(exceptItself);
  99. },
  100. toggleOtheChildren(exceptItself) {
  101. if (!exceptItself) return;
  102. exceptItself.forEach((val) => {
  103. this.$set(val, 'value', 'N');
  104. if (val.customerClueItemList && val.customerClueItemList[0]) {
  105. this.$set(val.customerClueItemList[0], 'searchValue', null);
  106. if (
  107. val.customerClueItemList[0] &&
  108. val.customerClueItemList[0].customerClueOptionList.length
  109. ) {
  110. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  111. }
  112. }
  113. });
  114. },
  115. radioClick(event) {
  116. // console.log(event);
  117. },
  118. },
  119. };
  120. </script>
  121. <style lang="scss">
  122. .radioGroup {
  123. font-size: 15px;
  124. .van-radio {
  125. padding: 5px 0;
  126. }
  127. .van-radio-group {
  128. padding-left: 20px;
  129. }
  130. .van-cell {
  131. padding: 10px 0;
  132. /* font-size: 14px; */
  133. }
  134. .van-cell::after {
  135. border: 0;
  136. }
  137. .van-field {
  138. padding: 0;
  139. width: 100%;
  140. border-radius: 4px;
  141. overflow: hidden;
  142. background-color: unset;
  143. height: 30px;
  144. line-height: 30px;
  145. border: 1px solid #cdc8c8;
  146. }
  147. .van-field__control {
  148. /* padding: 0 10px; */
  149. /* margin: 5px 0; */
  150. padding-left: 10px;
  151. }
  152. .van-radio__label {
  153. /* font-size: 14px; */
  154. }
  155. .van-f-red {
  156. font-size: 14px;
  157. }
  158. .rulesClass {
  159. border: 1px solid #ff0505;
  160. }
  161. .fieldInput {
  162. /* height: 38px; */
  163. }
  164. .rulesErrorMessage {
  165. color: red;
  166. font-size: 12px;
  167. padding: 3px 0;
  168. }
  169. }
  170. </style>