<!--
 * @Author: ch
 * @Date: 2022-03-31 14:26:09
 * @LastEditors: ch
 * @LastEditTime: 2022-04-15 18:04:08
 * @Description: file content
-->
<template>
	<view>
		<StatusTips :orderInfo="orderInfo" @close="timerCloseOrder"></StatusTips>
		<UiWhiteBox>
			<UiGoodsInfo :class="index === orderInfo.products.length - 1 && 'goods-info__last'"
				v-for="(item, index) in orderInfo.products" :data="item" :key="index">
				<template slot="operation">
					<view class="goods-info-operation">
						<UiButton size="min" type="primaryLine" 
							@click="$Router.push(`/saleAfterSelect?id=${item.orderProductId}`)">申请售后</UiButton>
					</view>
				</template>
			</UiGoodsInfo>
		</UiWhiteBox>
		<LogisitcsInfo :logisitcsInfo="orderInfo.logistics" />
		<OrderInfo :orderInfo="orderInfo" />
		<Operation></Operation>
	</view>
</template>
<script>
import UiGoodsInfo from '../../../components/UiGoodsInfo.vue'
import UiWhiteBox from '../../../components/UiWhiteBox.vue'
import UiButton from '../../../components/UiButton.vue'
import {ApiGetOrderDetail, ApiPutCancelOrder} from '@/common/api/order'
import StatusTips from './components/StatusTips.vue'
import OrderInfo from './components/OrderInfo.vue'
import LogisitcsInfo from './components/LogisitcsInfo.vue'
import Operation from './components/Operation.vue'
export default {
	components: { UiGoodsInfo, UiWhiteBox, UiButton, StatusTips, OrderInfo, LogisitcsInfo, Operation },
	data(){
		return {
			orderInfo : {
				products:[]
			},
		}
	},
	onLoad(){
		this.getOrderInfo();
	},
	methods : {
		/**
		 * 获取订单最新信息
		 */
		async getOrderInfo(){
			const {error, result} = await ApiGetOrderDetail(this.$Route.query.id);
			if(error){
				uni.$u.totast(error.message);
				return false;
			}
			this.orderInfo = {...result};
		},
		/**
		 * 超时自动关闭订单
		 */
		timerCloseOrder(){
			this.orderInfo = {...this.orderInfo, orderStatus : 2, closeReason:'超时未支付'};
			this.getOrderInfo();
		}
		
	}
	
}
</script>
<style lang="scss" scoped>
page{
	background: $color-grey1;
	padding-bottom: 138rpx;
}
.goods-info-operation{
	padding-top: 30rpx;
	text-align: right;
}
.goods-info__last{
	border: 0;
}

</style>