<template>
  <!-- #ifdef H5 -->
  <view>
    <Loading
    	:type="3"
    	:loadStatus="loadStatus"
    	:showText="errorText"
    />
    <zj-page-layout
      v-if="detail"
    	:hasFooter="true"
    	:isScroll="true"
    	:refresherTriggered="refresherTriggered"
    	@refresherrefresh="refresherrefresh">

      <view class="address-container">
        <view class="icon"><text class="iconfont icon-dingwei1"></text></view>
        <view class="hasdata">
          <view class="name">{{detail.userName}}<text>{{detail.phone}}</text></view>
          <view class="address ellipsis-2">{{detail.address}}</view>
        </view>
      </view>

      <view class="goods-container">
        <view class="title">商品信息</view>
        <view class="goods">
          <image :src="imageUrl + detail.goodsPicUrl"></image>
          <view class="main">
            <view class="name">{{detail.goodsTitle}}</view>
            <view class="des">{{detail.content}}</view>
            <view class="price"><text>{{detail.goodsAmount | priceFilter2}}</text>数量：{{detail.num}}</view>
          </view>
        </view>
        <view class="total">订单总金额<text>{{detail.price | priceFilter2}}</text></view>
      </view>

      <view class="order-container">
        <view class="title">订单信息</view>
        <view class="row">订单编号：{{detail.orderId}}</view>
        <view class="row">创建时间：{{detail.createTime}}</view>
        <view class="row">付款时间：{{detail.payTime}}</view>
        <view class="row">支付方式：{{detail.payType | payTypeFilter}}</view>
        <view class="row">支付单号：{{detail.transactionId}}</view>
        <view class="row">发货时间：{{detail.logisticsTime}}</view>
        <view class="row">收货时间：{{detail.completeTime}}</view>
      </view>

      <template slot="footer">
        <view class="bottom-container">
          <u-button text="取消订单" shape="circle"></u-button>
        </view>
      </template>

    </zj-page-layout>
  </view>
  <!-- #endif -->
  <!-- #ifndef H5 -->
  <web-view :src="webViewHref('/pages/mine/myBuy/detail', pam)"></web-view>
  <!-- #endif -->
</template>

<script>
  // #ifdef H5
  export default {
    filters: {
      payTypeFilter(val) {
        const MAP = {
          WECHAT: '微信支付'
        }
        return MAP[val];
      }
    },

    data() {
      return {
        id: null,
        detail: null,
        imageUrl: this.$imageUrl,
        loadStatus: 0,
				errorText: '',
        refresherTriggered: false,
      }
    },

    onLoad({id}) {
      this.id = id;
      this.getDetail();
    },

    methods: {
      getDetail() {
        this.$api.post('/orderPay/detail', {
          orderId: this.id
        }).then(res => {
					this.detail = res.data;
					this.loadStatus = 0;
					this.getLogisticsData();
				}).catch(res => {
					this.errorText = res.message;
					this.loadStatus = 2;
				}).finally(res => {
					this.refresherTriggered = false;
				})
      }
    }
  }
  // #endif
  // #ifndef H5
  export default {
    data() {
      return {
        pam: {},
      }
    },
  
    onLoad(pam) {
      this.pam = pam;
    },
  }
  // #endif
</script>

<style lang="scss" scoped>
.address-container {
  background: #FFFFFF;
  display: flex;
  align-items: center;
  height: 150rpx;
  padding: 0 20rpx;
  margin-top: 30rpx;
  .icon {
    width: 52rpx;
    height: 52rpx;
    border-radius: 50%;
    background: $theme-color;
    display: flex;
    flex-shrink: 0;
    justify-content: center;
    align-items: center;
    margin-right: 20rpx;
    .iconfont {
      font-size: 36rpx;
      color: #ffffff;
    }
  }
  .hasdata {
    .name {
      font-size: 32rpx;
      color: #333333;
      text {
        color: #999999;
        font-size: 28rpx;
        margin-left: 16rpx;
      }
    }
    .address {
      font-size: 28rpx;
      color: #666666;
      line-height: 34rpx;
      margin-top: 10rpx;
    }
  }
}

.goods-container {
  background: #ffffff;
  margin-top: 30rpx;
  padding: 30rpx 30rpx 0;
  .title {
    font-weight: 500;
  }
  .goods {
    display: flex;
    padding: 30rpx 0;
    image {
      width: 120rpx;
      height: 120rpx;
    }
    .main {
      flex: 1;
      margin-left: 20rpx;
      .name {
        font-size: 32rpx;
      }
      .des {
        margin-top: 12rpx;
        font-size: 28rpx;
        color: $reg-font;
      }
      .price {
        margin-top: 12rpx;
      	text {
      		color: $assist-color;
      		font-weight: 500;
      		font-size: 32rpx;
          margin-right: 12rpx;
      	}
      }
    }
  }
  .total {
    border-top: 1px solid #eaeaea;
    height: 80rpx;
    display: flex;
    align-items: center;
    justify-content: end;
    font-size: 28rpx;
    text {
      margin-left: 12rpx;
      color: $assist-color;
    }
  }
}

.order-container {
  background: #ffffff;
  margin-top: 30rpx;
  padding: 30rpx;
  .title {
    font-weight: 500;
    margin-bottom: 20rpx;
  }
  .row {
    margin-top: 12rpx;
    font-size: 28rpx;
    text {
      color: $assist-color;
    }
  }
}

.bottom-container {
  padding: 20rpx 30rpx;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  .u-button {
    width: auto;
    height: 60rpx;
    margin: 0;
    margin-left: 20rpx;
  }
}

</style>
