<template>
  <div class="app-container">
    <div class="filter-container">
      <el-divider content-position="left">上传河南ESB订单</el-divider>
      <el-form label-position="left">
        <div class="itemGroup">
          <el-form-item label="提单号">
            <el-input v-model="loaddingNumber" />
          </el-form-item>
          <el-button @click="inputData">开始上传</el-button>
          <el-button @click="Refresh">查询最新状态</el-button>
        </div>
        <el-table :data="data">
          <el-table-column prop="TrackingNumber" label="运单号" />
          <el-table-column prop="ESBTrackingNumber" label="E速宝单号" />
          <el-table-column prop="Status" label="状态" />
          <el-table-column prop="Message" label="错误消息" />
        </el-table>
      </el-form>
    </div>
  </div>
</template>
<style >
    .itemGroup{
        margin: 10px;
        border: 1px solid #ebebeb;
        padding: 30px;
    }

</style>
<script>
import axios from 'axios'
import { getToken } from '@/utils/auth'
export default {
  name: 'InputESBOrder',
  data() {
    return {
      data: [],
      ladding: false,
      loaddingNumber: '',
      IsRefresh: false
    }
  },
  mounted() {
    // this.loaddingNumber = '272-72097815'
    // this.Refresh()
  },
  methods: {
    inputData() {
      if (this.IsRefresh) {
        this.$alert('还在处理中，无法重试')
        return
      } else {
        axios({
          method: 'post',
          url: 'http://120.24.149.148:9518/api/Order/AddZZEUBOrder?ladingNumber=' + this.loaddingNumber,
          headers: { 'Authorization': 'token ' + getToken(), 'Content-Type': 'application/json' }
        }).then(r => {
          this.$alert('已提交任务成功，请关注订单列表数据')
          this.Refresh()
        })
      }
    },
    Refresh() {
      axios({
        method: 'get',
        url: 'http://120.24.149.148:9518/api/Order/GetZZEUBOrder?ladingNumber=' + this.loaddingNumber,
        headers: { 'Authorization': 'token ' + getToken(), 'Content-Type': 'application/json' }
      }).then(r => {
        this.data = r.data.data
      }).catch(error => {
        var msg = (error.response.data.message || error.response.data.errors || error.response.data)
        this.$alert(msg, '错误', { type: 'warning' })
      })
    },
    inputESBOrders() {
      if (!this.loaddingNumber) {
        this.$alert('请录入提单号')
        return
      }
    }
  }
}
</script>
