<template>
  <base-list>
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="物流更新时间">
          <el-date-picker
            v-model="pagerDto._Range_TargetTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd hh:mm:ss"
          />
        </el-form-item>
        <el-button type="primary" @click="pagerSerach()"> 搜索 </el-button>
      </el-form>
    </template>
    <template slot="n_option">
      <el-button type="primary" @click="outExcel()"> 导出查询 </el-button>
    </template>
    <template>
      <el-table
        v-loading="dataLoading"
        :data="data"
        :highlight-current-row="true"
        :select-on-indeterminate="true"
        width="100%"
      >
        <el-table-column label="行运易单号" prop="SystemNo"/>
        <el-table-column label="跟踪单号" prop="TrackingNumber" />
        <el-table-column label="中转单号" prop="TransferNumber" />
        <el-table-column label="更新时间" prop="TargetTimeStr" />
      </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 BaseList from "@/components/Xyy/baselist";
import { _getPageResult,_down } from "@/api/tracking/onlinetrack";
export default {
  name: "Onlinetrack",
  components: { "base-list": BaseList },
  data() {
    return {
      row: {},
     downLoading:false,
      data: [],
      dataLoading: false,
      pagerDto: {
        PageIndex: 0,
        PageSize: 10,
        total: 0,
        _Range_TargetTime: [],
      },
    };
  },
  created() {
    var end = this.addDays(new Date(), 0);
    var start = this.addDays(end, -1);
    this.pagerDto._Range_TargetTime = [
      this.DateFormat(start, "yyyy-MM-dd hh:mm:ss"),
      this.DateFormat(end, "yyyy-MM-dd hh:mm:ss"),
    ];
    this.pagerSerach(1);
  },
  mounted() {},
  methods: {
    // 时间处理函数
    addDays(d, days) {
      var adjustDate = new Date(d.getTime() + 24 * 60 * 60 * 1000 * days);
      return adjustDate;
    },
    DateFormat(d, format) {
      var date = {
        "M+": d.getMonth() + 1,
        "d+": d.getDate(),
        "h+": d.getHours(),
        "m+": d.getMinutes(),
        "s+": d.getSeconds(),
        "q+": Math.floor((d.getMonth() + 3) / 3),
        "S+": d.getMilliseconds(),
      };
      if (/(y+)/i.test(format)) {
        format = format.replace(
          RegExp.$1,
          (d.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
      }
      for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
          format = format.replace(
            RegExp.$1,
            RegExp.$1.length == 1
              ? date[k]
              : ("00" + date[k]).substr(("" + date[k]).length)
          );
        }
      }
      return format;
    },
    outExcel(){
      _down(this.pagerDto);
    },
    pagerSerach(index) {
      if (
        this.pagerDto._Range_TargetTime == "" ||
        this.pagerDto._Range_TargetTime == null
      ) {
        this.$message({
          type: "info",
          message: "请选择更新时间！",
        });
        return false;
      }
      this.dataLoading = true;
      if (index) {
        this.pagerDto.PageIndex = index;
      } else {
        this.pagerDto.PageIndex = 1;
      }
      _getPageResult(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>
