<!-- OrderDetailBody.vue -->
<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
    <seller-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.order_state_text}}</text>
            </view>

            <view class="div address">
                <view class="div">
                    <text class="span mobile" v-if="order_info.virtual_type==0">接收手机：{{ order_info.buyer_phone }}</text>
					<view style="font-size:.7rem;display:flex;padding:0" class="mobile" v-if="order_info.virtual_type==1">
					<view style="padding:0" class="left">卡券：</view>
					<view style="padding:0;flex:1;" class="right">
					<view style="padding:0" v-for="(item ,index) in order_info.virtual_content" :key="index">
					{{ item }}
					</view>
					</view>
					</view>
					<text class="span mobile" v-if="order_info.virtual_type==2">网盘：{{ order_info.virtual_content }}</text>
					<text class="span mobile" v-if="order_info.virtual_type==3">下载：<text class="a" @click="downloadFile(order_info.vc_file_url)">下载资源</text></text>
                </view>
                <view v-if="order_info.virtual_type==0 && order_info.code_list.length" class="div vr_code">
                    <text class="span" v-for="(item ,index) in order_info.code_list" :key="index">
                        <text class="span">兑换码{{item.vr_code}}</text><br><text class="span state">{{item.vr_code_desc}}</text>
                    </text>
                </view>
            </view>

            <view
                    class="div containers"
            >

                <image
                        class="img photo"
                        v-bind:src="order_info.goods_image_url"
                />
                <view class="div right-wrapper">
                    <label class="title">{{ order_info.goods_name }}</label>
                    <label class="property">{{ order_info.goods_spec }}</label>
                    <view class="div desc-wrapper">
                        <view class="div">
                            <label class="price"
                            >￥ {{ order_info.goods_price }}</label
                            >
                            <label class="count">x{{ order_info.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.voucher_code">
                        使用了面额为 {{order_info.voucher_price}} 元的店铺代金券
                    </view>
                    <view class="p" v-if="order_info.mallvoucher_price">
                        使用了面额为 {{order_info.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" v-if="order_info.promotion && order_info.promotion.length > 0">
                    <label class="title">优惠</label>
                    <label class="subtitle" v-for="(p,i) in order_info.promotion" v-bind:key="i">{{p[1]}}}</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 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>
</seller-base>
</template>

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


import SellerBase from '../SellerBase'


import { getOrderInfo } from '../../../api/sellerVrOrder'
import flexLine from '../../flexLine'
export default {
  name: 'SellerOrderDetail',
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      screenWidth:0,
      order_info: {},
        rec_id:0,
        popupRefund:false,
    }
  },
components:{TitleHeader,SellerBase,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().height

    // #endif

    this.screenWidth=uni.getSystemInfoSync().screenWidth

  },

  methods:{
      showPopup(id){
        this.$refs[id].open()
      },
      hidePopup(id){
        this.$refs[id].close()
      },
      goBack(){uni.navigateBack({delta:1})},
      showRefund(rec_id){
          this.rec_id=rec_id
		  this.showPopup('popupRefund')
      },
      refund (type) {
          uni.navigateTo({url:'MemberReturnForm'+'?'+urlencode({type:type, order_id: this.order_info.order_id, order_goods_id: this.rec_id })})
      },
	
	downloadFile(url){
		uni.downloadFile({
			url,      //文件链接
			success:({statusCode,tempFIlePath})=>{
				//statusCode状态为200表示请求成功，tempFIlePath临时路径
				if(statusCode==200){
					//保存到本地
					uni.saveFile({
						tempFIlePath,
						success:(res)=>{
							 //res.savedFilePath文件的保存路径
							 //保存成功并打开文件
							 uni.openDocument({
								filePath:res.savedFilePath,
							})
						},
						fail:()=>uni.showToast({icon:'none',title: '保存失败'})
					})
				}
			},
			fail:()=>uni.showToast({icon:'none',title: '下载失败'})
		})
	},
    complaint (order_id, goods_id) {
      uni.navigateTo({url:'MemberComplaintForm'+'?'+urlencode({ order_id: order_id, goods_id: goods_id })})
    }
  }
}
</script>
<style lang="scss" scoped>
    .common-header-wrap .common-header{box-shadow: unset}
    .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.7rem;
        color: #333;
        font-size:$subFontSize;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .property {
        font-size:$subFontSize;
        color: #7c7f88;
        padding-top:0.5rem;
    }
    .count {
        margin-top:0.2rem;
        color: #7c7f88;
        font-size:$subFontSize;
        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;
    }
    .count {
        color: #7c7f88;
        font-size:$h2;
        margin-left:0.5rem;
    }
    .address {
        padding-bottom:0.5rem;
        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: 1.05rem;*/
            }
        }
        .p {
            margin:0.25rem 0.9rem 0.55rem 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.25rem;
            line-height: 2.25rem;
            .span {
                font-size:$h2;
                color: $primaryColor;
            }
        }
    }
    .ship {
        margin-bottom:0;
    }
    .vr_code > .span{border-top:1px solid #e1e1e1;display: block;padding-top:0.5rem;padding-bottom:0.5rem}
    .vr_code > .span:last-child{padding-bottom:0}
    .vr_code .state{font-size:$subFontSize;color:#7c7f88}
</style>


