<!-- OrderDetailBody.vue -->
<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
    <member-base :show="false"><view class="div">
        <view class="div common-header-wrap">
            <view :style="'height:'+navHeight+'px'"></view>
            <view class="common-header-holder"></view>
            <view class="common-header-fixed">
            <title-header />
            <uni-nav-bar title="订单详情" class="common-header" left-icon="back" @clickLeft="goBack()">
            </uni-nav-bar>
        </view>
        </view>
        <view
                class="div order-body"
                v-if="order_info"
        >
            <view class="div order_state">
                <text class="i iconfont" v-if="order_info.order_state == '40'">&#xe61b;</text>
                <text class="i iconfont" v-else>&#xe61a;</text>
                <text class="span">{{order_info.state_desc}}</text>
                <view class="div pickup-code" v-if="order_info.order_state == '35'">（取货码{{order_info.chain_order_pickup_code}}）</view>
            </view>

            <view class="div address">
                <view class="div">
                    <text class="span">{{ order_info.reciver_name }}</text>
                    <text class="span mobile">{{ order_info.reciver_phone }}</text>
                </view>
                <view class="p" style="-webkit-box-orient: vertical; -webkit-line-clamp: 2;">
                    {{ order_info.reciver_addr }}
                </view>
            </view>

            <view class="div order_store" v-if="order_info.extend_store" @click="goNavigate('/pages/home/storedetail/Storedetail',{ 'id': order_info.extend_store.store_id })">
                <text class="i store iconfont">&#xe62d;</text><text class="span">{{order_info.extend_store.store_name}}</text><text class="i more iconfont">&#xe650;</text>
            </view>

            <view
                    class="div containers"
                    v-for="item in order_info.goods_list"
                    v-bind:key="item.goods_id"
					@click="goNavigate('/pages/home/goodsdetail/Goodsdetail',{goods_id:item.goods_id})"
            >

                <image mode="aspectFit"
                        class="img photo"
                        v-bind:src="item.image_url"
                />
                <view class="div right-wrapper">
                    <label class="title">{{ item.goods_name }}</label>
                    <label class="property">{{ item.goods_spec }}</label>
                    <view class="div desc-wrapper">
                        <view class="div">
                            <label class="price"
                            >￥ {{ item.goods_price }}</label
                            >
                            <label class="count">x{{ item.goods_num }}</label>
                        </view>
                        <view class="div btn-list">
                            <view v-if="order_info.if_complain" class="div common-btn ds-button-small default" @click.stop="complaint(order_info.order_id,item.rec_id)">投诉</view>
                            <view v-if="item.refund=='1'" class="div common-btn ds-button-small default" @click.stop="showRefund(item.rec_id)">售后</view>
                            <view v-if="item.extend_refund && !(item.extend_refund.refund_state==3 || item.extend_refund.refund_state==4)" class="div common-btn ds-button-small default" @click.stop="goRefund(item.extend_refund)">售后</view>
                        </view>
                    </view>
                </view>
            </view>
            <view
                    v-if="order_info.zengpin_list"
                    class="div containers"
                    v-for="item in order_info.zengpin_list"
                    v-bind:key="item.goods_id"
            >

                <image mode="aspectFit"
                        class="img photo"
                        v-bind:src="item.image_url"
                />
                <view class="div right-wrapper">
                    <label class="title"><text class="span tag-icon">赠品</text>{{ item.goods_name }}</label>
                    <label class="property">{{ item.goods_spec }}</label>
                    <view class="div desc-wrapper">
                        <view class="div">
                            <label class="price"
                            >￥ {{ item.goods_price }}</label
                            >
                            <label class="count">x{{ item.goods_num }}</label>
                        </view>
                    </view>
                </view>
            </view>

            <view class="div detail">
                <view class="div number">
                    <label
                    >订单编号：{{ order_info.order_sn }}
                    </label>
                    <view class="p">
                        下单时间：{{order_info.add_time}}
                    </view>
                </view>
                <view class="div number">
                    <view class="p" v-if="order_info.promotion && order_info.promotion.length">
                      {{order_info.promotion}}
                    </view>
                    <view class="p" v-if="order_info.voucher_code">
                        使用了面额为 {{order_info.voucher_price}} 元的店铺代金券
                    </view>
                    <view class="p" v-if="order_info.extend_order_common.mallvoucher_price">
                        使用了面额为 {{order_info.extend_order_common.mallvoucher_price}} 元的平台代金券
                    </view>
                </view>
                <view class="div pay" v-if="order_info.payment_name">
                    <view class="p">支付方式：{{ order_info.payment_name }}</view>
                </view>

            </view>

            <view
                    class="div desc section-header section-footer"
            >
                <view class="div container">
                    <label class="title">商品总额</label>
                    <label class="subtitle">￥{{ order_info.goods_amount }}</label>
                </view>
                <view class="div container">
                    <label class="title">运费</label>
                    <label class="subtitle">￥{{ order_info.shipping_fee }}</label>
                </view>
                <label class="amount"
                >实付款 : <text class="span"> ￥{{ order_info.order_amount }}</text>
                </label>
            </view>

        </view>

        <uni-popup background-color="#fff" ref="popupRefund" type="right" >
            <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
            <view class="div common-header-wrap">
                <view :style="'height:'+navHeight+'px'"></view>
                <view class="common-header-holder"></view>
                <view class="common-header-fixed">
                <title-header />
                <uni-nav-bar title="售后" class="common-header" left-icon="back" @clickLeft="hidePopup('popupRefund')">
                </uni-nav-bar>
            </view>
            </view>
            <view class="div common-popup-content ">
				<scroll-view class='main-content' style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
                <view class="div" @click='refund(1)'><flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">退款</text></flex-line></view>
                <view class="div" @click='refund(2)'><flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">退货</text></flex-line></view>
				</scroll-view>
			</view>
        </view>
        </uni-popup>
    </view></member-base>
