Radio.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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)">
  5. <img :src="it.select==1?check:defaultPic">
  6. <!-- <span :class="{'check':it.select==1}">{{it.name}}</span> -->
  7. <span v-if="(it.name.indexOf('${'))==-1" :class="{'check':it.select==1}">{{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. </p>
  17. </div>
  18. </template>
  19. <script type="text/javascript">
  20. import icon from '../images/radio-default.png'
  21. import checkIcon from '../images/radio-check.png'
  22. import {patt} from '@utils/tools.js'
  23. import MultiLineInput from '../common/MultiLineInput.vue';
  24. export default{
  25. name:'Radio',
  26. data(){
  27. return{
  28. defaultPic:icon,
  29. check:checkIcon,
  30. datas:{}
  31. }
  32. },
  33. props:['item'],
  34. created(){
  35. // this.datas = JSON.parse(JSON.stringify(this.item));
  36. this.datas = this.item;
  37. },
  38. methods:{
  39. handleClick(it,index){
  40. // let patt = /\$\{[^\]]+\}/g;
  41. const list = this.datas;
  42. let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝?
  43. let value = "";
  44. for(let i=0;i<data.length; i++){
  45. data[i].select = 0
  46. if(i==index){
  47. data[i].select = 1;
  48. value = data[i].name;
  49. }
  50. }
  51. const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value})
  52. this.$emit("updata",newData);
  53. },
  54. inpVal(val,index){//输入框失焦处理
  55. let valueStr = this.datas.value;
  56. if(valueStr){
  57. // let patt = /\$\{[^\]]+\}/g;
  58. let newVal = val;//修改时替换值用
  59. const str = valueStr.replace(patt,newVal);
  60. this.datas.value = str;
  61. }
  62. // 输入框回读
  63. let detailList = this.datas.questionDetailList;
  64. let currItem = detailList[index];
  65. currItem.value = val;
  66. this.$emit("updata",this.datas);
  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. }
  80. }
  81. </script>
  82. <style lang="less" scoped>
  83. .radio-wrap{
  84. img{
  85. width:100%;
  86. }
  87. .list{
  88. color: #7C828E;
  89. margin:0 .1rem .1rem 0;
  90. padding: .12rem .1rem;
  91. display: inline-block;
  92. white-space: nowrap;
  93. -webkit-white-space: nowrap;
  94. // -webkit-box-orient: vertical;
  95. img{
  96. width: .38rem;
  97. vertical-align: middle;
  98. }
  99. .check{
  100. color: #4F50FF;
  101. }
  102. }
  103. }
  104. </style>