<template>
  <section class="static-detial" v-loading="loading">
    <dm-sub-title title-align="space-between">
      活动数据详情
    </dm-sub-title>
    <div class="tips mt5 mb20">数据每天更新 1 次</div>
    <div class="pb20 clearfix">
      <el-input v-model="form.search" class="w270" placeholder="请输入姓名/昵称/手机号/会员卡号" clearable @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
      <el-date-picker class="w256" v-model="form.dateTime" value-format="yyyy-MM-dd" @change="refresh" type="daterange" range-separator="~" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
      <el-button icon="iconfont fz14 icon-cp-xiazai" type="primary" class="fr" @click="handleExport" size="small" :disabled="!total"> 查询结果导出</el-button>
    </div>
    <el-table tooltipEffect="light" :data="tableList" style="width:100%">
      <el-table-column label="基本信息" min-width="214" fixed="left">
        <div slot-scope="{ row }" class="member-info">
          <img class="member-logo" v-if="row.memberImage" :src="row.memberImage" alt="" />
          <svg aria-hidden="true" v-else class="member-logo">
            <use xlink:href="#icon-user-default"></use>
          </svg>
          <div>
            <p class="member-name">
              <template v-if="row.memberNick">
                {{ row.memberNick || '--' }}
              </template>
              <span class="member-subname" v-if="row.memberName">
                {{ row.memberNick ? `(${row.memberName})` : row.memberName }}
              </span>
            </p>
            <p class="member-name" v-if="row.phoneNum">{{ row.phoneNum }}</p>
          </div>
        </div>
      </el-table-column>
      <el-table-column label="会员卡号" min-width="130px" prop="cardNum" show-overflow-tooltip :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column label="服务门店" min-width="210" prop="mainStoreName">
        <template slot-scope="{ row }">
          {{ row.mainStoreName || '--' }}
          <br />
          {{ row.mainStoreCode || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="浏览次数" min-width="96" prop="browseCnt" :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column label="中奖次数" min-width="96" prop="winCnt" :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column label="分享次数" min-width="96" prop="shareCnt" :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column label="裂变新用户" min-width="112" prop="invitationMemberCnt" :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column label="消耗积分" min-width="96" prop="useIntegralCnt" :formatter="(row, col, val) => val || '--'"></el-table-column>
      <el-table-column min-width="88" prop="isNewMember" :formatter="(row, col, val) => val || '--'">
        <template slot="header">
          新会员
          <el-tooltip placement="top">
            <div slot="content">
              1、用户自身是否通过本次游戏注册成为会员；<br />
              2、POS会员转微信会员也会统计为新会员。
            </div>
            <i class="iconfont icon-QuestionCircleOutlined"></i>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="首次参与时间" min-width="114" prop="firstPlayTime" fixed="right">
        <template slot-scope="{ row }">
          {{ formatDateTimeByType(row.firstPlayTime, 'yyyy-MM-dd') || '--' }}
          <br />
          {{ formatDateTimeByType(row.firstPlayTime, 'HH-mm-ss') || '--' }}
        </template>
      </el-table-column>
    </el-table>
    <dm-pagination v-show="tableList.length" background class="dm-pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="form.pageNum" :page-sizes="[20, 40, 60, 80]" :page-size="form.pageSize" layout="total, sizes, prev, pager, next" :total="total"></dm-pagination>
    <vue-gic-export-excel :dialogVisible.sync="dialogVisible" :dataArr="tableList" :type="2" :excelUrl="exportGameDetail" :params="params" projectName="marketing"></vue-gic-export-excel>
  </section>
</template>

<script>
import { formatDateTimeByType } from '@/utils/index.js';
import { getGameDataDetail, exportGameDetail } from '@/service/api/gameApi.js';
export default {
  data() {
    return {
      tableList: [],
      form: {
        pageNum: 1,
        pageSize: 20,
        gameId: this.$route.params.id,
        dateTime: [],
        search: ''
      },
      formatDateTimeByType,
      total: 0,
      dialogVisible: false,
      exportGameDetail,
      params: {},
      loading: false
    };
  },
  mounted() {
    this.getTableList();
  },
  methods: {
    handleExport() {
      this.dialogVisible = true;
      this.params = {
        gameId: this.$route.params.id,
        search: this.form.search
      };
      if (this.form.dateTime && this.form.dateTime.length) {
        this.params.startTime = this.form.dateTime[0];
        this.params.endTime = this.form.dateTime[1];
      }
    },
    refresh() {
      this.form.pageNum = 1;
      this.getTableList();
    },
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getTableList();
    },
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getTableList();
    },
    getTableList() {
      const params = { ...this.form };
      this.loading = true;
      if (params.dateTime && params.dateTime.length) {
        params.startTime = params.dateTime[0];
        params.endTime = params.dateTime[1];
      }
      delete params.dateTime;

      getGameDataDetail(params)
        .then(res => {
          const { result } = res;
          this.tableList = result.result;
          this.total = result.totalCount;
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.static-detial {
  padding: 16px 20px;
}
.tips {
  font-weight: 400;
  color: #606266;
  line-height: 17px;
}
.member-info {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .member-logo {
    flex-shrink: 0;
    margin-right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 40px;
    overflow: hidden;
  }
  .member-name {
    font-size: 14px;
    font-weight: 400;
    color: #303133;
    line-height: 20px;
    .member-subname {
      color: #909399;
    }
  }
}
</style>
