<template>
<view id="order-detail">
    <view class="border-box">
        <view class="attention-box" v-if="detail.has_refund == 1">
            <span class="iconfont icon-warning"></span>
            订单正在售后中，待售后结束后结算佣金
        </view>
        <view class="order-item">
            <view class="title mx-1px-bottom">
                <view class="name">
                    订单状态
                </view>
                <view class="type" v-if="detail.has_refund == 0">
                    {{typeList[order.status]}}
                </view>
                <view class="type" v-if="detail.has_refund == 1">
                    售后中
                </view>
            </view>
            <view class="goods-item">
                <view class="item-middle">
                    <view class="middle-item mx-1px-bottom" :data-id="item.item_meta.detail_id" v-for="(item, index) in order.items" :key="index" @tap="jumpDetail">
                        <image :src="item.item_meta.image"></image>
                        <view class="text">
                            <view class="names">
                                {{item.item_name}}
                            </view>
                            <view class="model">
                                {{item.item_meta.specs_text}}
                            </view>
                        </view>
                        <view class="money-box">
                            <view>
                                {{item.quantity}}件
                            </view>
                            <view>
                                ￥{{item.units_total_yuan}}
                            </view>
                        </view>
                    </view>
                </view>
                <view class="item-bottom">
                    <view class="all-money">
                        {{order.count}}件, 共计 ￥{{order.items_total_yuan}}
                    </view>
                </view>
            </view>
        </view>
        <view class="item-add mx-1px-bottom">
            <view class="left-info">
                分销佣金：<span>¥ {{detail.commission}}</span>
            </view>
            <view class="right-info" v-if="detail.status == 0">待结算</view>
            <view class="right-info" v-if="detail.status == 1">已入账</view>
            <view class="right-info" v-if="detail.status == 2">已失效</view>
        </view>
        <view class="order-item">
            <view class="title mx-1px-bottom">
                订单信息
            </view>
            <view class="order-info">
                <view class="info-item">
                    <view class="name">
                        订单编号 :
                    </view>
                    <view class="text">{{detail.agent_order_no}}</view>
                </view>
                <view class="info-item">
                    <view class="name">
                        订单来源 :
                    </view>
                    <view class="text">官方商城</view>
                </view>
                <view class="info-item">
                    <view class="name">
                        支付方式 :
                    </view>
                    <view class="text">{{order.payment_text}}</view>
                </view>
                <view class="info-item">
                    <view class="name">
                        下单时间 :
                    </view>
                    <view class="text">{{order.submit_time}}</view>
                </view>
            </view>
        </view>
        <view class="order-item">
            <view class="title mx-1px-bottom">
                备注
            </view>
            <view class="order-info order-note">
                {{order.note || order.message || '暂无备注'}}
            </view>
        </view>
        <view class="pay-attention" v-if="detail.order_discount || detail.order_counpon || order.redeem_point">*此订单使用了
           <block v-if="detail.order_discount">促销活动</block><block v-if="detail.order_discount && detail.order_counpon">和</block><block v-if="detail.order_counpon">优惠券</block> <block v-if="detail.order_counpon && order.redeem_point"></block><block v-if="order.redeem_point">积分</block>
            </view>
    </view>
</view>
</template>
<script>

import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
import countdown from "@/components/Countdown/Countdown";

export default {
  data() {
    return {
      order: {},
      detail: {},
      typeList: {
        0: '临时订单',
        1: '待付款',
        2: '付款成功',
        3: '已发货',
        4: '已完成',
        5: '已完成',
        6: '已取消',
        7: '已退款',
        8: '已作废',
        9: '已删除',
        31: '部分已发货'
      },
      refundStatus: ['待审核', '审核通过', '拒绝申请', '已完成', '已关闭', '等待买家退货', '买家已退货', '等待商城发货'],
      muStatus: ['待成团', '已成团', '拼团失败'],
      norder_no: '',
      config: ''
    };
  },

  onLoad(e) {
    // 第三方平台配置颜色
    var bgConfig = this.$cookieStorage.get('globalConfig') || '';
    this.setData({
      config: bgConfig
    });
    this.setData({
      norder_no: e.order_no
    });
  },

  onShow() {
    wx.showLoading({
      title: "加载中",
      mask: true
    });
    this.queryOrderDetail(this.norder_no);
  },

  components: {
    countdown
  },
  props: {},
  methods: {
    jump() {
      wx.navigateTo({
        url: '/pages/store/collage/collage?multi_groupon_item_id=' + this.order.multi_groupon_users[0].multi_groupon_items_id
      });
    },

    jumpDetail(e) {
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/store/detail/detail?id=' + id
      });
    },

    // 获取订单详情
    queryOrderDetail(orderNo) {
      var token = this.$cookieStorage.get('user_token');
      this.$http.get({
        api: 'api/distribution/order/detail/' + orderNo,
        header: {
          Authorization: token
        }
      }).then(res => {
        if (res.statusCode = 200) {
          res = res.data;
          this.setData({
            detail: res.data,
            order: res.data.order
          });
        } else {
          wx.showModal({
            title: '',
            content: '请求失败，请稍后重试'
          });
        }

        wx.hideLoading();
      }).catch(rej => {
        wx.showModal({
          title: '',
          content: '请求失败，请稍后重试'
        });
        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 "pusherOrder";
</style>