<template>
  <base-list>
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="请求类型">
          <el-input v-model="pagerDto._Co_Target" />
        </el-form-item>
        <el-form-item label="请求路径">
          <el-input v-model="pagerDto._Co_ActionUrl" />
        </el-form-item>
        <el-form-item label="是否已重试">
          <el-select v-model="pagerDto._Eq_IsExecute" placeholder="是否已重试" clearable>
            <el-option
        v-for="item in IsExecutes"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
      </el-select>
        </el-form-item>
        <el-form-item label="失败时间" style="float:left;margin:0 10px">
          <el-date-picker
            v-model="pagerDto._Range_CreateTime"
            type="daterange"
            style="width:290px"
            range-separator="~"
            start-placeholder="失败时间开始"
            value-format="yyyy-MM-dd"
            end-placeholder="失败时间结束"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="pagerSerach(1)">搜索</el-button>
        </el-form-item>
      </el-form>
    </template>
    <template slot="n_option">
        <el-button @click="toPerform()">
        按勾选重新执行
      </el-button>
    </template>
    <template>
      <el-table
        v-loading="dataLoading"
        :data="data"
        :highlight-current-row="true"
        :select-on-indeterminate="true"
        width="100%"
        @selection-change="onSelection"
      >
       <el-table-column type="selection" :selectable="rowCanSelect" />
        <el-table-column prop="Target" label="请求类型" />
        <el-table-column prop="IsExecute" label="是否重试执行">
             <template slot-scope="r">
             <el-tag v-if="r.row.IsExecute==true" type="success">已重试</el-tag>
             <el-tag v-else type="danger">未重试</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="CreateTime" label="失败时间" />
        <el-table-column prop="ActionUrl" label="请求路径" />
        <el-table-column prop="Request" :show-overflow-tooltip="true" label="请求内容"/>
      </el-table>
      <el-pagination
        :page-sizes="[10, 20, 40,100, 400]"
        :current-page="pagerDto.PageIndex"
        :page-size.sync="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @size-change="changePager"
        @current-change="pagerSerach"
      />
    </template>
  </base-list>
</template>
<script>
import { getPaperErroJobLogs,toPerform } from '@/api/job'
import BaseList from '@/components/Xyy/baselist'
export default {
  name: 'ErroJobLog',
  components: { 'base-list': BaseList },
  data() {
    return {
        multipleSelection: [],
        Ids:'',
      data: [], dataLoading: false,
      pagerDto: { _Eq_IsExecute:0,PageIndex: 0, PageSize: 10, total: 0, QuerySort: [
          { 'Field': 'IsExecute', 'IsDesc': false },
        { 'Field': 'CreateTime', 'IsDesc': false }
      ] },
      IsExecutes:[
        {
          value: 0,
          label: '未重试'
        }, {
          value: 1,
          label: '已重试'
        },
      ],
    }
  },
  mounted() {
    this.pagerSerach(1);
  },
  methods: {
      //重新执行
      toPerform(){
          if(this.Ids==''){ this.$message({type: 'warning', message: '请先勾选数据！' }); return false;}
           this.dataLoading = true
          toPerform(this.Ids).then(res => {
              this.$message({type: 'success', message: '已发出执行请求' });
              this.pagerSerach(1);
      }).finally(res => { this.dataLoading = false })
      },
      onSelection(s) {
      this.multipleSelection = s
      var idArry = []
      for (let i = 0; i < this.multipleSelection.length; i++) {
        idArry.push(this.multipleSelection[i].Id)
      }
      this.Ids = idArry.join(',')
    },
     rowCanSelect(row) {
      return row.IsExecute == 0
    },
    pagerSerach(index) {
      this.dataLoading = true
      if (index) {
        this.pagerDto.PageIndex = index
      }
      getPaperErroJobLogs(this.pagerDto).then(res => {
        this.data = res.Result
        this.pagerDto.total = res.TotalCount
      }).finally(res => { this.dataLoading = false })
    },
    changePager(v) {
      this.PageSize = v
      this.pagerSerach()
    }
  }
}
</script>
