RadioSelect.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="radio-wrap radioSelect" v-if="item">
  3. <p v-for="(it,index) in datas.questionDetailList" :key="it.id" class="list">
  4. <img @click="handleClick(it,index,true,1)" :src="it.select==1?check:defaultPic"> <i @click="handleClick(it,index,true,1)">有</i>&nbsp;&nbsp;&nbsp;&nbsp;
  5. <img @click="handleClick(it,index,true,2)" :src="it.select==2?check:defaultPic"> <i @click="handleClick(it,index,true,2)">无</i>
  6. <span v-if="((it.description||it.name).indexOf('${'))==-1" :class="{'check':it.select==1||it.select==2}">{{it.description||it.name}}</span>
  7. </p>
  8. </div>
  9. </template>
  10. <script type="text/javascript">
  11. import icon from '../images/radio-default.png'
  12. import checkIcon from '../images/radio-check.png'
  13. import {patt,imageUrlPrefix,concatVal} from '@utils/tools.js'
  14. import MultiLineInput from '../common/MultiLineInput.vue';
  15. import OptionInp from '../common/OptionInp.vue';
  16. export default{
  17. name:'RadioSelect',
  18. data(){
  19. return{
  20. defaultPic:icon,
  21. check:checkIcon,
  22. datas:{},
  23. imgUrl:imageUrlPrefix,
  24. }
  25. },
  26. props:['item'],
  27. created(){
  28. // this.datas = JSON.parse(JSON.stringify(this.item));
  29. this.datas = this.item;
  30. },
  31. methods:{
  32. handleClick(it,index,flg,isHas){
  33. if(flg){
  34. document.activeElement.blur();
  35. document.activeElement.scrollIntoViewIfNeeded(true);
  36. setTimeout(()=>{
  37. document.activeElement.scrollIntoViewIfNeeded(true);
  38. },300)
  39. }
  40. const list = this.datas;
  41. let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝?
  42. for(let i=0;i<data.length; i++){
  43. // data[i].select = 0
  44. if(i==index){
  45. data[i].select = isHas;
  46. data[i].controlType = 8;
  47. }
  48. }
  49. let temp = concatVal(data,true);
  50. const newData = Object.assign({},this.datas,{questionDetailList:data,value:temp.value,valueP:temp.valueP})
  51. this.$emit("updata",newData);
  52. },
  53. inpVal(val,index){//输入框失焦处理
  54. // 输入框回读
  55. let detailList = this.datas.questionDetailList;
  56. let currItem = detailList[index];
  57. currItem.value = val;
  58. // 输入框失焦重新拼接父级的value
  59. let temp = concatVal(detailList);
  60. this.datas.value = temp.value;
  61. this.datas.valueP = temp.valueP;
  62. this.$emit("updata",this.datas);
  63. },
  64. /*inpSele(index){//输入框反选
  65. let detailList = this.datas.questionDetailList;console.log("单选:",index,detailList[index])
  66. detailList[index].select = 1;
  67. }*/
  68. },
  69. watch:{
  70. item:{
  71. handler(newVal,oldVal){
  72. this.datas = JSON.parse(JSON.stringify(newVal));
  73. },
  74. deep:true
  75. }
  76. },
  77. components:{
  78. MultiLineInput,
  79. OptionInp
  80. }
  81. }
  82. </script>
  83. <style lang="less" scoped>
  84. .radio-wrap{
  85. img{
  86. width:100%;
  87. }
  88. .list{
  89. color: #7C828E;
  90. margin:0 .1rem .1rem 0;
  91. padding: .12rem .1rem;
  92. white-space: nowrap;
  93. -webkit-white-space: nowrap;
  94. // -webkit-box-orient: vertical;
  95. span {
  96. margin-left:1.2rem;
  97. }
  98. img{
  99. width: .38rem;
  100. vertical-align: middle;
  101. }
  102. .check{
  103. color: #4F50FF;
  104. }
  105. }
  106. }
  107. </style>