<template>
  <div class="dm-wrap" v-loading="loading">
    <el-row>
      <el-input class="w300" v-model="listParams.search" placeholder="请输入操作对象/操作内容" clearable @change="onSearch">
        <i slot="prefix" class="el-input__icon el-icon-search"></i>
      </el-input>
      <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="onSearch"></el-date-picker>
    </el-row>
    <el-table class="mt20" :data="tableList">
      <el-table-column prop="operatorName" label="操作人">
        <template slot-scope="{ row }">{{ row.operatorPhone }}-{{ row.operatorName }}{{ row.superAdmin ? '-超管' : '' }}</template>
      </el-table-column>
      <el-table-column prop="ecmPlanName" label="操作对象"></el-table-column>
      <el-table-column label="操作时间">
        <template slot-scope="{ row }">
          <p class="cell-time">
            {{ formatDateTimeByType(row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
            <span>{{ formatDateTimeByType(row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
          </p>
        </template>
      </el-table-column>
      <el-table-column prop="context" label="操作内容" width="width"></el-table-column>
    </el-table>
    <dm-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"></dm-pagination>
  </div>
</template>

<script>
import { getEcmLog } from '@/service/api/ecmApi.js';
import { formatDateTimeByType } from '@/utils/index.js';
export default {
  name: 'ecm-operator-Log',
  data() {
    return {
      formatDateTimeByType,
      loading: false,
      tableList: [],
      total: 0,
      listParams: {
        pageSize: 20,
        currentPage: 1,
        beginTime: '',
        endTime: '',
        search: ''
      }
    };
  },
  mounted() {
    this.$store.commit('mutations_breadcrumb', [
      { name: '营销管理', path: '' },
      { name: '智能营销', path: '/ecm' },
      { name: '操作日志', path: '' }
    ]);
    this.getList();
  },
  methods: {
    handleSizeChange(val) {
      this.listParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listParams.currentPage = val;
      this.getList();
    },
    async getList() {
      this.loading = true;
      const { errorCode, result, message } = await getEcmLog(this.listParams).finally(() => (this.loading = false));
      if (errorCode == 0) {
        this.tableList = result.result || [];
        this.total = result.totalCount;
      } else {
        this.$message.warning(message);
      }
    },
    onSearch() {
      this.listParams.currentPage = 1;
      this.getList();
    }
  },
  computed: {
    dateRange: {
      set(val) {
        if (val) {
          this.listParams.beginTime = val[0];
          this.listParams.endTime = val[1];
        } else {
          this.listParams.beginTime = '';
          this.listParams.endTime = '';
        }
      },
      get() {
        return [this.listParams.beginTime, this.listParams.endTime];
      }
    }
  }
};
</script>