</template>

<script>
import {getFontSize} from '@/util/common'

import TitleHeader from '../../TitleHeader'

import { urlencode } from '@/util/common'

import MemberBase from '../MemberBase'
import { getOrderInfo } from '../../../api/memberOrder'
import flexLine from '../../flexLine'
export default {
  name:'MemberOrderDetail',
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      screenWidth:0,
      order_info: {},
      rec_id: 0,
    }
  },
  components:{
    TitleHeader,
    MemberBase,
    flexLine
  },

  onLoad: function (option) {
    if (option.order_id) {
      getOrderInfo(option.order_id).then(res => {
        this.order_info = res.result.order_info
      }).catch(function (error) {
        uni.showToast({icon:'none',title: error.message})
      })
    }
  },
  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().top
    // #endif
    this.screenWidth=uni.getSystemInfoSync().screenWidth
  },

  methods:{
    goNavigate(path,query=false){
      uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
    },

    showPopup(id){
      this.$refs[id].open()
    },
    hidePopup(id){
      this.$refs[id].close()
    },
    goBack(){uni.navigateBack({delta:1})},
    goRefund(refund){
      if(refund.return_type==1){
        uni.navigateTo({ url: '/pages/member/refund/RefundView'+'?'+urlencode( { refund_id: refund.refund_id } )})
      }else{
        uni.navigateTo({ url: '/pages/member/return/ReturnView'+'?'+urlencode( { refund_id: refund.refund_id } )})
      }
    },
    showRefund (rec_id) {
      this.rec_id = rec_id
      this.showPopup('popupRefund')
    },
    refund (type) {
      uni.navigateTo({ url: '/pages/member/return/ReturnForm'+'?'+urlencode( { type: type, order_id: this.order_info.order_id, order_goods_id: this.rec_id } )})
    },

    complaint (order_id, goods_id) {
      uni.navigateTo({ url: '/pages/member/complaint/ComplaintForm'+'?'+urlencode( { order_id: order_id, goods_id: goods_id } )})
    }
  }
}
</script>
<style lang="scss" scoped>
    .common-header-wrap .common-header{box-shadow: unset}
    .common-popup-content .main-content{padding:0 $pageSpace;box-sizing: border-box}
    .order-body {
        overflow: auto;
        height: 100%;
        position: absolute;
        width: 100%;
        .desc{
            .container {
                display: flex;
                flex-direction: row;
                justify-content: flex-start;
                align-items: center;
                background-color: #fff;
            }
            .title {
                width:5rem;
                font-size:$subFontSize;
                color: #333;
                margin-left:0.6rem;
            }
            .subtitle {
                flex: 1;
                margin-left:1rem;
                margin-right:0.6rem;
                color: $primaryColor;
                font-size:$subFontSize;
                text-align: right;
            }
        }

    }
    .order_state {
        background:$primaryColor;
        height:3.5rem;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        .i {
            color:#fff;
            font-size:1.2rem;
            padding: 0 0.5rem;
        }
        .span {
            font-size:$h2;
            color: #fff;
        }
    }
    .containers {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: stretch;
        background-color: #fff;
        border-bottom: 1px solid #e8eaed;
    }
    .photo {
        width:4rem;
        height:4rem;
        margin:0.75rem 0.5rem 0.75rem 0.75rem;
        border: 1px solid #e8eaed;
        flex-basis:4rem;
        flex-shrink: 0;
    }
    .right-wrapper {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 0 0.75rem 0 0;
        width: 100%;
        overflow: hidden;
    }
    .title {
        margin-top:0.75rem;
        color: #333;
        font-size:$subFontSize;

        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .property {
        font-size:$fontSize;
        color: #7c7f88;
        padding-top:0.5rem;
    }
    .count {
        margin-top:0.2rem;
        color: #7c7f88;
        font-size:$fontSize;
        margin-right:0.5rem;
    }
    .desc-wrapper {
        height:1rem;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding-top:1rem;
    }
    .price {
        color: $primaryColor;
        font-size:$h2;
        margin-left: 0;
    }
	.btn-list{
		display: flex;
	}
	.ds-button-small.default{
		margin: 0 .1rem;
	}
    .count {
        color: #7c7f88;
        font-size:$h2;
        margin-left:0.5rem;
    }
    .address {
        height:4.4rem;
        background-color: #fff;
        margin-bottom:0.5rem;
        .div {
            padding: 0.5rem 0.5rem 0;
        }
        .img {
            height:0.8rem;
        }
        .span {
            color: #333;
            font-size:$h2;
            &.mobile {
                padding-left:1rem;
            }
        }
        .p {
            margin:0.25rem 0.9rem 0.5rem 0.5rem;
            font-size:$subFontSize;
            color: #7c7f88;

            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
        }
    }

    .contact {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        height:2.3rem;
        background-color: #fff;
        margin-top:0.4rem;
        border-bottom: 1px solid #e8eaed;
        padding: 0 0.65rem;
        .span {
            font-size:$fontSize;
            color: #333;
            padding-right:0.3rem;
        }
        .img {
            width:0.6rem;
            height: 0.65rem;
        }
    }

    .detail {
        display: flex;
        flex-direction: column;
        font-size:$subFontSize;
        color: #7c7f88;
        background-color: #fff;
        margin:0.4rem 0;
        box-sizing: border-box;
        .number {
            padding:0.7rem 0.8rem;
            border-bottom: 1px solid #e8eaed;
            .p {
                padding-top:0.3rem;
                font-size:$subFontSize;
            }
            .button {
                color: #7c7f88;
                height:1rem;
                background-color: #fff;
                border: 1px solid #7c7f88;
                width:2.7rem;
                height:1rem;
                border-radius:0.1rem;
                font-size:$subFontSize;
                display:flex;align-items:center;justify-content:center;
            }
        }
        .pay {
            border-bottom: 1px solid #e8eaed;
            padding:0.7rem 0.8rem;
        }
        .givetime {
            padding:0.7rem 0.8rem;
            font-size:$subFontSize;
        }
        input {
            background-color: #fff;
            border: 1px solid #7c7f88;
        }
    }
    .desc {
        background-color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding-top:0.6rem;
        box-sizing: border-box;
        margin-bottom:4rem;
        .desc-item {
            flex: 1;
            margin-top:0.5rem;
        }
        .amount {
            display: flex;
            justify-content: flex-end;
            font-size:$subFontSize;
            color: #333;
            padding-right:0.75rem;
            border-top: 1px solid #e8eaed;
            margin-top:0.6rem;
            height:2.2rem;
            line-height:2.2rem;
            .span {
                font-size:$h2;
                color: $primaryColor;
            }
        }
    }
    .ship {
        margin-bottom: 0;
    }
    .order_store{background:#fff;height:1rem;line-height:1rem;padding:0.5rem 0.8rem;border-bottom:1px solid #f5f5f5}
    .order_store .span{color:#333;font-size:$subFontSize;font-weight:600;float:left;margin:0 0.4rem;}
    .order_store .i.store{float:left}
    .order_store .i.more{float:left;font-size:$subFontSize;}
    .pickup-code{font-size:$fontSize;color:#fff}
</style>
