radioGroup.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. <div class="title" v-if="val.customerClueName">
  10. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  11. {{ val.customerClueName }}
  12. </div>
  13. <van-radio-group v-model="val.searchValue" @change="radioGroupChange">
  14. <template v-for="(item, index) in val.customerClueOptionList">
  15. <van-radio :name="item.customerClueOptionId" @click="radioClick" :key="index">
  16. {{ item.customerClueOption }}
  17. </van-radio>
  18. <radioGroup
  19. :clueOptionList="item.customerClueItemList"
  20. :parentOptionList="val"
  21. :parentId="item.customerClueOptionId"
  22. v-if="val.searchValue == item.customerClueOptionId"></radioGroup>
  23. </template>
  24. </van-radio-group>
  25. </template>
  26. <!-- 回答类型:wb-文本,sz-数字,rq-日期,zp-照片,dx-单选,bg-表格 -->
  27. <template v-if="val.answerType == 'wb'">
  28. <div class="title" v-if="val.customerClueName">
  29. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  30. {{ val.customerClueName }}
  31. </div>
  32. <template v-if="parentOptionList.searchValue == val.itemOptionParentId">
  33. <van-field
  34. v-model="val.answerValue"
  35. :placeholder="val.remark"
  36. :minTextLength="val.minTextLength"
  37. :error-message="val.remark"
  38. :class="{
  39. fieldInput: true,
  40. rulesClass: val.answerValue != null && val.answerValue.length < val.minTextLength,
  41. }" />
  42. <span
  43. class="rulesErrorMessage"
  44. v-if="val.answerValue != null && val.answerValue.length < val.minTextLength">
  45. {{ val.remark }}
  46. </span>
  47. </template>
  48. </template>
  49. <!-- 数字输入框 -->
  50. <template v-if="val.answerType == 'sz'">
  51. <div class="title" v-if="val.customerClueName">
  52. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  53. {{ val.customerClueName }}
  54. </div>
  55. <van-field
  56. class="fieldInput"
  57. v-model="val.answerValue"
  58. :placeholder="val.remark"
  59. :minTextLength="val.minTextLength"
  60. :error-message="val.remark"
  61. type="number"></van-field>
  62. </template>
  63. <!-- 表格 -->
  64. <template v-if="val.answerType == 'bg'">
  65. <div class="title" v-if="val.customerClueName">
  66. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  67. {{ val.customerClueName }}
  68. </div>
  69. <el-table :data="val.tableData.data" style="width: 100%; position: relative; left: -10px">
  70. <el-table-column
  71. v-for="(item, index) in val.tableData.title"
  72. :prop="item.prop"
  73. :label="item.label"
  74. align="center">
  75. <template slot-scope="scope">
  76. <template v-if="item.answerType == 'text'">
  77. {{ scope.row[item.prop] }}
  78. </template>
  79. <template v-if="item.answerType == 'wb'">
  80. <van-field v-model="scope.row[item.prop]" />
  81. </template>
  82. <!-- 正整数 digit -->
  83. <template v-if="item.answerType == 'sz'">
  84. <van-field v-model="scope.row[item.prop]" type="digit" />
  85. </template>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </template>
  90. </template>
  91. </div>
  92. </template>
  93. <script>
  94. export default {
  95. name: 'radioGroup',
  96. props: {
  97. clueOptionList: {
  98. type: Array,
  99. default: () => [],
  100. },
  101. parentOptionList: {
  102. type: Object,
  103. default: () => {},
  104. },
  105. parentId: {
  106. type: [Number, null],
  107. default: null,
  108. },
  109. },
  110. data() {
  111. return {};
  112. },
  113. watch: {
  114. clueOptionList: {
  115. handler(val) {
  116. val.forEach((item) => {
  117. // bg表格数据存在remark
  118. if (item.answerType == 'bg') {
  119. this.$set(item, 'tableData', JSON.parse(item.remark));
  120. }
  121. });
  122. },
  123. immediate: true,
  124. },
  125. },
  126. created() {
  127. // console.log(this.clueOptionList);
  128. },
  129. methods: {
  130. radioGroupChange(name) {
  131. if (!name) return;
  132. // console.log(name);
  133. // console.log(this.clueOptionList);
  134. // 如果选中的数据有父级,将父级数据修改为选中状态
  135. if (this.parentOptionList && this.parentId) {
  136. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  137. }
  138. // 获取选中数据
  139. let clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  140. let activaRadio = clueOptionList.customerClueOptionList.find(
  141. (val) => val.customerClueOptionId == name
  142. );
  143. // 修改选中状态
  144. this.$set(activaRadio, 'value', 'Y');
  145. // 过滤未选中的数据
  146. let exceptItself = clueOptionList.customerClueOptionList.filter(
  147. (val) => val.customerClueOptionId !== name
  148. );
  149. // 删除未选中数据状态兄弟级和子级
  150. // console.log(exceptItself);
  151. this.toggleOtheChildren(exceptItself);
  152. },
  153. toggleOtheChildren(exceptItself) {
  154. if (!exceptItself) return;
  155. exceptItself.forEach((val) => {
  156. this.$set(val, 'value', 'N');
  157. if (val.customerClueItemList && val.customerClueItemList[0]) {
  158. this.$set(val.customerClueItemList[0], 'searchValue', null);
  159. if (
  160. val.customerClueItemList[0] &&
  161. val.customerClueItemList[0].customerClueOptionList.length
  162. ) {
  163. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  164. }
  165. }
  166. });
  167. },
  168. radioClick(event) {
  169. // console.log(event);
  170. },
  171. },
  172. };
  173. </script>
  174. <style lang="scss">
  175. .radioGroup {
  176. font-size: 15px;
  177. .van-radio {
  178. padding: 5px 0;
  179. }
  180. .van-radio-group {
  181. padding-left: 20px;
  182. }
  183. .van-cell {
  184. padding: 10px 0;
  185. /* font-size: 14px; */
  186. }
  187. .van-cell::after {
  188. border: 0;
  189. }
  190. .van-field {
  191. padding: 0;
  192. width: 100%;
  193. border-radius: 4px;
  194. overflow: hidden;
  195. background-color: unset;
  196. height: 30px;
  197. line-height: 30px;
  198. border: 1px solid #cdc8c8;
  199. }
  200. .van-field__control {
  201. /* padding: 0 10px; */
  202. /* margin: 5px 0; */
  203. padding-left: 10px;
  204. }
  205. .van-radio__label {
  206. /* font-size: 14px; */
  207. }
  208. .van-f-red {
  209. font-size: 14px;
  210. }
  211. .rulesClass {
  212. border: 1px solid #ff0505;
  213. }
  214. .fieldInput {
  215. /* height: 38px; */
  216. }
  217. .rulesErrorMessage {
  218. color: red;
  219. font-size: 12px;
  220. padding: 3px 0;
  221. }
  222. .uploadImg {
  223. width: 50px;
  224. }
  225. .el-table {
  226. .el-table__cell {
  227. padding: 3px 0;
  228. }
  229. }
  230. }
  231. </style>