Radio.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. <OptionInp v-else :item="it" @handleInp="inpVal($event,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} 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){
  43. // let patt = /\$\{[^\]]+\}/g;
  44. const list = this.datas;
  45. let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝?
  46. let value = "";
  47. for(let i=0;i<data.length; i++){
  48. data[i].select = 0
  49. if(i==index){
  50. data[i].select = 1;
  51. value = data[i].name;
  52. }
  53. }
  54. const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value})
  55. this.$emit("updata",newData);
  56. },
  57. inpVal(val,index){//输入框失焦处理
  58. let valueStr = this.datas.value;
  59. if(valueStr){
  60. // let patt = /\$\{[^\]]+\}/g;
  61. let newVal = val;//修改时替换值用
  62. const str = valueStr.replace(patt,newVal);
  63. this.datas.value = str;
  64. }
  65. // 输入框回读
  66. let detailList = this.datas.questionDetailList;
  67. let currItem = detailList[index];
  68. currItem.value = val;
  69. this.$emit("updata",this.datas);
  70. },
  71. },
  72. watch:{
  73. item:{
  74. handler(newVal,oldVal){
  75. this.datas = JSON.parse(JSON.stringify(newVal));
  76. },
  77. deep:true
  78. }
  79. },
  80. components:{
  81. MultiLineInput,
  82. OptionInp
  83. }
  84. }
  85. </script>
  86. <style lang="less" scoped>
  87. .radio-wrap{
  88. img{
  89. width:100%;
  90. }
  91. .list{
  92. color: #7C828E;
  93. margin:0 .1rem .1rem 0;
  94. padding: .12rem .1rem;
  95. display: inline-block;
  96. white-space: nowrap;
  97. -webkit-white-space: nowrap;
  98. // -webkit-box-orient: vertical;
  99. img{
  100. width: .38rem;
  101. vertical-align: middle;
  102. }
  103. .check{
  104. color: #4F50FF;
  105. }
  106. }
  107. }
  108. </style>