radioGroup.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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" :key="index" @click="radioClick">
  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 -->
  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. <template v-if="val.answerType == 'sz'">
  50. <div class="title" v-if="val.customerClueName">
  51. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  52. {{ val.customerClueName }}
  53. </div>
  54. <van-field
  55. class="fieldInput"
  56. v-model="val.answerValue"
  57. :placeholder="val.remark"
  58. :minTextLength="val.minTextLength"
  59. :error-message="val.remark"
  60. type="number"></van-field>
  61. </template>
  62. <template v-if="val.answerType == 'zp'">
  63. <van-cell>
  64. <template #title>
  65. <span v-if="val.isMust == 0" class="van-f-red">*</span>
  66. {{ val.customerClueName }}
  67. <!-- 操作说明图片和电话 -->
  68. <taskTips
  69. v-if="val.contactPhone || val.examplePhoto"
  70. :contactPhone="val.contactPhone"
  71. :examplePhoto="val.examplePhoto">
  72. </taskTips>
  73. </template>
  74. <template #right-icon>
  75. <span v-if="val.isMust == '0'" style="color: red">图片必填</span>
  76. <div class="uploadImg">
  77. <complaintImg
  78. uploadid="uploadid2"
  79. :itemData="val"
  80. @newimgarr="newimgarr1"
  81. :customerClueId="val.customerClueId"
  82. :customerClueItemId="val.customerClueItemId"
  83. :required="false">
  84. </complaintImg>
  85. </div>
  86. <!-- <van-icon color="#666" name="photograph" size="24" @click="imgClick(val)" /> -->
  87. </template>
  88. </van-cell>
  89. <deletComplaintImg :itemData="val" @deleteImg="deleteImg"></deletComplaintImg>
  90. </template>
  91. </template>
  92. </div>
  93. </template>
  94. <script>
  95. import taskTips from '@/views/deviceWithin/taskTips';
  96. import deletComplaintImg from '@/components/deletComplaintImg';
  97. import complaintImg from '@/components/complaintImg';
  98. export default {
  99. components: { deletComplaintImg, taskTips, complaintImg },
  100. name: 'radioGroup',
  101. props: {
  102. clueOptionList: {
  103. type: Array,
  104. default: () => [],
  105. },
  106. parentOptionList: {
  107. type: Object,
  108. default: () => {},
  109. },
  110. parentId: {
  111. type: [Number, null],
  112. default: null,
  113. },
  114. },
  115. data() {
  116. return {};
  117. },
  118. created() {
  119. // console.log(this.clueOptionList);
  120. },
  121. methods: {
  122. radioGroupChange(name) {
  123. if (!name) return;
  124. // console.log(name);
  125. // console.log(this.clueOptionList);
  126. // 如果选中的数据有父级,将父级数据修改为选中状态
  127. if (this.parentOptionList && this.parentId) {
  128. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  129. }
  130. // 获取选中数据
  131. let clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  132. let activaRadio = clueOptionList.customerClueOptionList.find(
  133. (val) => val.customerClueOptionId == name
  134. );
  135. // 修改选中状态
  136. this.$set(activaRadio, 'value', 'Y');
  137. // 过滤未选中的数据
  138. let exceptItself = clueOptionList.customerClueOptionList.filter(
  139. (val) => val.customerClueOptionId !== name
  140. );
  141. // 删除未选中数据状态兄弟级和子级
  142. // console.log(exceptItself);
  143. this.toggleOtheChildren(exceptItself);
  144. },
  145. toggleOtheChildren(exceptItself) {
  146. if (!exceptItself) return;
  147. exceptItself.forEach((val) => {
  148. this.$set(val, 'value', 'N');
  149. if (val.customerClueItemList && val.customerClueItemList[0]) {
  150. this.$set(val.customerClueItemList[0], 'searchValue', null);
  151. if (
  152. val.customerClueItemList[0] &&
  153. val.customerClueItemList[0].customerClueOptionList.length
  154. ) {
  155. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  156. }
  157. }
  158. });
  159. },
  160. radioClick(event) {
  161. // console.log(event);
  162. },
  163. imgClick(val) {
  164. this.show = true;
  165. },
  166. // 设置照片数据
  167. newimgarr1(val) {
  168. console.log(val);
  169. let fileInfoList = [{ fileUrl: val.fileUrl, id: val.id }].concat(
  170. val.itemData.fileInfoList ? val.itemData.fileInfoList : []
  171. );
  172. this.$set(val.itemData, 'fileInfoList', fileInfoList);
  173. this.setFileIdList(val);
  174. },
  175. // 设置照片id
  176. setFileIdList(val) {
  177. let fileIdList = [];
  178. let fileInfoList = val.itemData.fileInfoList || [];
  179. fileInfoList.forEach((val) => {
  180. fileIdList.push(val.id);
  181. });
  182. this.$set(val.itemData, 'fileIdList', fileIdList);
  183. },
  184. // 删除照片
  185. deleteImg(val) {
  186. val.itemData.fileInfoList.splice(val.index, 1);
  187. this.setFileIdList(val);
  188. },
  189. },
  190. };
  191. </script>
  192. <style lang="scss">
  193. .radioGroup {
  194. font-size: 15px;
  195. .van-radio {
  196. padding: 5px 0;
  197. }
  198. .van-radio-group {
  199. padding-left: 20px;
  200. }
  201. .van-cell {
  202. padding: 10px 0;
  203. /* font-size: 14px; */
  204. }
  205. .van-cell::after {
  206. border: 0;
  207. }
  208. .van-field {
  209. padding: 0;
  210. width: 100%;
  211. border-radius: 4px;
  212. overflow: hidden;
  213. background-color: unset;
  214. height: 30px;
  215. line-height: 30px;
  216. border: 1px solid #cdc8c8;
  217. }
  218. .van-field__control {
  219. /* padding: 0 10px; */
  220. /* margin: 5px 0; */
  221. padding-left: 10px;
  222. }
  223. .van-radio__label {
  224. /* font-size: 14px; */
  225. }
  226. .van-f-red {
  227. font-size: 14px;
  228. }
  229. .rulesClass {
  230. border: 1px solid #ff0505;
  231. }
  232. .fieldInput {
  233. /* height: 38px; */
  234. }
  235. .rulesErrorMessage {
  236. color: red;
  237. font-size: 12px;
  238. padding: 3px 0;
  239. }
  240. .uploadImg {
  241. width: 50px;
  242. }
  243. }
  244. </style>