<template>
  <section class="dm-wrap" v-loading="recordLoading">
    <div class="clearfix pb22">
      <el-input v-model="listParams.search" class="w350" placeholder="请输入用户信息/兑换码名称" clearable @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
      <el-date-picker class="w350" v-model="dateTime" type="daterange" range-separator="至" start-placeholder="兑换开始日期" end-placeholder="兑换结束日期" @change="refresh"></el-date-picker>
    </div>
    <el-table tooltipEffect="light" :data="tableList" style="width: 100%">
      <el-table-column :show-overflow-tooltip="true" min-width="120" header-align="left" fixed="left" align="left" prop="memberId" label="会员信息">
        <template slot-scope="scope">
          <a :href="'/member/#/wechatmemberDetail?memberId=' + scope.row.memberId" target="_blank">
            <img class="vertical-middle table__avatar--40" :src="scope.row.imageUrl || defaultAvatar" width="60" height="60" />
            <div class="inline-block vertical-middle">
              <p class="table-name--ellipsis">{{ scope.row.memberName || '--' }}</p>
              <!-- <p class="fz13 gray">{{ scope.row.phoneNumber || '--' }}</p> -->
            </div>
          </a>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" label="兑换时间">
        <template slot-scope="scope">
          <p class="cell-time">
            {{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm', true).y }}<br />
            <span>{{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm', true).h }}</span>
          </p>
        </template>
      </el-table-column>
      <el-table-column min-width="140" align="left" prop="search" label="兑换码名称" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" label="兑换码类型">
        <template slot-scope="scope">
          <!-- 兑换码类型（1：专属，2：通用） -->
          {{ scope.row.cdkeyType == 1 ? '专属码' : '通用码' }}
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="140" align="left" prop="cdkey" label="兑换码码值"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="140" align="left" prop="cdkeyContentDescribe" label="兑换内容"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="createTime" label="兑换码状态">
        <template slot-scope="scope">
          <div v-if="scope.row.convertibilityStatus == 1" class="dm-status--success">成功</div>
          <div v-if="scope.row.convertibilityStatus == 2" class="dm-status--error">失败</div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="convertibilityRemark" label="备注"></el-table-column>
    </el-table>
    <dm-pagination v-show="tableList.length" background class="dm-pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listParams.currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="listParams.pageSize" layout="total, sizes, prev, pager, next" :total="total"></dm-pagination>
  </section>
</template>
<script>
import { cdkeyLogRecord } from '@/service/api/cdKeyApi.js';
import { formatDateTimeByType } from '@/utils/index.js';
import tableMethods from '@/mixins/tableMethods.js';
export default {
  name: 'cdkey-record',
  mixins: [tableMethods],
  data() {
    return {
      recordLoading: false,
      tableList: [],
      listParams: {
        beginTime: '',
        endTime: '',
        search: '',
        currentPage: 1,
        pageSize: 20
      },
      dateTime: ['', ''],
      total: 0
    };
  },
  created() {
    this.$store.commit('mutations_breadcrumb', [{ name: '营销管理', path: '' }, { name: '兑换码', path: '' }, { name: '兑换记录', path: '' }]); // eslint-disable-line
    this.getTableList();
  },
  methods: {
    formatDateTimeByType,
    async getTableList() {
      try {
        this.recordLoading = true;
        if (this.dateTime) {
          this.listParams.beginTime = formatDateTimeByType(this.dateTime[0], 'yyyy-MM-dd');
          this.listParams.endTime = formatDateTimeByType(this.dateTime[1], 'yyyy-MM-dd');
        } else {
          this.listParams.beginTime = this.listParams.endTime = '';
        }
        let res = await cdkeyLogRecord(this.listParams);
        if (res.errorCode === 0 && res.result) {
          this.tableList = res.result.result || [];
          this.total = res.result.totalCount;
        } else {
          this.tableList = [];
          this.total = 0;
        }
        this.recordLoading = false;
      } catch (err) {
        this.recordLoading = false;
      }
    }
  }
};
</script>
