<template>
  <div>
    <div class="left clearfix" v-if="item.show">
      <img src="../images/doctor.png" class="fl" />
      <div class="content fl">
        <p>{{item.name}}{{item.controlType==2?'(可多选)':''}}</p>
      </div>
    </div>
    <div class="right clearfix" v-if="item.content">
      <img v-if="typeof(item.content)==='string'" src="../images/patient.png" alt class="fr" />
      <div v-if="typeof(item.content)==='string'" class="content fr">
        <p>{{item.content}}</p>
      </div>
      <div v-else class="imgs-list">
        <p>
          <img v-for="img in item.content" :src="img" alt=""/>
        </p>
      </div>
      <span class="edit" v-if="showEdit" @click="cancelPre(item.type,item.questionDetailList)">修改</span>
    </div>
  </div>
</template>
<script>
  import {getNSum} from '@utils/tools';
export default {
  props:['item','idx','cancelNum','num','extNum','isLast','cancelTab'],
  data() {
    return {};
  },
  computed:{
    showEdit(){
      const {cancelNum,idx,num,extNum,cancelTab,isLast}=this;
      let cancelExt=0,realExt=getNSum(extNum);
      //const cancelN=extNum.length>0?cancelNum-1:cancelNum;
      const extArr = [...extNum];
      //extArr.splice(0,+cancelTab);
      extArr.length=cancelTab!==-1?+cancelTab:0;
      cancelExt=getNSum(extArr);
      const  realCNum = ((cancelExt+1)||1)+cancelNum;   //第一个问题不在计数中，所以+1
      const realNum = 1+num;
      const realIdx = ((realExt+1)||1)+idx;
      //console.log("cancelNum:",cancelNum,"idx:",idx,"num:",num,"extNum:",extNum,"cancelTab:",cancelTab,"isLast:",isLast);
      //console.log(this.item," realCNum:",realCNum,"realNum:",realNum,"realIdx:",realIdx);
      if((realCNum<realIdx&&realIdx===realNum-1)||(num===0&&isLast&&cancelNum!==idx)){
        //console.log('true');
        return true;
      }
      return false;
    }
  },
  methods:{
    cancelPre(type,result){
      this.$emit("cancel",type,result,false,this.idx);
    }
  }
};
</script>
<style lang="less" scoped>
  @import "../less/base.less";
.left {
  margin-bottom: 0.2rem;
  padding-top: 0.12rem;
  padding-left: 0.24rem;
  .content {
    max-width: 5rem;
    background-color: #colors[bgques];
    border-radius: 0 0.24rem 0.24rem 0.24rem;
    margin-top: 0.3rem;
    font-size: 0.28rem;
    padding: 0.24rem;
    display: inline-block;
  }
  img {
    width: 0.8rem;
    height: 0.8rem;
    margin-right: 0.24rem;
  }
}
.right {
  padding-top: 0.2rem;
  margin-bottom: 0.12rem;
  padding-right: 0.24rem;
  .imgs-list{
    max-width: 80%;
    text-align: right;
    float: right;
    margin-right: 0.8rem;
    img{
      width: 1.5rem;
      height: 1.5rem;
    }
  }
  .edit{
    color: #colors[theme];
    font-style: normal;
    font-size: .26rem;
    float: right;
    display: inline-block;
    margin-top: .56rem;
    margin-right: .24rem;
  }
  .content {
    max-width: 5rem;
    background-color: #colors[theme];
    border-radius: 0.24rem 0 0.24rem 0.24rem;
    margin-top: 0.3rem;
    font-size: 0.3rem;
    padding: 0.24rem;
    display: inline-block;
    p {
      color: #fff;
    }
  }
  img {
    width: 0.8rem;
    height: 0.8rem;
    margin-left: 0.24rem;
  }
}
</style>
