<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-04-12 17:56:45
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-18 11:36:42
 -->
<template>
  <section class="common-right-wrap">
    <div class="p-20">
      <div class="overstore-tip m-b-20" style="width:978px;">
        <div role="alert" class="el-alert el-alert--info el-alert-tip flex flex-align-start">
          <i class="el-alert__icon el-icon-info font-12 color-2f54eb"></i>
          <div class="el-alert__content">
            <span class="el-alert__title color-606266 font-14">当前卡券记录中发送数量、领取数量、领取率、使用数量、核销率、销售额为gic总体卡券记录，包含好办使用记录。后续更新将统计好办渠道卡券记录</span>
          </div>
        </div>
      </div>
      <div class="m-b-20">
        <!-- <el-input placeholder="请输入卡券名称" v-model="searchInput" class="w-264" style="width: 264px;" @keyup.native="value => toInput(value, searchInput)" clearable @clear="clearInput"> <i slot="prefix" class="el-input__icon el-icon-search"></i> </el-input> -->
      </div>
      <el-table class="select-table" ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" style="width: calc(100% - 3px);">
        <el-table-column prop="" label="卡券名称" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.cardName }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="" width="96">
          <template slot="header" slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="发送卡券数量，包含扫码发券数" placement="right">
              <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">发送数量</span>
            </el-tooltip>
          </template>
          <template slot-scope="scope">
            {{ scope.row.issuingQuantity }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="领取数量">
          <template slot-scope="scope">{{ scope.row.getedQuantity }}</template>
        </el-table-column>
        <el-table-column prop="" label="领取率">
          <template slot-scope="scope">{{ scope.row.getedRate | percenteNum }}</template>
        </el-table-column>
        <el-table-column prop="" label="使用数量">
          <template slot-scope="scope">
            <div>{{ scope.row.usageQuantity }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="核销率">
          <template slot-scope="scope">
            <div>{{ scope.row.verificationRate | percenteNum }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="销售额">
          <template slot-scope="scope">
            <div>{{ scope.row.saleAmount }}</div>
          </template>
        </el-table-column>
        <el-table-column width="150">
          <template slot="header" slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="发送卡券的导购总人数，次日刷新" placement="right">
              <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">导购人数</span>
            </el-tooltip>
          </template>
          <template slot-scope="scope">
            {{ scope.row.sendMemberCount }}
          </template>
        </el-table-column>
        <el-table-column prop="" width="200" label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="showSendRecord(scope.$index, scope.row, '1')">发送记录</el-button>
            <el-button type="text" @click="showGetRecord(scope.$index, scope.row, '2')">领取记录</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block common-wrap__page text-right m-t-24" v-if="tableData.length != 0">
        <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
      </div>
    </div>
    <card-get-record v-if="getRecordShow" :brandId="brandId" :coupCardId="coupCardId" @closeGetRecord="closeGetRecord"></card-get-record>
    <card-send-record v-if="sendRecordShow" :brandId="brandId" :coupCardId="coupCardId" @closeSendRecord="closeSendRecord"></card-send-record>
  </section>
</template>

<script>
import cardGetRecord from '@/components/app/card/card-get-record.vue';
import cardSendRecord from '@/components/app/card/card-send-record.vue';
import errMsg from '@/common/js/error';
import { _debounce } from '@/common/js/public';
import { postRequest } from '@/api/api';
export default {
  components: {
    cardGetRecord,
    cardSendRecord
  },
  props: {
    brandId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      activeId: '2',

      searchInput: '',
      tableData: [],
      loading: false,
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      getRecordShow: false,
      sendRecordShow: false,
      coupCardId: ''
    };
  },
  filters: {
    percenteNum(val) {
      return val > 0 ? Number(val * 100).toFixed(2) + '%' : Number(val).toFixed(2) + '%';
    }
  },
  watch: {
    brandId(val) {
      if (!!val) {
        this.getTableList();
      }
    }
  },
  methods: {
    showGetRecord(index, row) {
      const that = this;
      that.coupCardId = row.coupCardId;
      that.getRecordShow = true;
    },
    closeGetRecord() {
      const that = this;
      that.getRecordShow = false;
    },
    showSendRecord(index, row) {
      const that = this;
      that.coupCardId = row.coupCardId;
      that.sendRecordShow = true;
    },
    closeSendRecord() {
      const that = this;
      that.sendRecordShow = false;
    },
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList(that.brandId);
    }, 500),
    // 搜索清除
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList(that.brandId);
    },
    /**
     * 分页---页码变化
     *  @param {Number} val
     */
    handleSizeChange(val) {
      let that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     *  @param {Number} val
     */
    handleCurrentChange(val) {
      let that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     * 切换年
     */
    changeYear() {
      let that = this;
      that.currentPage = 1;
      that.getTableList();
    },

    /**
     * 获取列表数据
     */
    async getTableList() {
      const that = this;
      that.loading = true;
      let para = {
        gicEnterpriseId: that.brandId,
        search: that.searchInput || '', // 搜索字段
        pageNum: that.currentPage, // 当前页
        pageSize: that.pageSize // 一页显示个数
      };
      postRequest('/haoban-app-customer-web/cardCoupon/find-card-log-page', para)
        .then(res => {
          let resData = res.data;
          that.loading = false;
          if (resData.errorCode == 1) {
            that.tableData = resData.result.list || [];
            that.total = resData.result.pageInfo.total;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  mounted() {
    let that = this;
    that.$emit('showTab', '2');
    if (!!that.brandId) {
      that.getTableList();
    }
  }
};
</script>
<style type="text/less" lang="less" scoped>
.el-alert--info {
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
  -webkit-box-align: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: flex-start;
  align-items: flex-start;
  .el-alert__icon {
    font-size: 12px;
    padding-top: 3px;
  }
}
.w-123 {
  width: 123px;
}
.p-20 {
  padding: 20px;
  box-sizing: border-box;
}
</style>
