<template>
  <div class="marketing-ecm">
    <div class="search">
      <el-input
        v-model="search.search"
        placeholder="请输入计划名称"
        class="w260"
        prefix-icon="el-icon-search"
        clearable
        @change="change"
      />
      <el-date-picker :clearable="false" class="ml10 w256" value-format="yyyy-MM-dd" :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.marketingType" placeholder="所有营销方式" clearable @change="change">
        <el-option v-for="item in ecmTypeList" :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: "ecm",
  props: {
    tableData: Object
  },
  mixins: [ dickerPickMixin, paginationMixins ],
  data() {
    return {
      search: {
        search: '',
        beginTime: '',
        endTime: '',
        marketingType: null
      },
      ecmTypeList: [
        { label: '积分', value: 'integral' },
        { label: '短信', value: 'message' },
        { label: '话务', value: 'teltask' },
        { label: '群发任务', value: 'qfxx' },
        { label: '图文消息', value: 'teletext' },
        { label: '图片', value: 'image' },
        { label: '文本消息', value: 'text' },
        { label: '小程序', value: 'wxa' },
        { label: '卡券', value: 'card' }
      ]
    };
  },
  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>
