<template>
  <div id="api-retry">
    <!-- eslint-disable -->
    <header>
      <el-date-picker
        v-model="searchData.date"
        type="daterange"
        range-separator="~"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
        style="width: 400px"
        @change="onSearchDataChange">
      </el-date-picker>
    </header>
    <!-- 表格 -->
    <el-table
      v-loading="load"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%">
      <el-table-column
        label="品牌"
        show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.i }}
        </template>
      </el-table-column>
      <el-table-column
        label="接口名称"
        show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.fieldName || '--' }}
        </template>
      </el-table-column>
      <el-table-column
        label="重试状态"
        show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.triggerCuInfo || '--' }}
        </template>
      </el-table-column>
      <el-table-column
        label="失败原因"
        show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.targetCuInfo || '--' }}
        </template>
      </el-table-column>
      <el-table-column
        label="时间">
        <template slot-scope="{row}">
          <div class="twoLine">
            {{ row.beforeData || '--' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="{row}">
          <el-button type="text" @click.prevent.native="retry(row.a)">重试</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-if="tableData.length > 0"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currentPage"
      :page-sizes="[20, 40, 60, 80]"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next"
      :total="page.totalCount">
    </el-pagination>
  </div>
</template>
<script>
/* eslint-disable */
import { getRequest } from '@/api/api';

export default {
  name: 'api-retry',
  data() {
    return {
      menuData: [
        {
          name: '接口重试',
          path: '/api-retry'
        }
      ],
      activeName: 'first',
      searchData: {
        date: []
      },
      tableData: [],
      page: {
        currentPage: 1,
        pageSize: 20,
        totalCount: 999
      },
    }
  },
  created() {
    this.getLogsList();
  },
  mounted() {
    // this.$emit('showTab', 'platform_erp_retry');
  },
  methods: {
    getLogsList() {
      // eslint-disable-next-line
      let { date } = this.searchData;
      let { currentPage, pageSize } = this.page;
      date = date.length ? date : ['',''];
      let params = {
        startTime: date[0] || undefined,
        endTime: date[1] || undefined,
        currentPage	: currentPage || 1,
        pageSize: pageSize || 20
      };
      getRequest('/gic-platform-operation/erp/list', params).then(res => {
        console.log(res)
        const { result } = res;
        if(result) {
          this.page.totalCount = result.totalCount || 0;
          this.tableData = result.result || [];
        }
      })
    },
    onSearchDataChange(val) {
      this.page.currentPage = 1;
      !val && (this.searchData.date = []);
      this.getLogsList();
    },
    // 改变每页显示数量
    handleSizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
      this.getLogsList();
    },
    // 换页
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.getLogsList();
    },
  },
  props: {
    // 左侧菜单选中 id
    activeSelTab: {
      type: [String, Number],
      default() {
        return 'platform_erp_retry';
      }
    }
  },
}
</script>
<style lang="scss" scoped>
#api-retry {
  background-color: #fff;
  header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
  }
}
</style>