Radio.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <!-- <portal to="notification-outlet">-->
  3. <div class="select">
  4. <ul class="clearfix">
  5. <li
  6. v-for="(item,idx) in result"
  7. :class="[{'liSelect':item.select,'noBorder':((item.description||item.name).indexOf('${'))!=-1}]"
  8. :key="item.id"
  9. @click="selectResult(item,idx)"
  10. >
  11. <span v-if="((item.description||item.name).indexOf('${'))==-1">{{item.description||item.name}}</span>
  12. <OptionInp v-else :item="item" @handleInp="inpVal($event,idx)" @handleSelec="handleClick(item,idx,false,true)"/>
  13. </li>
  14. </ul>
  15. <div :class="sure?'realSure sure':'sure'" @click="makeSuer">
  16. 确定
  17. </div>
  18. </div>
  19. <!--</portal>-->
  20. </template>
  21. <script>
  22. import OptionInp from '../common/OptionInp.vue';
  23. import {concatVal} from '../utils/tools.js';
  24. export default {
  25. props: ["symptomResult","num"],
  26. data() {
  27. return {
  28. result: [], //答案结果
  29. connectResult: [], //id
  30. contentResult: "", //name
  31. rules: [], //规则所需数据value
  32. sure:false,
  33. numPlus:1
  34. };
  35. },
  36. mounted() {
  37. this.numPlus = this.num;
  38. const list = this.symptomResult.questionDetailList;
  39. this.result = list.length>0?list:this.symptomResult.questionMapping;
  40. },
  41. watch:{
  42. result: {
  43. handler(newArr) {
  44. let num = 0;
  45. for(let i = 0;i < newArr.length;i++){
  46. if(!newArr[i].select){
  47. ++num
  48. }
  49. }
  50. if(num == newArr.length){
  51. this.sure = false
  52. }else{
  53. this.sure = true
  54. }
  55. },
  56. immediate: true,
  57. deep:true
  58. }
  59. },
  60. methods: {
  61. inpVal(val,index){//输入框失焦处理
  62. // 输入框回读
  63. let detailList = this.result;
  64. let currItem = detailList[index];
  65. currItem.value = val;
  66. // 输入框失焦重新拼接父级的value
  67. let temp = concatVal(detailList);
  68. /*this.datas.value = temp.value;
  69. this.datas.valueP = temp.valueP;
  70. this.$emit("updata",this.datas);*/
  71. },
  72. handleClick(it,index,flg,ipt){
  73. if(flg){
  74. document.activeElement.blur();
  75. document.activeElement.scrollIntoViewIfNeeded(true);
  76. setTimeout(()=>{
  77. document.activeElement.scrollIntoViewIfNeeded(true);
  78. },300)
  79. }
  80. const list = this.datas;
  81. let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝
  82. if(ipt){//输入框单选,输入了内容才算选中,删除内容算取消
  83. for(let i=0;i<data.length; i++){
  84. if(i==index){
  85. data[i].select=data[i].value?1:0;
  86. }else{
  87. data[i].select = 0
  88. }
  89. }
  90. }else{
  91. for(let i=0;i<data.length; i++){
  92. if(i==index){
  93. data[i].select = data[i].select==1?0:1;
  94. }else{
  95. data[i].select = 0
  96. }
  97. }
  98. }
  99. let temp = concatVal(data);
  100. const newData = Object.assign({},this.datas,{questionDetailList:data,value:temp.value,valueP:temp.valueP});
  101. this.$emit("updata",newData);
  102. },
  103. makeSuer() {
  104. if(!this.sure){return}
  105. let result = this.result;
  106. let number = this.numPlus,tmpResult='';
  107. for (let i = 0; i < result.length; i++) {
  108. if(result[i].select){
  109. tmpResult=result[i].description||result[i].name
  110. }
  111. }
  112. this.contentResult = tmpResult;
  113. this.$emit("updataResultSingle", this.result, this.contentResult,++number);
  114. },
  115. selectResult(item,idx) {
  116. const { select } = item;
  117. let result = JSON.parse(JSON.stringify(this.result))
  118. if (select) {//判断是否选中,选中的取消,关联id删除,未选中判断是否互斥
  119. for (let i = 0; i < result.length; i++) {
  120. if(i == idx){
  121. result[i].select = false
  122. }
  123. }
  124. }else{
  125. for (let i = 0; i < result.length; i++) {
  126. if(i == idx){
  127. result[i].select = true
  128. }else{
  129. result[i].select = false
  130. }
  131. }
  132. }
  133. this.result = result
  134. }
  135. },
  136. components:{
  137. OptionInp
  138. }
  139. };
  140. </script>
  141. <style lang="less" scoped>
  142. @import "../less/base.less";
  143. .select {
  144. background-color: #fff;
  145. padding: 0.3rem 0 0;
  146. position: fixed;
  147. width: 100%;
  148. bottom: 0;
  149. box-sizing: border-box;
  150. li {
  151. padding: 0.14rem 0.2rem;
  152. border:1px #DFE0E4 solid;
  153. border-radius: 0.36rem;
  154. font-size: 0.26rem;
  155. margin: 0.15rem;
  156. float: left;
  157. color: #666;
  158. &.noBorder{
  159. border: none;
  160. width: 100%;
  161. }
  162. }
  163. .liSelect {
  164. color: #fff;
  165. background-color: #colors[btn];
  166. border-color: #colors[btn];
  167. }
  168. }
  169. </style>