<template>
<view id="express">

    <view class="title">
        <view class="name">
            {{name || '其他快递'}}
        </view>
        <view class="no">
            {{no}}
        </view>
    </view>

    <view class="box mx-1px-left" v-if="init && info && info.length">
        <view class="item" v-for="(item, index) in info" :key="index">
            <view class="dot">

            </view>
            <view class="text">
                <view class="info">
                    {{item.context}}
                </view>
                <view class="time">
                   {{item.time}}
                </view>
            </view>

        </view>
    </view>
    <view class="no-data" v-if="init && !info">
        暂无物流信息
    </view>
</view>
</template>
<script>
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';

export default {
  data() {
    return {
      info: '',
      name: '',
      no: '',
      init: false
    };
  },

  onLoad(e) {
    if (e.no) {
      this.setData({
        no: e.no,
        name: e.name
      });
      this.getExpress(e.no);
    } else {
      wx.showModal({
        content: '无物流编号',
        showCancel: false
      });
    }
  },

  components: {},
  props: {},
  methods: {
    getExpress(no) {
      var token = this.$cookieStorage.get('user_token');
      wx.showLoading({
        title: '查询中',
        mask: true
      });
      this.$http.get({
        api: 'api/express/query',
        data: {
          no: no
        },
        header: {
          Authorization: token
        }
      }).then(res => {
        if (res.statusCode == 200) {
          res = res.data;

          if (res.data) {
            this.setData({
              info: res.data,
              init: true
            });
          } else {
            wx.showModal({
              content: res.message || '请求失败',
              showCancel: false
            });
          }
        } else {
          wx.showModal({
            content: '请求失败',
            showCancel: false
          });
        }

        wx.hideLoading();
      }).catch(err => {
        wx.showModal({
          content: '请求失败',
          showCancel: false
        });
        wx.hideLoading();
      });
    },

    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  },
  computed: {},
  watch: {}
};
</script>
<style rel="stylesheet/less" lang="less">
    @import "express";
</style>
