<template>
  <div>
    <el-card shadow="never" style="margin-bottom: 20px">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="跟踪单号">
          <el-input v-model="pagerDto._Eq_TrackingNumber" />
        </el-form-item>
        <el-form-item>
          <el-button @click="serarch()" type="primary" :loading="dataLoading"
            >查询</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            :loading="dataLoading"
            @click="RestartTrace()"
            >重启跟踪</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
    <el-card shadow="never" style="margin-bottom: 20px">
      <el-table
        :data="logs"
        :highlight-current-row="true"
        :select-on-indeterminate="true"
        width="100%"
        :height="570"
        border
        @selection-change="onSelection"
      >
        <el-table-column
          key="TrackingNumber"
          prop="TrackingNumber"
          type="selection"
        />
        <el-table-column label="跟踪单号" prop="TrackingNumber" width="200" />
        <el-table-column label="发货时间" prop="DeliveryTime" width="200">
          <template slot-scope="r">
            {{ r.row.DeliveryTime.replace("T", " ").substring(0, 19) }}
          </template>
        </el-table-column>
        <el-table-column
          label="重启跟踪时间"
          prop="RestartTraceTime"
          width="200"
        >
          <template slot-scope="r">
            {{ r.row.RestartTraceTime!=null?r.row.RestartTraceTime.replace("T", " ").substring(0, 19):"" }}
          </template>
        </el-table-column>
        <el-table-column label="重启结果" prop="RestartTraceMessage" />
      </el-table>
      <el-pagination
        :page-sizes="[20, 50, 100, 200]"
        :current-page="pagerDto.PageIndex"
        :page-size="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @current-change="serarch"
      />
    </el-card>
  </div>
</template>
<script>
import { GetWaitRestartTracePage, RestartTrace } from "@/api/esb";
export default {
  name: "WaitRestartTrace", //等待重启跟踪数据
  data() {
    return {
      logs: [],
      dataLoading: false,
      selectIds: [],
      pagerDto: {
        _Eq_TrackingNumber: "",
        PageIndex: 1,
        PageSize: 20,
        total: 0,
      },
    };
  },
  methods: {
    onSelection(s) {
      var ids = [];
      for (let i = 0; i < s.length; i++) {
        ids.push(s[i].TrackingNumber);
      }
      this.selectIds = ids;
    },
    RestartTrace() {
      if (this.selectIds == null || this.selectIds.length == 0) {
        this.$message({ type: "error", message: "请选择需要重启推送的单号！" });
        return false;
      }
      this.dataLoading = true;
      RestartTrace(this.selectIds)
        .then((r) => {
          this.serarch(0);
        })
        .finally((res) => {
          this.dataLoading = false;
        });
    },
    serarch(index) {
      if (index > 0) this.pagerDto.PageIndex = index;
      this.dataLoading = true;
      GetWaitRestartTracePage(this.pagerDto)
        .then((r) => {
          this.logs = r.Result;
          this.pagerDto.total = r.TotalCount;
        })
        .finally((res) => {
          this.dataLoading = false;
        });
    },
  },
};
</script>