<template>
  <div class="AbstractProgram">
    <br />
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>新媒体</el-breadcrumb-item>
      <el-breadcrumb-item>稿前校对统计</el-breadcrumb-item>
    </el-breadcrumb>
    <br />
    <el-card class="box-card">
      <el-form
        :model="form"
        size="small"
        :inline="true"
        label-width="120px"
        class="demo-form-inline"
      >
        <el-form-item label="日期">
          <el-date-picker
            v-model="form.time"
            type="datetimerange"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            :disabled-date="disabledDate"
            placeholder="日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关键词">
          <el-input v-model="form.keyword" placeholder="检索关键词" clearable />
        </el-form-item>
        <el-form-item style="float: right">
          <el-button type="primary" @click="onSubmit" :loading="load">
            查询
          </el-button>
          <!-- <el-button type="primary" @click="onExport" :loading="load">
            导出
          </el-button> -->
        </el-form-item>
      </el-form>
    </el-card>
    <br />
    <el-card>
      <el-table :data="tableData" style="width: 100%" :header-cell-style="{ backgroundColor: '#f4f5f7', color: '#606266' }">
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="displayName"
          label="用户名称"
        />
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="createTime"
          label="校对时间"
        />
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="textLength"
          label="校对字数"
        />
      </el-table>
      <br />
      <el-pagination
        @current-change="change"
        background
        :default-current-page="page"
        layout="prev, pager, next"
        :total="total"
      />
    </el-card>
  </div>
</template>

<script>
// @ is an alias to /src
import { getYoumeiList } from '@/api/newMdeiaApi';
import dayjs from 'dayjs';

//   import config from "@/config/index";
let T = undefined;
export default {
  name: 'Proofread',
  data() {
    return {
      page: 1,
      size: 10,
      total: 0,
      load: false,
      tableData: [],
      form: {
        keyword: '',
        time: [],
      },
    };
  },
  mounted() {
    const h = Date.now();
    const h1 = h - (h % 3600000);
    const h2 = h - (h % 3600000) - 3600000;
    const time1 = dayjs(h2).format('YYYY-MM-DD HH:mm:ss');
    const time2 = dayjs(h1).format('YYYY-MM-DD HH:mm:ss');
    this.form = {
      keyword: '',
      time: [time1, time2],
    };
    this.getDate();
  },
  computed: {},
  methods: {
    getDate() {
      if (T) window.clearTimeout(T);
      T = setTimeout(() => {
        this.load = true;
        if (T) window.clearTimeout(T);
      }, 200);
      getYoumeiList({
        page: this.page,
        size: this.size,
        keyword: this.form.keyword,
        startTime: this.form.time[0],
        endTime: this.form.time[1],
      })
        .then(r => {
          if (T) window.clearTimeout(T);
          this.load = false;
          this.total = r.total || 0;
          this.tableData = r.records || [];
        })
        .catch(() => {
          if (T) window.clearTimeout(T);
          this.tableData = [];
          this.load = false;
        });
    },
    disabledDate(time) {
      return time.getTime() > Date.now();
    },
    change(page) {
      this.page = page;
      console.log(page);
      this.getDate();
    },
    onSubmit() {
      this.page = 1;
      this.getDate();
    },
    onExport() {},
  },
  components: {},
};
</script>

<style>
.el-pagination .btn-next .el-icon,
.el-pagination .btn-prev .el-icon{
    margin: 0 auto;
}
</style>
