<template>
  <div class="content">
    <div class="top" v-if="!isCluePage">
      <div class="left">计划：{{ $route.query.name }}</div>
      <div class="right" v-if="isRepeat">批次合计：{{ batchNum }} / 最新批次时间：{{ batchTimes }}</div>
    </div>
    <div class="middle" v-for="(item, index) in data" :key="index">
      <template v-if="item.isSales == 1">
        <div class="left" v-if="isReference && !isCluePage">
          <img :src="require('@/assets/img/experimentIcon.png')" class="icon" />
          <span class="title">实验组</span>
          <span>-计划触达</span>
        </div>
      </template>
      <template v-else>
        <div class="left" v-if="isReference && !isCluePage">
          <img :src="require('@/assets/img/referenceIcon.png')" class="icon" />
          <span class="title">参照组</span>
          <span>-计划非触达</span>
        </div>
      </template>
      <!--非线索页列表-->
      <div class="right" :class="[isCluePage ? 'cluePage' : '']" ref="right">
        <div v-if="!isCluePage">
          <p>计划人次</p>
          <!-- <p>{{ item.planMbrTimes ? item.planMbrTimes.toLocaleString() : 0 }}</p> -->
          <p>{{ formatterNum(item.planMbrTimes) }}</p>
        </div>
        <div>
          <p>{{ isCluePage ? '计划触达人数' : '计划人数' }}</p>
          <p>{{ formatterNum(item.planMbrNum) }}</p>
        </div>
        <div v-if="isCluePage && item.flag" class="taskRate">
          <p>
            任务完成率<span>（任务总数 {{ formatterNum(item.taskCnt) }}）</span>
          </p>
          <p>{{ formatterRate(item.taskRate) }}</p>
        </div>
        <div v-if="isCluePage || item.isSales == 1" class="touchMbr">
          <p>
            触达人数<span>（触达率 {{ formatterRate(item.touchRate) }}）</span>
          </p>
          <p>{{ formatterNum(item.touchMbrNum) }}</p>
        </div>
        <div v-else class="touchMbr touchMbr2">- -</div>
        <div class="convMbr">
          <p>
            转化人数<span :class="{ active: isReference && item.isSales == 1 && data[0].transformRate < data[1].transformRate }">（转化率 {{ formatterRate(item.transformRate) }}）</span>
          </p>
          <p>{{ formatterNum(item.convMbrNum) }}</p>
        </div>
        <div>
          <p>转化订单数</p>
          <p>{{ formatterNum(item.convOrderCnt) }}</p>
        </div>
        <div>
          <p>转化收益</p>
          <p>{{ parseFloat(item.convSalesAmt || 0).toLocaleString('zh', { minimumFractionDigits: 2 }) }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'market-list',
  props: {
    // 是否是线索页面
    isCluePage: {
      type: Boolean,
      default: false
    },
    // 是否重复营销
    isRepeat: {
      type: Boolean,
      default: true
    },
    // 是否勾选参照组
    isReference: {
      type: Boolean,
      default: true
    },
    // 数据
    data: {
      type: Array,
      default: () => []
    },
    batchTimes: String,
    batchNum: Number | String
  },
  computed: {
    formatterNum() {
      return val => (!val ? '0' : parseInt(val).toLocaleString());
    },
    formatterRate() {
      return val => (!val ? '0.00%' : parseFloat(val).toFixed(2) + '%');
    }
  }
};
</script>
<style lang="scss" scoped>
.content {
  font-family: PingFangSC-Medium, PingFang SC;
  margin-left: 8px;
  margin-right: 13px;
  .top {
    color: #303133;
    height: 50px;
    background: #f5f7fa;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    margin-top: 10px;
    .left {
      font-size: 16px;
      font-weight: 600;
      line-height: 22px;
      padding-left: 27px;
    }
    .right {
      font-family: PingFangSC-Regular, PingFang SC;
      font-size: 14px;
      font-weight: 400;
      line-height: 20px;
      padding-right: 16px;
    }
  }
  .middle {
    margin-bottom: 4px;
    height: 100px;
    background: #f0f5ff;
    border-radius: 6px;
    display: flex;
    align-items: center;
    .left {
      width: 226px;
      height: 55px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      padding: 0 35px 0 25px;
      border-right: 1px solid#E4E7ED;
      span {
        font-size: 14px;
        font-weight: 400;
        color: #606266;
        line-height: 20px;
        white-space: nowrap;
      }
      .title {
        font-weight: 600;
        color: #303133;
        margin-right: 4px;
      }
      .icon {
        width: 40px;
        height: 40px;
        border-radius: 4px;
        margin-right: 15px;
      }
    }
    .right {
      padding: 0 28px 0 32px;
      height: 58px;
      flex: 1;
      display: flex;
      justify-content: space-between;
      div {
        flex: 1;
        p {
          &:nth-child(1) {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #606266;
            line-height: 20px;
            padding-top: 4px;
            margin-bottom: 6px;
          }
          &:nth-child(2) {
            font-size: 24px;
            font-family: DINAlternate-Bold, DINAlternate;
            font-weight: bold;
            color: #303133;
            line-height: 28px;
          }
          .active {
            color: #f5222d;
            margin-left: 4px;
          }
        }
      }
      .touchMbr2 {
        align-items: center;
        padding-top: 19px;
      }
      .convMbr,
      .touchMbr,
      .taskRate {
        flex: 1.3;
      }
    }
    .cluePage {
      padding-left: 65px;
    }
    &:nth-of-type(3) {
      background: #f5f7fa;
      margin-bottom: 7px;
      .left {
        padding-right: 21px;
      }
    }
  }
}
</style>
