Radio.vue 3.3 KB

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