Radio.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.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)" />
  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. let valueP = "";
  48. for(let i=0;i<data.length; i++){
  49. data[i].select = 0
  50. if(i==index){
  51. data[i].select = 1;
  52. // value = data[i].name;
  53. // 选中该项时,带的输入框内有值则加上
  54. if(data[i].value){
  55. let newVal = '#{' + data[i].value + '}';
  56. let str = data[i].name.replace(patt,newVal);//医生
  57. let strP = (data[i].description ||data[i].name).replace(patt,newVal);//患者
  58. value = str ;
  59. valueP = strP ;
  60. }else{
  61. value = data[i].name ;
  62. valueP = data[i].name ;
  63. }
  64. }
  65. }
  66. // const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value})
  67. const newData = Object.assign({},this.datas,{questionDetailList:data,value:value,valueP:valueP})
  68. this.$emit("updata",newData);
  69. },
  70. inpVal(val,index){//输入框失焦处理
  71. let valueStr = this.datas.value;
  72. /*if(valueStr){
  73. // let patt = /\$\{[^\]]+\}/g;
  74. let newVal = val;//修改时替换值用
  75. const str = valueStr.replace(patt,newVal);
  76. this.datas.value = str;
  77. }*/
  78. if(valueStr){
  79. let rePatt = /\#\{[^\]]+\}/g;
  80. let newVal = '#{' +val+'}';
  81. let str = "";
  82. // 区分第一次输入还是修改
  83. if(valueStr.indexOf("${") !== -1){
  84. str = valueStr.replace(patt,newVal);
  85. }else{//修改
  86. str = valueStr.replace(rePatt,newVal);
  87. }
  88. this.datas.value = str;
  89. this.datas.valueP = str;//输入框内容无医生患者之分
  90. }
  91. // 输入框回读
  92. let detailList = this.datas.questionDetailList;
  93. let currItem = detailList[index];
  94. currItem.value = val;
  95. this.$emit("updata",this.datas);
  96. },
  97. },
  98. watch:{
  99. item:{
  100. handler(newVal,oldVal){
  101. this.datas = JSON.parse(JSON.stringify(newVal));
  102. },
  103. deep:true
  104. }
  105. },
  106. components:{
  107. MultiLineInput,
  108. OptionInp
  109. }
  110. }
  111. </script>
  112. <style lang="less" scoped>
  113. .radio-wrap{
  114. img{
  115. width:100%;
  116. }
  117. .list{
  118. color: #7C828E;
  119. margin:0 .1rem .1rem 0;
  120. padding: .12rem .1rem;
  121. display: inline-block;
  122. white-space: nowrap;
  123. -webkit-white-space: nowrap;
  124. // -webkit-box-orient: vertical;
  125. img{
  126. width: .38rem;
  127. vertical-align: middle;
  128. }
  129. .check{
  130. color: #4F50FF;
  131. }
  132. }
  133. }
  134. </style>