<template>
  <div class="marketing-message">
    <div class="search">
      <el-input placeholder="请输入活动名称" type="text" prefix-icon="el-icon-search" class="w256" clearable v-model="search.planName" @change="change"></el-input>
      <el-date-picker :clearable="false" value-format="yyyy-MM-dd" class="w256 ml10" :pickerOptions="pickerOptions" v-model="time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
      <span class="search-tip ml10">同一客户同时外呼成功并发送短信营销次数算作两次</span>
    </div>
    <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"
        :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>
    <dm-pagination
      v-if="tableData.total > 0"
      style="margin-top: 20px; text-align: right"
      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>
</template>

<script>
import dickerPickMixin from './mixins/datePickRuleMixin';
import paginationMixins from './mixins/paginationMixins';
export default {
  name: 'AiRecord',
  props: {
    tableData: Object
  },
  mixins: [ dickerPickMixin, paginationMixins ],
  data() {
    return {
      search: {
        planName: '',
        aiStartTime: '',
        aiEndTime: ''
      }
    }
  },
  methods: {
    change() {
      const { currentPage, pageSize } = this.tableData;
      this.search.aiStartTime = this.time ? ( typeof this.time[0] == 'string ' ? this.time[0] : this.dateformat(new Date(this.time[0]), 'yyyy-MM-dd')) : null;
      this.search.aiEndTime = this.time ? ( typeof this.time[0] == 'string ' ? this.time[1] : this.dateformat(new Date(this.time[1]), 'yyyy-MM-dd')) : null;
      this.$emit("changeSearch", Object.assign({ pageNum: currentPage, pageSize }, this.search));
    }
  }
};
</script>

<style lang="scss" scoped>
@import './css/all.scss';
.search .search-tip {
  vertical-align: middle;
  font-size: 14px;
  color: #909399;
}
</style>
