123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <template>
- <div class="check-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},{'exclu':exclusion !==999 && it.exclusion !== exclusion}]">{{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"
- ref="inp"
- @handleInp="inpVal($event,index)"
- :exclu="exclusion !==999 && it.exclusion !== exclusion"
- />
- </p>
- </div>
- </template>
- <script type="text/javascript">
- import {imageUrlPrefix,patt,concatVal} from '@utils/tools.js';
- import icon from '../images/check-default.png';
- import checkIcon from '../images/check.png';
- import MultiLineInput from '../common/MultiLineInput.vue';
- import OptionInp from '../common/OptionInp.vue';
- export default{
- name:'CheckBox',
- data(){
- return{
- imgUrl:imageUrlPrefix,
- defaultPic:icon,
- check:checkIcon,
- datas:{},
- exclusion:999 //互斥
- }
- },
- props:['item'],
- created(){
- // this.datas = JSON.parse(JSON.stringify(this.item));
- this.datas = this.item;
- this.resetExc();
- },
- methods:{
- handleClick(it,index){
- const that = this;
- const list = this.datas;
- let data = list.questionDetailList&&list.questionDetailList.slice(0);
- // 处理互斥
- const excluArr = data.filter(it=>it.exclusion==1);
- const filArr = data.filter(it=>it.select==1);
- if(excluArr.length>0){//有互斥
- if(filArr.length>0){//有选中
- if(it.exclusion !== filArr[0].exclusion){
- return
- }
- }
- this.exclusion = it.exclusion;
- }
- // 处理选中状态
- if(data[index].select){
- data[index].select = 0;
- }else{
- data[index].select = 1;
- this.exclusion = it.exclusion;
- }
- // 处理取消-互斥
- const filArr1 = data.filter(it=>it.select==1);
- if(excluArr.length>0){//有互斥
- if(filArr1.length==0){//无选中
- this.exclusion = 999;
- }else{
- this.exclusion = filArr1[0].exclusion;
- }
- }
- let temp = concatVal(data);
- const newData = Object.assign({},this.datas,{questionDetailList:data},{value:temp.value?temp.value:''},{valueP:temp.valueP?temp.valueP:''});
- this.$emit("updata",newData);
- },
- inpVal(val,index){//输入框失焦处理
- // 输入框回读
- let detailList = this.datas.questionDetailList;
- let currItem = detailList[index];
- currItem.value = val;
- // 输入框失焦重新拼接父级的value
- let temp = concatVal(detailList);
- this.datas.value = temp.value;
- this.datas.valueP = temp.valueP;
- this.$emit("updata",this.datas);
- },
- resetExc(){
- // 回读互斥项标识
- const arr = this.datas.questionDetailList;
- const filArr = arr.filter(it=>it.select==1);
- if(filArr.length > 0){
- this.exclusion = filArr[0].exclusion;
- }else{
- this.exclusion = 999;
- }
- }
- },
- watch:{
- item:{
- handler(newVal,oldVal){
- this.datas = JSON.parse(JSON.stringify(newVal));
- this.resetExc();
- },
- deep:true
- }
- },
- components:{
- MultiLineInput,
- OptionInp
- }
- }
- </script>
- <style lang="less" scoped>
- .check-wrap{
- img{
- width:100%;
- }
- .list{
- color: #7C828E;
- margin:0 .1rem .1rem 0;
- padding: .12rem .1rem;
- display: inline-block;
- white-space: nowrap;
- img{
- width: .38rem;
- vertical-align: middle;
- }
- }
- .check{
- color: #4F50FF;
- }
- .exclu{
- color:#e6e7e9;
- }
- }
- </style>
|