<template>
  <section class="dm-wrap">
    <div class="pb22 clearfix">
      <span>创建时间</span><el-date-picker class="w400 ml10" v-model="dateTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="refresh"></el-date-picker> <span class="ml20">发送时间</span><el-date-picker class="w400 ml10" v-model="dateTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="refresh"></el-date-picker>
      <el-button class="fr" type="primary" @click="$router.push('/message/import-send/add')">导入群发</el-button>
    </div>
    <div class="pb22 clearfix">
      <el-select class="dm-select w160" v-model="listParams.status" clearable placeholder="所有状态" @change="refresh">
        <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-input v-model="listParams.searchParam" class="w300" placeholder="请输入模板名称" clearable @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
    </div>
    <el-table tooltipEffect="light" :data="tableList" style="width: 100%" v-loading="loading">
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="cardName" label="模板名称"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" width="100" align="left" prop="createTime" 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 :show-overflow-tooltip="true" width="100" align="left" prop="createTime" 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 :show-overflow-tooltip="true" min-width="120" align="left" prop="cardName" label="模板内容"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="cardName" label="计划人数"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="cardName" label="送达人数"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="cardName" label="计费人数"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" min-width="120" align="left" prop="orderNumber" label="状态">
        <template slot-scope="scope">
          <span v-html="filterStatus(scope.row)"></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" width="120px" fixed="right">
        <template>
          <el-button type="text" @click="$router.push('/message/import-send/info/123')">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-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"></el-pagination>
    <vue-gic-export-excel :dialogVisible.sync="dialogVisible" :dataArr="tableList" :type="2" :excelUrl="excelUrl" :params="params" :projectName="projectName"></vue-gic-export-excel>
  </section>
</template>
<script>
import { coupcardCheckList, exportCoupcardCheckExcel } from '@/service/api/cardApi.js';
import { formatDateTimeByType } from '@/utils/index.js';
import talbeMethods from '@/mixins/tableMethods.js';
import filterAvater from '@/mixins/filterAvater.js';

export default {
  name: 'destory-list',
  mixins: [talbeMethods, filterAvater],
  data() {
    return {
      formatDateTimeByType,
      dateTime: [],
      listParams: {
        beginTime: '',
        endTime: '',
        searchParam: '',
        currentPage: 1,
        pageSize: 20
      },
      status: [{ value: 0, label: '抵金券' }, { value: 1, label: '折扣券' }, { value: 2, label: '兑换券' }], // eslint-disable-line
      total: 0,
      loading: false,
      tableList: [],
      projectName: 'marketing', // 当前项目名
      dialogVisible: false,
      excelUrl: '', // 下载数据的地址
      params: {} // 传递的参数
    };
  },
  created() {
    this.getTableList();
    this.$store.commit('mutations_breadcrumb', [{ name: '营销管理', path: '' }, { name: '短信营销', path: '' }, { name: '导入发送列表', path: '' }]); // eslint-disable-line
  },
  methods: {
    // 列表状态过滤器
    // 8.优惠券状态（0：删除，1：正常，2：失效，3：已发放，4：已领取，5：已使用，6：已到期,7:已销毁, 8:已占用）
    filterStatus(row) {
      let _content = '';
      if (row.status == 0) {
        _content = `<div class="dm-status--info">已删除</div>`;
      } else if (row.status == 1) {
        _content = `<div class="dm-status--primary">正常</div>`;
      } else if (row.status == 2) {
        _content = `<div class="dm-status--info">已失效</div>`;
      } else if (row.status == 3) {
        _content = `<div class="dm-status--primary">已发放</div>`;
      } else if (row.status == 4) {
        _content = `<div class="dm-status--success">已领取</div>`;
      } else if (row.status == 5) {
        _content = `<div class="dm-status--success">已使用</div>`;
      } else if (row.status == 6) {
        _content = `<div class="dm-status--info">已到期</div>`;
      } else if (row.status == 7) {
        _content = `<div class="dm-status--info">已销毁</div>`;
      } else if (row.status == 8) {
        _content = `<div class="dm-status--info">已占用</div>`;
      }
      return _content;
    },
    // 加载列表
    async getTableList() {
      return;
      this.loading = true;
      this.dataTimeFormat();
      try {
        let res = await coupcardCheckList(this.listParams);
        this.tableList = res.result.result || [];
        this.total = res.result.totalCount || 0;
      } catch (err) {
        this.$tips({ type: 'error', message: '加载列表失败' });
      }
      this.loading = false;
    },
    // 导出列表
    exportExcel() {
      this.dialogVisible = true;
      this.excelUrl = exportCoupcardCheckExcel;
      this.dataTimeFormat();
      this.params = {
        searchParam: this.listParams.searchParam,
        beginTime: this.listParams.beginTime,
        endTime: this.listParams.endTime,
        requestProject: 'marketing'
      };
    },
    /**-------辅助方法---------- */
    dataTimeFormat() {
      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 = '';
      }
    }
  }
};
</script>
