<template>
  <div class="order-path">
    <PathMap
      :pathList="pathList"
    />
  </div>
</template>

<script>
import PathMap from '../../components/PathMap'
export default {
  components: { PathMap },
  created () {
    // 获取url中的订单号和类型
    this.orderNo = this.$utils.url.getQueryString('orderNo')
    this.type = this.$utils.url.getQueryString('type')
    // 路由获取上页订单号
    !this.orderNo && (this.orderNo = this.$route.params.orderNo)
    !this.type && (this.type = this.$route.params.type)
    if (this.pathList.length) {
      this.type === 'DISPATCH' && (this.pathList = [this.pathList[1]])
    }
    document.title = '实时路径'
    // alert(`
    // url = ${window.location.href}
    // orderNo = ${this.orderNo}
    // type = ${this.type}
    // `)
  },
  mounted () {
    this.getOrderPath()
  },

  data () {
    return {
      orderNo: '', // 物流订单号
      type: '', // 类型
      pathList: [], // 路径数据
    }
  },
  methods: {
    // 获取订单实时路径
    getOrderPath () {
      const url = this.$API.businessPages.logisticsInfo.getOrderPath
      const param = {
        orderNo: this.orderNo,
        type: this.type,
      }
      const config = {
        headers: { 'Content-Type': 'application/json' },
        transformRequest: [],
      }
      this.$https.post(url, param, config)
        .then(data => {
          if (data.succeed) {
            this.pathList = data.data
          } else {
            this.$toast(data.errorMsg)
          }
        })
    },
  },
}
</script>

<style lang="scss" scoped>
.order-path {
  width: 100%;
  height: 100%;
}
</style>
