<template>
	<view class="app">
		<view class="" v-if="total>0">
			<view class="item" v-for="(item,index) in orderlist" :key="index">
				<view class="name">
					{{item.trainingOrderTime}}
					<span>{{item.trainingOrderStatus=='WAIT_PAY'?'待付款':''}}
						{{item.trainingOrderStatus=='PAY'?'已付款':''}}
						{{item.trainingOrderStatus=='REFUNDED'?'已退款':''}}
						{{item.trainingOrderStatus=='CANCEL'?'已取消':''}}
					</span>
				</view>
				<view class="detailslist" @tap="goOrderlearning(item)">
					<image :src="baseurl+item.trainingItemCoverUrl" mode=""></image>
					<view class="model">
						<span>{{item.trainingItemTitle}}</span>
						<span v-if="item.trainingItemPrice">￥{{item.trainingItemPrice}}</span>
						<span v-else>￥0</span>
					</view>
				</view>
				<view class="submit" @tap='goOrderdetails(item)' v-if="item.trainingOrderStatus=='WAIT_PAY'"
					style="background-color: #4271B9;">
					去支付
				</view>
			</view>
		</view>
		<view class="noorder" v-else>
			<u-empty mode="list" icon-size='220' text='暂无'></u-empty>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import baseurl from '@/api/baseurl.js'
	import {
		selectTrainingOrderItemGroupList
	} from '@/api/Orderlist/index.js'
	export default {
		data() {
			return {
				baseurl: undefined,
				nurseStationPersonId: undefined,
				pageNum: 1,
				pageSize: 10,
				orderlist: [],
				total: 0,
			};
		},
		onShow() {},
		onLoad() {
			this.baseurl = baseurl
			const that = this
			const value = uni.getStorageSync('nursePersonId');
			if (value) {
				that.nurseStationPersonId = value
				that.info();
			} else {}
		},
		methods: {
			//订单详情
			goOrderdetails(item) {
				uni.navigateTo({
					url: `/pages/Orderdetails/Orderdetails?trainingOrderNo=${item.trainingOrderNo}`
				})
			},
			//我的学习
			goOrderlearning(item) {
				uni.navigateTo({
					url: `/pages/Orderlearning/Orderlearning?trainingOrderStatus=${item.trainingOrderStatus}&trainingParentId=${item.trainingItemId}&trainingOrderNo=${item.trainingOrderNo}`
				})
			},
			//列表信息
			info() {
				selectTrainingOrderItemGroupList(this.pageNum, this.pageSize, this.nurseStationPersonId)
					.then(res => {
						this.orderlist = res.rows
						this.total = res.total
					})
			},
		},
		onReachBottom() { //下滑加载
			if (this.orderlist.length >= this.total) {} else {
				this.pageNum++
				selectTrainingOrderItemGroupList(this.pageNum, this.pageSize, this.nurseStationPersonId)
					.then(res => {
						res.rows.forEach(e => {
							this.orderlist.push(e)
						})
					})
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.pageNum = 1
			this.info();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	}
</script>

<style lang="scss">
	@import "./Orderlist.scss";
</style>
