<template>
  <div class="marketing-card">
    <div class="search mb10">
       投放时间：<el-date-picker :clearable="false" class="w256 mb10 mr10" value-format="yyyy-MM-dd" :pickerOptions="pickerOptions" v-model="launchTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
       领取时间：<el-date-picker :clearable="false" class="mr10 w256 mb10" value-format="yyyy-MM-dd" :pickerOptions="pickerOptions" v-model="collectionTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      <el-input
        v-model="search.search"
        placeholder="请输入卡券券码"
        class="w260 mr10 mb10"
        prefix-icon="el-icon-search"
        @change="change"
        clearable
      />
      <el-select class="w160 mb10" v-model="search.receiveCode" placeholder="所有投放渠道" clearable @change="change">
        <el-option v-for="item in tableData.dictList" :key="item.dictCode" :value="item.dictCode" :label="item.dictName" />
      </el-select>
    </div>
    <div class="table">
      <el-table
        v-loading="tableData.loading"
        :data="tableData.data"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column
          v-for="(v, i) in tableData.tableHeader"
          :key="i"
          :prop="v.prop"
          :min-width="v.minWidth"
          :label="v.label"
          :formatter="v.formatter"
          :fixed="v.fixed"
          show-overflow-tooltip
        >
          <template slot-scope="{ row }">
            <span v-if="v.formatter" v-html="v.formatter(row)"></span>
            <span v-else>{{ row[v.prop] || "--" }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="pager" v-if="tableData.total > 0">
        <dm-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="tableData.currentPage"
          :page-sizes="tableData.pageSizeList"
          :page-size="tableData.pageSize"
          layout="total, sizes, prev, pager, next"
          :total="tableData.total"
        >
        </dm-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import dickerPickMixin from './mixins/datePickRuleMixin';
import paginationMixins from './mixins/paginationMixins';
const curMonth = new Date().getMonth() + 1;
const halfBefore = new Date().setMonth(curMonth - (6 + 1));
const datePrickerBegin = new Date(halfBefore).setHours(24);
export default {
  name: 'card',
  props: {
    tableData: Object
  },
  mixins: [ dickerPickMixin, paginationMixins ],
  data() {
    return {
      launchTime: [new Date(datePrickerBegin), new Date()],
      collectionTime: [new Date(datePrickerBegin), new Date()],
      search: {
        putBeginTime: '',  // 投放开始时间
        putEndTime: '', // 投放结束时间
        receiveBeginTime: '', // 领取开始时间
        receiveEndTime: '', // 结束
        search: '', // 卡券代码
        receiveCode: null,  // 投放渠道
      }
    }
  },
  methods: {
    change() {
      const { currentPage, pageSize } = this.tableData;
      const { launchTime, collectionTime } = this;
      this.search.putBeginTime = launchTime ? ( typeof launchTime[0] == 'string ' ? launchTime[0] : this.dateformat(new Date(launchTime[0]), 'yyyy-MM-dd')) : null;
      this.search.putEndTime = launchTime ? ( typeof launchTime[0] == 'string ' ? launchTime[1] : this.dateformat(new Date(launchTime[1]), 'yyyy-MM-dd')) : null;
      this.search.receiveBeginTime = collectionTime ? collectionTime[0] : null;
      this.search.receiveEndTime = collectionTime ? collectionTime[1] : null;
      const commonObj = { currentPage, pageSize };
      this.$emit("changeSearch", Object.assign({}, this.search, commonObj));
    },
  }
};
</script>

<style scoped>
@import './css/all.scss';
</style>
