<template>
  <div class="marketing-message">
    <div class="search">
       <el-date-picker :clearable="false" value-format="yyyy-MM-dd" class="w256" :pickerOptions="pickerOptions" v-model="time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
       <el-select class="ml10 w160" v-model="search.smsType" placeholder="所有模板类型" clearable @change="change">
        <el-option v-for="item in sysTypeList" :key="item.id" :value="item.value" :label="item.label" />
      </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';
export default {
  name: 'message',
  props: {
    tableData: Object
  },
  mixins: [ dickerPickMixin, paginationMixins ],
  data() {
    return {
      search: {
        beginTime: '',
        endTime: '',
        smsType: null
      },
      sysTypeList: [
        { label: '普通短信', value: 0 },
        { label: '营销短信', value: 1 }
      ]
    }
  },
  methods: {
    change() {
      const { currentPage, pageSize } = this.tableData;
      this.search.beginTime = this.time ? ( typeof this.time[0] == 'string ' ? this.time[0] : this.dateformat(new Date(this.time[0]), 'yyyy-MM-dd')) : null;
      this.search.endTime = this.time ? ( typeof this.time[0] == 'string ' ? this.time[1] : this.dateformat(new Date(this.time[1]), 'yyyy-MM-dd')) : null;
      const commonObj = { currentPage, pageSize };
      this.$emit("changeSearch", Object.assign({}, this.search, commonObj));
    }
  }
};
</script>

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