123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <div class="radio-wrap" v-if="item">
- <img :src="datas.url.replace('{imageUrlPrefix}',imgUrl)" v-if="datas.url">
- <p v-for="(it,index) in datas.questionDetailList" :key="it.id" class="list" @click="handleClick(it,index)">
- <img :src="it.select==1?check:defaultPic">
- <!-- <span :class="{'check':it.select==1}">{{it.name}}</span> -->
- <span v-if="((it.description||it.name).indexOf('${'))==-1" :class="{'check':it.select==1}">{{it.description||it.name}}</span>
- <!-- <MultiLineInput v-else
- @handleInp="inpVal($event,index)"
- :msg="it.name"
- :part="it"
- :border="false"
- :inline="true"
- :select="it.select==1"
- /> -->
- <OptionInp v-else :item="it" @handleInp="inpVal($event,index)" />
- </p>
- </div>
- </template>
- <script type="text/javascript">
- import icon from '../images/radio-default.png'
- import checkIcon from '../images/radio-check.png'
- import {patt,imageUrlPrefix} from '@utils/tools.js'
- import MultiLineInput from '../common/MultiLineInput.vue';
- import OptionInp from '../common/OptionInp.vue';
- export default{
- name:'Radio',
- data(){
- return{
- defaultPic:icon,
- check:checkIcon,
- datas:{},
- imgUrl:imageUrlPrefix,
- }
- },
- props:['item'],
- created(){
- // this.datas = JSON.parse(JSON.stringify(this.item));
- this.datas = this.item;
- },
- methods:{
- handleClick(it,index){
- // let patt = /\$\{[^\]]+\}/g;
- const list = this.datas;
- let data = list.questionDetailList&&list.questionDetailList.slice(0); //数组深拷贝?
- let value = "";
- let valueP = "";
- for(let i=0;i<data.length; i++){
- data[i].select = 0
- if(i==index){
- data[i].select = 1;
- // value = data[i].name;
- // 选中该项时,带的输入框内有值则加上
- if(data[i].value){
- let newVal = '#{' + data[i].value + '}';
- let str = data[i].name.replace(patt,newVal);//医生
- let strP = (data[i].description ||data[i].name).replace(patt,newVal);//患者
- value = str ;
- valueP = strP ;
- }else{
- value = data[i].name ;
- valueP = data[i].name ;
- }
- }
- }
- // const newData = Object.assign({},this.datas,{questionDetailList:data},{value:value})
- const newData = Object.assign({},this.datas,{questionDetailList:data,value:value,valueP:valueP})
- this.$emit("updata",newData);
- },
- inpVal(val,index){//输入框失焦处理
- let valueStr = this.datas.value;
- /*if(valueStr){
- // let patt = /\$\{[^\]]+\}/g;
- let newVal = val;//修改时替换值用
- const str = valueStr.replace(patt,newVal);
- this.datas.value = str;
- }*/
- if(valueStr){
- let rePatt = /\#\{[^\]]+\}/g;
- let newVal = '#{' +val+'}';
- let str = "";
- // 区分第一次输入还是修改
- if(valueStr.indexOf("${") !== -1){
- str = valueStr.replace(patt,newVal);
- }else{//修改
- str = valueStr.replace(rePatt,newVal);
- }
- this.datas.value = str;
- this.datas.valueP = str;//输入框内容无医生患者之分
- }
-
- // 输入框回读
- let detailList = this.datas.questionDetailList;
- let currItem = detailList[index];
- currItem.value = val;
- this.$emit("updata",this.datas);
- },
- },
- watch:{
- item:{
- handler(newVal,oldVal){
- this.datas = JSON.parse(JSON.stringify(newVal));
- },
- deep:true
- }
- },
- components:{
- MultiLineInput,
- OptionInp
- }
- }
- </script>
- <style lang="less" scoped>
- .radio-wrap{
- img{
- width:100%;
- }
- .list{
- color: #7C828E;
- margin:0 .1rem .1rem 0;
- padding: .12rem .1rem;
- display: inline-block;
- white-space: nowrap;
- -webkit-white-space: nowrap;
- // -webkit-box-orient: vertical;
- img{
- width: .38rem;
- vertical-align: middle;
- }
- .check{
- color: #4F50FF;
- }
- }
- }
- </style>
|