<template>
	<view class="container">
		<view v-for="(item,index) in hireOrderList" :key="index" @tap="loadToNav" :data-orderSn="item.order_sn"
			class="order-card">
			<view class="card-top flex-row">
				<view>{{item.car_model}}</view>
				<view class="card card-k" v-if="item.order_status == 0">待支付</view>
				<view class="card card-k" v-else-if="item.order_status == 1">待取车</view>
				<view class="card card-k" v-else-if="item.order_status == 2">待激活</view>
				<view class="card card-b" v-else-if="item.order_status == 3">使用中</view>
				<view class="card card-r" v-else-if="item.order_status == 4">已逾期</view>
				<view class="card card-k" v-else-if="item.order_status == 5">还车申请中</view>
				<view class="card card-k" v-else-if="item.order_status == 6">还车中</view>
				<view class="card card-k" v-else-if="item.order_status == 7">车辆已归还</view>
				<view class="card card-k" v-else-if="item.order_status == 8||item.order_status == 9">已取消</view>
			</view>
			<view class="card-border"></view>
			<view class="card-bottom">
				<view class="bottom-item flex-row">
					<view class="item-left flex-row">
						<view>下单时间</view>
						<view>租用时长</view>
						<view v-if="item.order_status == 3">剩余租期</view>
					</view>
					<view class="item-right">
						<view>{{tools.formatTime(item.ctime)}}</view>
						<view>
							{{item.hire_duration_time.day > 0 ? item.hire_duration_time.day :'' }}<text
								v-if="item.hire_duration_time.day>0">日</text>{{item.hire_duration_time.hour > 0 ? item.hire_duration_time.hour :'' }}<text
								v-if="item.hire_duration_time.hour>0">小时</text>{{item.hire_duration_time.minute > 0 ? item.hire_duration_time.minute :'' }}<text
								v-if="item.hire_duration_time.minute>0">分</text>
						</view>
						<view v-if="item.order_status == 3">
							{{item.order_time.day > 0 ? item.order_time.day :'' }}<text
								v-if="item.order_time.day>0">日</text>{{item.order_time.hour > 0 ? item.order_time.hour :'' }}<text
								v-if="item.order_time.hour>0">小时</text>{{item.order_time.minute > 0 ? item.order_time.minute :'' }}<text
								v-if="item.order_time.minute>0">分</text>
							<!-- hire_end_time -当前时间 -->
						</view>
					</view>
				</view>
				<view class="bottom-price flex-row">
					订单金额
					<!-- <view class="price-text">￥<text>{{((item.money-0) + (item.deposit-0) + (item.insurance-0)) / 100}}</text></view> -->
					<view class="price-text">
						￥<text>{{item.money / 100}}</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script module="tools" lang="wxs" src="@/pages/common/wxs/tools.wxs"></script>
<script module="tools" lang="sjs" src="@/pages/common/wxs/tools.sjs"></script>
<script>
	var config = require('../../common/config.js');
	var common = require('../../common/common.js');
	var http = require('../../common/http.js');
	var storage = require('../../common/storage.js');
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				status: '-1',
				sort_time: 0,
				sort_num: 0,
				hireOrderList: [],
				order_sn: '',
				myLocation: {
					latitude: null,
					longitude: null
				},
				orderInfoTime: {},
				nowTime: 0
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			const locationStr = uni.getStorageSync('user_current_location');
			if (locationStr) {
				this.myLocation = locationStr;
			}
			let timestamp = Date.now();
			this.nowTime = Math.floor(timestamp / 1000);
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this.hireOrderList = []
			this.sort_time = 0
			this.bindHireOrderList()
		},
		
		// 分享给好友
		onShareAppMessage: function(res) { //发送给朋友
			return {
				title: this.appConfig.app_name,
				path: 'pages/order/order',
			}
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.page++
			this.bindHireOrderList()
		},
		/**
		 * 页面下拉触底事件的处理函数
		 */
		onPullDownRefresh() {
			this.page = 1
			this.bindHireOrderList()
		},
		methods: {
			bindHireOrderList() {
				const me = this
				http.postApi(config.API_DAYHIRE_HIRE_ORDER_LIST, {
					page: me.page,
					limit: me.limit,
					status: me.status,
					sort_time: me.sort_time,
					sort_num: me.sort_num
				}, (resp) => {
					if (resp.data.code === 200) {
						// me.hireOrderList = resp.data.data.list
						me.hireOrderList.push.apply(me.hireOrderList, resp.data.data.list)
						if (me.hireOrderList.length > 0) {
							me.sort_time = me.hireOrderList[me.hireOrderList.length - 1].ctime;
							me.sort_num = me.hireOrderList[me.hireOrderList.length - 1].sort_num;
							// timeToDay
							me.hireOrderList = me.hireOrderList.map(item => {
								item.order_time = common.getTimeToDay(Math.ceil(item.hire_end_time - me.nowTime)/60)
								item.hire_duration_time = common.getTimeToDay(Math.ceil(item.hire_end_time - item.hire_begin_time)/60)
								return item
							})
						}
					} else {
						common.simpleToast(resp.data.msg)
					}
				})
			},

			navToPage(e) {
				const url = e.currentTarget.dataset.url;
				if (!url) {
					return;
				}
				uni.navigateTo({
					url: url
				});
			},

			loadToNav(e) {
				//#ifdef MP-ALIPAY
				this.order_sn = e.currentTarget.dataset.orderSn
				//#endif
				//#ifdef MP-WEIXIN
				this.order_sn = e.currentTarget.dataset.ordersn
				//#endif
				const isJumpReturn = false
				uni.navigateTo({
					url: '/pages/orderStatus/orderStatus?order_sn=' + this.order_sn + '&longitude=' + this
						.myLocation.longitude + '&latitude=' + this.myLocation.latitude +'&isJumpReturn=' + isJumpReturn,
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
			},
		}
	};
</script>

<style>
	@import './order.css';
</style>