<template>
	<view class="content">
		<!-- 订单管理列表 -->
		<view class="orders" v-if="orders.length > 0">
			<view class="orders-item" v-for="(item, index) in orders" :key="index">
				<view class="orders-flex">
					<view class="no nowrap">
						<text class="orders-tag" v-if="!item.is_my">客户</text>
						<text class="orders-tag order-tag-my" v-else>个人</text>
						{{item.order_no}}
					</view>
					<view class="state">{{item.refund_status.text}}</view>
				</view>
				<view class="orders-content">
					<view class="orders-content-item">
						<label>业务类型</label>
						<view class="nowrap orders-content-type">
							<text v-for="(itemType, indexType) in item.item_type" :key="indexType" v-if="itemType.number > 0">{{itemType.title}}x{{itemType.number}}</text>
						</view>
					</view>
					<view class="orders-content-block">
						<view class="item-flex" v-for="(citem, cindex) in item.items" :key="cindex">
							<view class="item-flex-title">{{citem.institution.title}}</view>
							<view class="item-flex-value">￥{{citem.price}}</view>
						</view>
					</view>
					<view class="orders-content-item" v-if="item.total > 0">
						<label>咨询服务费</label>
						<view class="nowrap">￥{{item.total}}</view>
					</view>
					<view class="orders-content-item">
						<label>下单时间</label>
						<view class="nowrap">{{item.created_at}}</view>
					</view>
					<view class="orders-content-item">
						<label>退款时间</label>
						<view class="nowrap">-</view>
					</view>
				</view>
			</view>
			<!-- 分页 -->
			<u-loadmore v-if="pagesShow" :status="status" />
		</view>
		<!-- 订单是空的 -->
		<view class="order-null" v-else>
			<u-empty
				mode="order"
				icon="http://cdn.uviewui.com/uview/empty/order.png"
				text="暂无已退款订单"
			>
			</u-empty>
		</view>
	</view>
</template>

<script>
	import { refunds } from '@/apis/interfaces/order.js'
	export default {
		data() {
			return {
				orders		: [],
				// 分页
				page		: {
					current	: 1,
					has_more: false,
				},
				pagesShow	: false,
				status   	: ''
			};
		},
		created() {
			this.getList()
		},
		methods:{
			// 获取列表
			getList(){
				refunds({
					status: '',
					page  : this.page.current 
				}).then(res => {
					let { data, page } = res;
					let atList   	= page.current == 1 ? [] : this.orders
					
					this.orders 	= atList.concat(data)
					this.page  		= page
					this.pagesShow 	= false
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			}
		},
		onReachBottom() {
			this.pagesShow = true;
			if(this.page.has_more){
				this.status    = 'loading';
				this.page.current++
				this.getList()
				return
			}
			this.status    = 'nomore';
		}
	}
</script>

<style lang="scss">
	// 订单为空
	.order-null{
		height: 80vh;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	// 订单列表
	.orders{
		padding: 30rpx 0 10rpx;
		.orders-item{
			margin: 0 30rpx 20rpx;
			background-color: white;
			border-radius: $radius;
		}
		.orders-content{
			padding: 20rpx 30rpx;
			&-item{
				line-height: 70rpx;
				display: flex;
				justify-content: space-between;
				font-size: 30rpx;
				color: #111111;
				label{
					color: #999999;
				}
			}
			&-type{
				text{
					margin-right: 30rpx;
					position: relative;
					display: inline-block;
					&::after{
						position: absolute;
						content: "/";
						width: 30rpx;
						text-align: center;
						font-size: 30rpx;
						top: 0;
						right: -30rpx;
					}
					&:last-child{
						margin-right: 0;
						&::after{
							display: none;
						}
					}
				}
			}
			&-block{
				background: rgba(68, 110, 254, .03);
				padding: 20rpx;
				font-size: 28rpx;
				border-radius: 10rpx;
				margin: 10rpx 0;
				.item-flex{
					display: flex;
					justify-content: space-between;
					line-height: 50rpx;
				}
			}
		}
		.orders-flex{
			border-bottom: solid 1rpx #F6F6F6;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx $padding;
			&:last-child{
				border-top: solid 1rpx #F6F6F6;
				border-bottom: none;
			}
			.orders-tag{
				display: inline-block;
				background: $main-color;
				font-size: 26rpx;
				color: white;
				border-radius: 10rpx;
				padding: 0 10rpx;
				height: 40rpx;
				line-height: 40rpx;
				margin-right: 10rpx;
				&.order-tag-my{
					background: $text-price;
				}
			}
			.no{
				font-size: 30rpx;
				color: #111;
				line-height: 60rpx;
				width: calc(100% - 150rpx);
			}
			.state{
				color: $main-color;
				font-weight: bold;
				font-size: 30rpx;
				line-height: 60rpx;
				width: 150rpx;
				text-align: right;
			}
		}
	}
</style>
