radioGroup.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. <template v-if="val.customerClueName.indexOf('填写服务商代码') != -1">
  34. <div class="fws">
  35. <van-field class="fwsLeft" v-model="fws" disabled />
  36. <van-field
  37. class="fwsRight"
  38. v-model="val.answerValue"
  39. :placeholder="val.remark"
  40. type="number"
  41. :class="{
  42. fieldInput: true,
  43. rulesClass: val.answerValue != null && val.answerValue.length < val.minTextLength,
  44. }" />
  45. </div>
  46. </template>
  47. <template v-else>
  48. <van-field
  49. v-model="val.answerValue"
  50. :placeholder="val.remark"
  51. :minTextLength="val.minTextLength"
  52. autosize
  53. type="textarea"
  54. :class="{
  55. fieldInput: true,
  56. rulesClass: val.answerValue != null && val.answerValue.length < val.minTextLength,
  57. }" />
  58. </template>
  59. <span
  60. class="rulesErrorMessage"
  61. v-if="val.answerValue != null && val.answerValue.length < val.minTextLength">
  62. {{ val.remark }}
  63. </span>
  64. </template>
  65. </template>
  66. <!-- 数字输入框 -->
  67. <template v-if="val.answerType == 'sz'">
  68. <div class="title" v-if="val.customerClueName">
  69. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  70. {{ val.customerClueName }}
  71. </div>
  72. <van-field
  73. v-if="
  74. val.customerClueName.indexOf('开户门店代码') != -1 ||
  75. val.customerClueName.indexOf('开户经销商代码') != -1
  76. "
  77. class="fieldInput"
  78. v-model="val.answerValue"
  79. :placeholder="val.remark"
  80. maxlength="10"
  81. :minTextLength="val.minTextLength"
  82. type="digit"
  83. @focus="inputFocus(val)"></van-field>
  84. <van-field
  85. v-else
  86. class="fieldInput"
  87. v-model="val.answerValue"
  88. :placeholder="val.remark"
  89. :minTextLength="val.minTextLength"
  90. type="number"></van-field>
  91. </template>
  92. <!-- 照片 -->
  93. <template v-if="val.answerType == 'zp'">
  94. <van-cell>
  95. <template #title>
  96. <span v-if="val.isMust == 0" class="van-f-red">*</span>
  97. {{ val.customerClueName }}
  98. <!-- 操作说明图片和电话 -->
  99. <taskTips
  100. v-if="val.contactPhone || val.examplePhoto"
  101. :contactPhone="val.contactPhone"
  102. :examplePhoto="val.examplePhoto">
  103. </taskTips>
  104. </template>
  105. <template #right-icon>
  106. <span v-if="val.isMust == '0'" style="color: red">图片必填</span>
  107. <div class="uploadImg">
  108. <complaintImg
  109. uploadid="uploadid2"
  110. :itemData="val"
  111. @newimgarr="newimgarr1"
  112. :customerClueId="val.customerClueId"
  113. :customerClueItemId="val.customerClueItemId"
  114. :required="false">
  115. </complaintImg>
  116. </div>
  117. <!-- <van-icon color="#666" name="photograph" size="24" @click="imgClick(val)" /> -->
  118. </template>
  119. </van-cell>
  120. <deletComplaintImg :itemData="val" @deleteImg="deleteImg"></deletComplaintImg>
  121. </template>
  122. <!-- 表格 -->
  123. <template v-if="val.answerType == 'bg'">
  124. <div class="title" v-if="val.customerClueName">
  125. <span class="van-f-red" v-if="val.isMust == 0">*</span>
  126. {{ val.customerClueName }}
  127. </div>
  128. <el-table :data="val.tableData.data" style="width: 100%; position: relative; left: -10px">
  129. <el-table-column
  130. v-for="(item, index) in val.tableData.title"
  131. :prop="item.prop"
  132. :label="item.label"
  133. align="center">
  134. <template slot-scope="scope">
  135. <template v-if="item.answerType == 'text'">
  136. {{ scope.row[item.prop] }}
  137. </template>
  138. <template v-if="item.answerType == 'wb'">
  139. <van-field v-model="scope.row[item.prop]" />
  140. </template>
  141. <!-- 正整数 digit -->
  142. <template v-if="item.answerType == 'sz'">
  143. <van-field v-model="scope.row[item.prop]" type="digit" />
  144. </template>
  145. </template>
  146. </el-table-column>
  147. </el-table>
  148. </template>
  149. </template>
  150. </div>
  151. </template>
  152. <script>
  153. import taskTips from '@/views/deviceWithin/taskTips';
  154. import deletComplaintImg from '@/components/deletComplaintImg';
  155. import complaintImg from '@/components/complaintImg';
  156. export default {
  157. components: { deletComplaintImg, taskTips, complaintImg },
  158. name: 'radioGroup',
  159. props: {
  160. clueOptionList: {
  161. type: Array,
  162. default: () => [],
  163. },
  164. parentOptionList: {
  165. type: Object,
  166. default: () => {},
  167. },
  168. parentId: {
  169. type: [Number, null],
  170. default: null,
  171. },
  172. },
  173. data() {
  174. return {
  175. fws: 'FSQ',
  176. };
  177. },
  178. watch: {
  179. clueOptionList: {
  180. handler(val) {
  181. val.forEach((item) => {
  182. // bg表格数据存在remark
  183. if (item.answerType == 'bg') {
  184. this.$set(item, 'tableData', JSON.parse(item.remark));
  185. }
  186. });
  187. },
  188. immediate: true,
  189. },
  190. },
  191. created() {
  192. // console.log(this.clueOptionList);
  193. },
  194. methods: {
  195. radioGroupChange(name) {
  196. if (!name) return;
  197. // console.log(name);
  198. // console.log(this.clueOptionList);
  199. // 如果选中的数据有父级,将父级数据修改为选中状态
  200. if (this.parentOptionList && this.parentId) {
  201. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  202. }
  203. // 获取选中数据
  204. let clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  205. let activaRadio = clueOptionList.customerClueOptionList.find(
  206. (val) => val.customerClueOptionId == name
  207. );
  208. // 修改选中状态
  209. this.$set(activaRadio, 'value', 'Y');
  210. // 过滤未选中的数据
  211. let exceptItself = clueOptionList.customerClueOptionList.filter(
  212. (val) => val.customerClueOptionId !== name
  213. );
  214. // 删除未选中数据状态兄弟级和子级
  215. // console.log(exceptItself);
  216. this.toggleOtheChildren(exceptItself);
  217. },
  218. toggleOtheChildren(exceptItself) {
  219. if (!exceptItself) return;
  220. exceptItself.forEach((val) => {
  221. this.$set(val, 'value', 'N');
  222. if (val.customerClueItemList && val.customerClueItemList[0]) {
  223. this.$set(val.customerClueItemList[0], 'searchValue', null);
  224. if (
  225. val.customerClueItemList[0] &&
  226. val.customerClueItemList[0].customerClueOptionList.length
  227. ) {
  228. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  229. }
  230. }
  231. });
  232. },
  233. radioClick(event) {
  234. // console.log(event);
  235. },
  236. imgClick(val) {
  237. this.show = true;
  238. },
  239. // 设置照片数据
  240. newimgarr1(val) {
  241. console.log(val);
  242. let fileInfoList = [{ fileUrl: val.fileUrl, id: val.id }].concat(
  243. val.itemData.fileInfoList ? val.itemData.fileInfoList : []
  244. );
  245. this.$set(val.itemData, 'fileInfoList', fileInfoList);
  246. this.setFileIdList(val);
  247. },
  248. // 设置照片id
  249. setFileIdList(val) {
  250. let fileIdList = [];
  251. let fileInfoList = val.itemData.fileInfoList || [];
  252. fileInfoList.forEach((val) => {
  253. fileIdList.push(val.id);
  254. });
  255. this.$set(val.itemData, 'fileIdList', fileIdList);
  256. },
  257. // 删除照片
  258. deleteImg(val) {
  259. val.itemData.fileInfoList.splice(val.index, 1);
  260. this.setFileIdList(val);
  261. },
  262. // 设置输入框长度限制
  263. inputFocus(val) {
  264. if (val.minTextLength) return;
  265. this.$set(val, 'minTextLength', 10);
  266. },
  267. },
  268. };
  269. </script>
  270. <style lang="scss">
  271. .radioGroup {
  272. font-size: 15px;
  273. .van-radio {
  274. padding: 5px 0;
  275. }
  276. .van-radio-group {
  277. padding-left: 20px;
  278. }
  279. .van-cell {
  280. padding: 10px 0;
  281. /* font-size: 14px; */
  282. }
  283. .van-cell::after {
  284. border: 0;
  285. }
  286. .van-field {
  287. padding: 0;
  288. width: 97%;
  289. border-radius: 4px;
  290. overflow: hidden;
  291. background-color: unset;
  292. // height: 30px;
  293. // line-height: 30px;
  294. border: 1px solid #cdc8c8;
  295. }
  296. .van-field__control {
  297. /* padding: 0 10px; */
  298. /* margin: 5px 0; */
  299. padding-left: 10px;
  300. }
  301. .van-radio__label {
  302. /* font-size: 14px; */
  303. }
  304. .van-f-red {
  305. font-size: 14px;
  306. }
  307. .rulesClass {
  308. border: 1px solid #ff0505;
  309. }
  310. .fieldInput {
  311. /* height: 38px; */
  312. }
  313. .rulesErrorMessage {
  314. color: red;
  315. font-size: 12px;
  316. padding: 3px 0;
  317. }
  318. .uploadImg {
  319. width: 50px;
  320. }
  321. .el-table {
  322. .el-table__cell {
  323. padding: 3px 0;
  324. }
  325. }
  326. .fws {
  327. display: flex;
  328. flex-direction: row;
  329. width: 90%;
  330. padding: 5px 0;
  331. .fwsLeft {
  332. width: 50px;
  333. font-weight: 600;
  334. color: #000;
  335. }
  336. }
  337. }
  338. </style>