radioGroup.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. :key="index"
  132. :prop="item.prop"
  133. :label="item.label"
  134. align="center">
  135. <template slot-scope="scope">
  136. <template v-if="item.answerType == 'text'">
  137. {{ scope.row[item.prop] }}
  138. </template>
  139. <template v-if="item.answerType == 'wb'">
  140. <van-field v-model="scope.row[item.prop]" />
  141. </template>
  142. <!-- 正整数 digit -->
  143. <template v-if="item.answerType == 'sz'">
  144. <van-field v-model="scope.row[item.prop]" type="digit" />
  145. </template>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </template>
  150. </template>
  151. </div>
  152. </template>
  153. <script>
  154. import taskTips from '@/views/deviceWithin/taskTips';
  155. import deletComplaintImg from '@/components/deletComplaintImg';
  156. import complaintImg from '@/components/complaintImg';
  157. export default {
  158. components: { deletComplaintImg, taskTips, complaintImg },
  159. name: 'radioGroup',
  160. props: {
  161. clueOptionList: {
  162. type: Array,
  163. default: () => [],
  164. },
  165. parentOptionList: {
  166. type: Object,
  167. default: () => {},
  168. },
  169. parentId: {
  170. type: [Number, null],
  171. default: null,
  172. },
  173. },
  174. data() {
  175. return {
  176. fws: 'FSQ',
  177. };
  178. },
  179. watch: {
  180. clueOptionList: {
  181. handler(val) {
  182. val.forEach((item) => {
  183. // bg表格数据存在remark
  184. if (item.answerType == 'bg') {
  185. this.$set(item, 'tableData', JSON.parse(item.remark));
  186. }
  187. });
  188. },
  189. immediate: true,
  190. },
  191. },
  192. created() {
  193. // console.log(this.clueOptionList);
  194. },
  195. methods: {
  196. radioGroupChange(name) {
  197. if (!name) return;
  198. // console.log(name);
  199. // console.log(this.clueOptionList);
  200. // 如果选中的数据有父级,将父级数据修改为选中状态
  201. if (this.parentOptionList && this.parentId) {
  202. this.$set(this.parentOptionList, 'searchValue', this.parentId);
  203. }
  204. // 获取选中数据
  205. let clueOptionList = this.clueOptionList.find((val) => val.searchValue == name);
  206. let activaRadio = clueOptionList.customerClueOptionList.find(
  207. (val) => val.customerClueOptionId == name
  208. );
  209. // 修改选中状态
  210. this.$set(activaRadio, 'value', 'Y');
  211. // 过滤未选中的数据
  212. let exceptItself = clueOptionList.customerClueOptionList.filter(
  213. (val) => val.customerClueOptionId !== name
  214. );
  215. // 删除未选中数据状态兄弟级和子级
  216. // console.log(exceptItself);
  217. this.toggleOtheChildren(exceptItself);
  218. },
  219. toggleOtheChildren(exceptItself) {
  220. if (!exceptItself) return;
  221. exceptItself.forEach((val) => {
  222. this.$set(val, 'value', 'N');
  223. if (val.customerClueItemList && val.customerClueItemList[0]) {
  224. this.$set(val.customerClueItemList[0], 'searchValue', null);
  225. if (
  226. val.customerClueItemList[0] &&
  227. val.customerClueItemList[0].customerClueOptionList.length
  228. ) {
  229. this.toggleOtheChildren(val.customerClueItemList[0].customerClueOptionList);
  230. }
  231. }
  232. });
  233. },
  234. radioClick(event) {
  235. // console.log(event);
  236. },
  237. imgClick(val) {
  238. this.show = true;
  239. },
  240. // 设置照片数据
  241. newimgarr1(val) {
  242. console.log(val);
  243. let fileInfoList = [{ fileUrl: val.fileUrl, id: val.id }].concat(
  244. val.itemData.fileInfoList ? val.itemData.fileInfoList : []
  245. );
  246. this.$set(val.itemData, 'fileInfoList', fileInfoList);
  247. this.setFileIdList(val);
  248. },
  249. // 设置照片id
  250. setFileIdList(val) {
  251. let fileIdList = [];
  252. let fileInfoList = val.itemData.fileInfoList || [];
  253. fileInfoList.forEach((val) => {
  254. fileIdList.push(val.id);
  255. });
  256. this.$set(val.itemData, 'fileIdList', fileIdList);
  257. },
  258. // 删除照片
  259. deleteImg(val) {
  260. val.itemData.fileInfoList.splice(val.index, 1);
  261. this.setFileIdList(val);
  262. },
  263. // 设置输入框长度限制
  264. inputFocus(val) {
  265. if (val.minTextLength) return;
  266. this.$set(val, 'minTextLength', 10);
  267. },
  268. },
  269. };
  270. </script>
  271. <style lang="scss">
  272. .radioGroup {
  273. font-size: 15px;
  274. .van-radio {
  275. padding: 5px 0;
  276. }
  277. .van-radio-group {
  278. padding-left: 20px;
  279. }
  280. .van-cell {
  281. padding: 10px 0;
  282. /* font-size: 14px; */
  283. }
  284. .van-cell::after {
  285. border: 0;
  286. }
  287. .van-field {
  288. padding: 0;
  289. width: 97%;
  290. border-radius: 4px;
  291. overflow: hidden;
  292. background-color: unset;
  293. // height: 30px;
  294. // line-height: 30px;
  295. border: 1px solid #cdc8c8;
  296. }
  297. .van-field__control {
  298. /* padding: 0 10px; */
  299. /* margin: 5px 0; */
  300. padding-left: 10px;
  301. }
  302. .van-radio__label {
  303. /* font-size: 14px; */
  304. }
  305. .van-f-red {
  306. font-size: 14px;
  307. }
  308. .rulesClass {
  309. border: 1px solid #ff0505;
  310. }
  311. .fieldInput {
  312. /* height: 38px; */
  313. }
  314. .rulesErrorMessage {
  315. color: red;
  316. font-size: 12px;
  317. padding: 3px 0;
  318. }
  319. .uploadImg {
  320. width: 50px;
  321. }
  322. .el-table {
  323. .el-table__cell {
  324. padding: 3px 0;
  325. }
  326. }
  327. .fws {
  328. display: flex;
  329. flex-direction: row;
  330. width: 90%;
  331. padding: 5px 0;
  332. .fwsLeft {
  333. width: 50px;
  334. font-weight: 600;
  335. color: #000;
  336. }
  337. }
  338. }
  339. </style>