<template>
	<view class="web_box">
		<!-- <u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="我的订单" @leftClick="leftClick" bgColor="#fff">
		</u-navbar> -->
		<view class="list" v-if="orderList.length > 0">
			<block v-for="(item,index) in orderList" :key="index">
				<view class="list_item" @click="toDetail(index)">
					<view class="hflex acenter jbetween">
						<view class="order_id">订单编号：{{item.order_no}}</view>
						<view class="order_state" v-if="item.status == 0">等待买家付款</view>
					</view>
					<view class="hflex acenter" style="padding-top: 10rpx;">
						<image :src="item.course_info.img" mode="widthFix" style="width: 322rpx;border-radius: 16rpx;"></image>
						<view class="img_right">
							<view class="title">{{item.course_info.name}}</view>
							<view class="text_style1">总学时：{{item.period}}学时</view>
							<view class="text_style1">讲师：{{item.course_info.lecturer}}</view>
							<view class="hflex acenter jbetween" v-if="item.status == 0">
								<view class="order_price">￥{{item.course_info.price}}</view>
								<u-button @tap.stop="toPay(index)">继续付款</u-button>
							</view>
							<view class="hflex acenter jbetween" v-else>
								<view v-if="item.is_invoice == 0" class="order_apply" @tap.stop="toApply(index)">申请发票</view>
								<view v-if="item.is_invoice == 1" class="order_apply" @tap.stop="applyDetail(index)">发票详情</view>
								<u-button @tap.stop="toStudy(item.course_id)">前往学习</u-button>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="list vflex acenter jcenter" v-else>
			<image src="../../../static/images/common/order_none.png" class="img_none"></image>
			<view class="text_none">
				暂无订单
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				orderList: [],
				page: 1,
				limit: 10,
				total: 0
			}
		},
		onLoad() {
			this.getOrderList()
		},
		methods: {
			leftClick() {
				$api.jump('/pages/mine/mine',3)
			},
			// 获取订单列表
			getOrderList() {
				var that = this
				$api.req({
					url: '/api/User/myOrder',
					data: {
						page: that.page,
						limit: that.limit
					}
				}, function(res) {
					console.log(res);
					if (res.code == 1) {
						if (that.page == 1) {
							that.orderList = res.data.list
							that.total = res.data.count
						}else {
							that.orderList = that.orderList.concat(res.data.list)
							that.total = res.data.count
						}
					}
				})
			},
			// 继续付款
			toPay(index) {
				$api.jump('/pages/index/course/buy?order_no=' + this.orderList[index].order_no + '&id=' + this.orderList[index].course_id + '&order_id=' + this.orderList[index].id)
			},
			// 继续学习
			toStudy(id) {
				$api.jump('/pages/index/course/detail?id=' + id)
			},
			// 申请发票
			toApply(index) {
				$api.jump('/pages/mine/order/apply?order_no=' + this.orderList[index].id + '&course_id=' + this.orderList[index].course_id)
			},
			// 发票详情
			applyDetail(index) {
				$api.jump('/pages/mine/order/apply?data=' + JSON.stringify(this.orderList[index].invoice) + '&course_id=' + this.orderList[index].course_id)
			},
			// 查看详情
			toDetail(index) {
				if(this.orderList[index].status == 0) {
					$api.jump('/pages/index/course/buy?order_no=' + this.orderList[index].order_no + '&id=' + this.orderList[index].course_id)
				} else {
					$api.jump('/pages/mine/order/detail?order_no=' + this.orderList[index].order_no)
				}
			},
			// 触底事件
			onReachBottom() {
				console.log("到底了");
				console.log(this.page );
				console.log(this.limit);
				console.log(Number(this.total));
				if (Number(this.page) * Number(this.limit) >= Number(this.total)) {
					$api.info("没有更多了")
				} else {
					this.page++
					this.getOrderList()
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.web_box::v-deep {
		padding: 0 30rpx;
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.list {
			width: 100%;
		}
		.list_item {
			width: 100%;
			box-sizing: border-box;
			padding: 12rpx;
			margin-top: 20rpx;
			background-color: #fff;
			box-shadow: 0px 2px 6px 0px rgba(213,213,213,0.5);
			border-radius: 24rpx;
		}
		.order_id {
			font-size: 24rpx;
			font-weight: 400;
			color: #333333;
		}
		.order_state {
			font-size: 24rpx;
			font-weight: 400;
			color: #FA6400;
		}
		.img_right {
			width: calc(100% - 322rpx);
			padding-left: 12rpx;
		}
		.title {
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
			padding-bottom: 14rpx;
		}
		.text_style1 {
			font-size: 20rpx;
			font-weight: 400;
			color: #999999;
			padding-bottom: 12rpx;
		}
		.order_price {
			font-size: 32rpx;
			font-weight: 600;
			color: #FA6400;
		}
		.order_apply {
			font-size: 20rpx;
			font-weight: 400;
			color: #2988FE;
		}
		.u-button {
			width: 144rpx;
			height: 48rpx;
			border-radius: 40rpx;
			border: 1px solid #FF5D00;
			font-size: 22rpx;
			font-weight: 400;
			color: #FA6400;
			margin: 0;
		}
		.text_none {
			font-size: 32rpx;
			color: #333333;
			margin-top: 44rpx;
		}
		.img_none {
			margin-top: 300rpx;
			width: 570rpx;
			height: 328rpx;
		}
	}
</style>