<template>
  <div class="dm-wrap card_profit">
    <div class="title">
      <h2>卡券收益</h2>
      <span>计划中的卡券，计划中卡券触达的人群使用该卡券消费的收益，包含已过计划收益有效期的数据</span>
    </div>
    <template>
      <card-profit-sum :list="list" />
      <el-table :data="tableData" v-if="tableData.length > 1" style="margin:20px 0 20px" max-height="710" header-cell-class-name="card-profit-header">
        <el-table-column :prop="cardName" label="卡券名称" min-width="150">
          <template slot-scope="scope">
            <div class="name" v-if="scope.row.cardName">
              <div class="top">
                <span v-if="scope.row.cardName.length <= 15" :class="[scope.row.status == 0 ? 'del_card' : 'pointer']" @click="toCardDetail(scope.row)">{{ scope.row.cardName }}</span>
                <el-tooltip open-delay="100" placement="top-start" :content="scope.row.cardName" v-else>
                  <span :class="['card_name', scope.row.status == 0 ? 'del_card' : 'pointer']" @click="toCardDetail(scope.row)">{{ scope.row.cardName }}</span>
                </el-tooltip>
                <span class="type" v-if="scope.row.status != 0">{{ scope.row.cardType == 0 ? '抵金券' : scope.row.cardType == 1 ? '折扣券' : scope.row.cardType == 2 ? '兑换券' : '--' }}</span>
                <img :src="require('@/assets/img/Icon-yishanchu.svg')" alt="" v-else style="width: 46px;height: 21px;margin-left: 6px" />
              </div>
              <p>{{ scope.row.subTitle }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column v-for="(v, i) in tableHeader" :key="i" :prop="v.prop" :label="v.label" :formatter="v.formatter">
          <template slot-scope="scope">
            <span v-if="v.formatter" v-html="v.formatter(scope.row)"></span>
            <span v-else>{{ scope.row[v.prop] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>

<script>
import formatterNum from '@/mixins/validateNum';
import cardProfitSum from './card-profit-sum.vue';
export default {
  name: 'card-profit',
  props: {
    list: {
      type: Object,
      default: () => {}
    },
    tableData: {
      type: Array,
      default: () => []
    }
  },
  mixins: [formatterNum],
  components: { cardProfitSum },
  data() {
    return {
      tableHeader: [
        { label: '触达人数', prop: 'touchMbrNum', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.touchMbrNum) },
        { label: '领取人数', prop: 'getMbrNum', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.getMbrNum) },
        { label: '领取率', prop: 'drawRate', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterRate((row.getMbrNum / row.touchMbrNum) * 100) },
        { label: '使用人数', prop: 'useMbrNum', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.useMbrNum) },
        { label: '使用率', prop: 'useRate', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterRate((row.useMbrNum / row.getMbrNum) * 100) },
        { label: '销售单数', prop: 'orderCnt', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.orderCnt) },
        { label: '销售单金额', prop: 'salesAmt', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNumAndFixed(row.salesAmt) }
      ]
    };
  },
  methods: {
    toCardDetail(row) {
      if (row.status == 0) return;
      window.open(window.location.origin + `/marketing/#/card/edit/${row.cardId}`);
    }
  }
};
</script>

<style scoped lang="scss">
.card_profit {
  padding: 20px !important;
  margin-bottom: 10px !important;
  font-family: PingFangSC-Regular, PingFang SC;
  .title {
    padding-left: 4px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    h2 {
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 700;
      color: #303133;
      line-height: 22px;
    }
    span {
      margin-left: 28px;
      font-size: 14px;
      color: #909399;
    }
  }
  .name {
    color: #303133;
    line-height: 22px;
    .top {
      display: flex;
      align-items: center;
      .type {
        display: inline-block;
        width: 42px;
        height: 16px;
        line-height: 16px;
        text-align: center;
        background: #fff1f0;
        border-radius: 2px;
        border: 1px solid #ffa39e;
        font-size: 12px;
        color: #f5222d;
        margin-left: 6px;
      }
      .card_name {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        max-width: 210px;
      }
      .del_card {
        cursor: normal;
        opacity: 0.56;
      }
      .pointer {
        cursor: pointer;
      }
    }
    p {
      font-size: 12px;
      color: #909399;
      line-height: 22px;
    }
  }
  /deep/ .card-profit-header .cell {
    font-family: PingFangSC-Medium, PingFang SC;
  }
}
</style>
