radioGroup.vue 9.0 KB

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