<template>
	<view class="container">
		<view class="swiper-box">
			<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
				<view class="list_box" v-for="(item, index) in list" :key="index">
					<view class="list_center">
						<view class="list_left">
							<view class="list_name mar-b" v-if="userInfo.type == 1">{{ item.doctor_name }}</view>
							<view class="list_name mar-b" v-if="userInfo.type == 2 && item.type == 1 || item.type == 2">{{item.patient_name}}</view>
							<view class="list_name mar-b" v-if="userInfo.type == 2 && item.type == 3">{{item.organ_name}}</view>
							<view class="list_name mar-b" v-if="userInfo.type == 3">{{ item.doctor_name }}</view>
							<view class="list_address mar-b">医院: {{ item.hospital_name }}</view>
							<view class="list_address mar-b">预约方式: {{ item.type == 1 ? '咨询' : item.type == 2 ? '预约' : '多点执业'}}</view>
							<!-- <view class="list_address mar-b">支付金额: {{ item.pay_price }}</view>
							<view class="list_address mar-b">支付方式: {{ item.pay_type == 1 ? '微信' : '余额' }}</view> -->
						</view>
						<view class="list_right" v-if="item.refund == 0">
							{{
								item.status == 0
									? '未支付'
									: item.status == 1
									? '已支付'
									: item.status == 2
									? '已预约'
									: item.status == 3
									? '待确认'
									: item.status == 4
									? '已确认'
									: item.status == 5
									? '已完成'
									: '已评价'
							}}
						</view>
						<view class="list_right" v-if="item.refund != 0">{{ item.refund == 1 ? '退款中' : item.status == 2 ? '退款完成' : '退款失败' }}</view>
					</view>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import { mapState } from 'vuex';
import { orderList } from '@/api/patient.js';
export default {
	data() {
		return {
			limit: 10, //每次加载数据条数
			page: 1, //当前页数
			loadingType: 'more', //加载更多状态
			loading: 0, //判断是否为点击搜索按钮跳转加载
			list: []
		};
	},
	onLoad() {
		this.loadData();
	},
	onPullDownRefresh() {
		this.page = 1;
		this.commission('refresh');
	},
	computed: {
		...mapState(['userInfo'])
	},
	onShow() {
		console.log(this.userInfo)
	},
	methods: {
		//获取订单列表
		loadData(type) {
			let obj = this;
			console.log(obj.loadingType)
			//这里是将订单挂载到tab列表下
			if (type !== 'refresh') {
				//没有更多数据直接跳出方法
				if (obj.loadingType === 'nomore') {
					return;
				} else {
					// 设置当前为数据载入中
					obj.loadingType = 'loading';
				}
			} else {
				//当重新加载数据时更新状态为可继续添加数据
				obj.loadingType = 'more';
			}
			orderList({
				state: 0,
				keyword: '',
				page: obj.page,
				limit: obj.limit
			})
				.then(({ data }) => {
					if (type === 'refresh') {
						obj.list = [];
					}
					obj.list = obj.list.concat(data.list);
					//判断是否还有下一页，有是more  没有是nomore
					if (obj.limit == data.list.length) {
						obj.page++;
						obj.loadingType = 'more';
					} else {
						obj.loadingType = 'nomore';
					}
					console.log(obj.page)
					// 判断是否为刷新数据
					if (type === 'refresh') {
						// 判断是否为点击搜索按钮跳转加载
						if (obj.loading == 1) {
							uni.hideLoading();
						} else {
							uni.stopPullDownRefresh();
						}
					}
				})
				.catch(e => {
					console.log(e);
				});
		}
	}
};
</script>

<style lang="scss">
.mar-b {
	margin-bottom: 10rpx;
}
.container {
	padding: 20rpx 20rpx 0;
	.swiper-box{
		height: 90vh;
		.list-scroll-content{
			height: 100%;
		}
	}
}
.list_box {
	background-color: #ffffff;
	margin-bottom: 20rpx;
	padding: 30rpx 55rpx 45rpx 45rpx;
	display: flex;
	flex-direction: column;
	background: rgba(255, 255, 255, 1);
	box-shadow: 0px 5rpx 5rpx 0px rgba(35, 24, 21, 0.06);
	border-radius: 10rpx;
	.list_name {
		font-size: 32rpx;
		font-weight: 500;
		color: rgb(0, 0, 0);
		line-height: 36rpx;
		margin-bottom: 25rpx;
	}
	.list_center {
		display: flex;
		justify-content: space-between;
		.list_address {
			font-size: 24rpx;
			font-weight: 500;
			color: rgba(102, 102, 102, 1);
			line-height: 36rpx;
		}
		.list_right {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			font-weight: bold;
			color: $base-color;
		}
	}
}
</style>
