<template>
  <div class="p20" v-loading="loading">
    <div class="pb20 clearfix flex-center">
      <el-select v-model="listParams.sendStatus" class="w250 mr10" placeholder="全部发放状态" clearable @change="refresh">
        <el-option label="成功" :value="1"></el-option>
        <el-option label="失败" :value="0"></el-option>
      </el-select>
      <el-input placeholder="请输入关键字搜索" class="w400 mr10" v-model="listParams.search" clearable @change="refresh">
        <el-select v-model="listParams.searchType" slot="prepend" style="width:120px;" placeholder="请选择" @change="refresh">
          <el-option label="福利ID" :value="1"></el-option>
          <el-option label="卡券包名称" :value="2"></el-option>
          <el-option label="备注名" :value="3"></el-option>
          <el-option label="副标题" :value="4"></el-option>
          <el-option label="会员称呼" :value="5"></el-option>
          <el-option label="会员手机号" :value="6"></el-option>
        </el-select>
      </el-input>
      <el-select v-model="listParams.appCode" class="w250 mr10" placeholder="全部来源" clearable @change="refresh">
        <el-option label="成功" :value="1"></el-option>
        <el-option label="失败" :value="0"></el-option>
      </el-select>
      <el-input class="vertical-middle w300" v-model="listParams.activityName" clearable placeholder="请输入活动名称搜索" @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
    </div>
    <div class="table-search-head">
      发放时间：<el-date-picker class="w350 mr10" v-model="dateTime" type="daterange" range-separator="~" start-placeholder="领取开始日期" end-placeholder="领取结束日期" @change="refresh"></el-date-picker>
    </div>
    <el-table tooltip-effect="dark" :data="tableList" style="width:100%">
      <el-table-column label="会员信息" fixed="left" min-width="120px">
        <template slot-scope="scope">
          <member-info :member-name="scope.row.memberName" :member-image="scope.row.memberImage" :member-phone="scope.row.memberPhone || scope.row.memberCardNo"></member-info>
        </template>
      </el-table-column>
      <el-table-column label="发放时间" min-width="120px">
        <template slot-scope="scope">
          <div v-html="listTime(scope.row.createTime)"></div>
        </template>
      </el-table-column>
      <el-table-column prop="appName" label="履约单号" min-width="120px"></el-table-column>
      <el-table-column prop="couponPackageName" label="卡券包名称" min-width="130px">
        <template slot-scope="scope">
          <span :title="scope.row.couponPackageId" p-key="couponPackageId">{{ scope.row.couponPackageName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="couponPackageName" label="卡券数量" min-width="130px">
        <template slot="header">
          <el-tooltip placement="top" content="卡券包中会员真实领取的卡券数量" open-delay="200">
            <span class="tooltip-icon">卡券数量</span>
          </el-tooltip>
        </template>
        <template slot-scope="scope">
          <el-button type="text" @click="showDetail(scope.row)">{{ scope.row.couponSize }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="来源" min-width="150px">
        <template slot-scope="scope">
          <el-button type="text">{{ scope.row.appName || '--' }}</el-button>
          <el-button type="text">{{ scope.row.activityName || '--' }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="clearfix">
      <dm-pagination class="fr mb0" v-if="tableList.length" background @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>
    </div>
  </div>
</template>

<script>
import { page, formate } from '@/mixins/table.js';
import { listTime } from '@/utils/index.js';
import api from '@/api/card-package.js';
const { pagePackageLog } = api;
export default {
  name: 'MergeRecordList',
  mixins: [ page, formate  ],
  data() {
    return {
      loading: false,
      dateTime: [],
      listParams: {
        appCode: '',
        activityName: '',
        sendStatus: '',
        beginTime: '',
        endTime: '',
        packageName: '',
        search: '',
        searchType: 2,
        currentPage: 1,
        pageSize: 20
      },
      tableList: [],
      total: 0,
      detail: '',
      mask: {
        show: false
      }
    };
  },
  created() {
    this.$emit('updateBread', [  { breadName: '福利中心'  }, { breadName: 'GIC卡券包', breadPath: '/card-package/list' }, { breadName: '卡券包发放记录' } ]);
  },
  mounted() {
    this.getTableList();
  },
  methods: {
    listTime,
    showDetail({ packageLogId }) {
      return;
    },
    getTableList() {
      if(this.loading) {
        return;
      }
      this.loading = true;
      this.formatterTimeFunc('beginTime', 'endTime', 'yyyy-MM-dd', 'dateTime');
      let params = { ...this.listParams, memberCardId: this.currentAreaId };
      pagePackageLog(params).then(res => {
        this.loading = false;
        const data = res.result;
        console.log(data.result);
        this.tableList = data.result || [];
        this.total = data.totalCount;
        // 删除至最后一页没数据的情况，页码-1
        if (this.tableList.length === 0 && this.listParams.currentPage !== 1) {
          this.listParams.currentPage -= 1;
          this.getTableList();
        }
      }).finally(() => {
        this.loading = false;
      });
    }
  },
};
</script>
