<template>
  <div class="dm-wrap card_profit">
    <div class="title">
      <h2>卡券</h2>
      <span>在卡券下发后，下发顾客在营销有效期内的消费转化情况。无论顾客最终有没有使用卡券消费都会统计在内</span>
    </div>
    <template>
      <card-profit-sum :list="list" />
      <div class="title" style="margin-top:20px">
        <h2 class="mini-sub-title">卡券核销</h2>
        <span>卡券核销情况统计通过当前智能营销计划投放的卡券，顾客使用该卡券消费的情况。即使消费时间已经过了收益有效期也会统计在内</span>
      </div>
      <el-table :data="tableData" v-if="tableData.length > 0" 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 || !('status' in scope.row) ? '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 && 'status' in scope.row">{{ scope.row.cardType == 0 ? '抵金券' : scope.row.cardType == 1 ? '折扣券' : scope.row.cardType == 2 ? '兑换券' : scope.row.cardType == 3 ? '商场抵金券' : '--' }}</span>
                <img :src="require('@/assets/img/Icon-yishanchu.svg')" alt="" v-else-if="'status' in scope.row" 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: 'drawRate', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterRate((row.getMbrNum / row.touchMbrNum) * 100) },
        { label: '领取人数', prop: 'getMbrNum', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.getMbrNum) },
        { label: '核销率', prop: 'useRate', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterRate((row.useMbrNum / row.getMbrNum) * 100) },
        { label: '核销人数', prop: 'useMbrNum', minWidth: '160', align: 'left', fixed: 'left', formatter: row => this.formatterNum(row.useMbrNum) },
        { 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 || !('status' in row)) 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;
  h2.subtitle {
    width: 139px;
    height: 25px;
    background: #bad9ff;
    line-height: 25px;
    text-align: center;
    border-radius: 2px;
    margin-left: -2px;
    color: #303133;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 600;
  }
  .title {
    padding-left: 4px;
    margin-bottom: 20px;
    display: flex;
    // align-items: center;
    flex-direction: column;
    h2 {
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 700;
      color: #303133;
      line-height: 22px;
    }
    span {
      // margin-left: 28px;
      margin-top: 20px;
      font-size: 14px;
      color: #909399;
    }
  }
  .name {
    color: #303133;
    line-height: 22px;
    .top {
      display: flex;
      align-items: center;
      .type {
        display: inline-block;
        padding: 0 5px;
        // 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>
