<template>
	<view class="center">
		<view class="input-box flex">
			<view class=" input-content flex">
				<view class="iconfont iconsearch"></view>
				<view class="input"><input type="text" disabled placeholder="输入关键字" /></view>
			</view>
		</view>
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData" :style="{ height: maxheight + 'px' }">
			<view class="main" v-for="(item, index) in list" :key="index" @click="goToOrderDetail(item)">
				<view class="top flex">
					<view class="userinfo clamp">订单编号ID：{{ item.order_id }}</view>
					<view class="type">{{ item.status_name }}</view>
				</view>
				<view class="mainbox" v-for="(ls, ind) in item._info">
					<view class="bg"><image :src="ls.cart_info.productInfo.image" mode=""></image></view>
					<view class="main-info flex">
						<view class="main-left">
							<view class="name clamp2">{{ ls.cart_info.productInfo.store_name }}</view>
						</view>
						<view class="main-right">
							<view class="price">￥{{ ls.cart_info.productInfo.ot_price }}</view>
							<view class="num">x{{ ls.cart_info.cart_num}}</view>
						</view>
					</view>
				</view>
				<view class="item-btm">共{{ item.total_num }}件商品 合计：￥{{ item.total_price }}</view>
			</view>
			<uni-load-more :status="loadType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
import { merchantList } from '@/api/merchant.js';
export default {
	components: {
		empty,
		uniLoadMore
	},
	onReady() {
		let obj = this;
		// 初始化获取页面高度
		uni.createSelectorQuery()
			.select('.center')
			.fields(
				{
					size: true
				},
				data => {
					// 初始化获取头部高度
					uni.createSelectorQuery()
						.select('.input-box')
						.fields(
							{
								size: true
							},
							es => {
								console.log(data,es)
								// 保存头部高度
								obj.maxheight = data.height - es.height;
							}
						)
						.exec();
				}
			)
			.exec();
	},
	data() {
		return {
			page: 1,
			limit: 10,
			loadType: 'more',
			list: [],
			maxheight:''
		};
	},
	onPullDownRefresh() {
		this.loadData();
	},
	onLoad() {
		this.loadData();
	},
	methods: {
		loadData() {
			const obj = this;
			if (obj.loadType == 'loading' || obj.loadType == 'nomore') {
				return;
			}
			obj.loadType = 'loading';
			merchantList({ page: obj.page, limit: obj.limit }).then(({ data }) => {
				obj.list = obj.list.concat(data.data);
				obj.page ++
				if (data.data.length == obj.limit) {
					obj.loadType = 'more';
				} else {
					obj.loadType = 'nomore';
				}
			});
		},
		goToOrderDetail(e) {
			uni.navigateTo({
				url: '/pages/merchant/orderDetail?id=' + e.order_id
			});
		},
	}
};
</script>

<style lang="scss">
page,.center {
	height: 100%;
	background: #f6f4f4;
}
.input-box {
	width: 100%;
	padding: 25rpx;
	background-color: #52c696;
	z-index: 999;
	height: 60px;
	.iconsearch {
		padding-left: 30%;
		font-size: 50rpx;
		color: #9f9f9f;
	}
	.input-content {
		border-radius: 99rpx;
		color: #9f9f9f;
		flex-grow: 1;
		padding: 10rpx 30rpx;
		background-color: #ffffff;
		.input {
			flex-grow: 1;
			input {
				font-size: $font-lg;
			}
		}
	}
	.input-button {
		padding-left: 20rpx;
		font-size: $font-lg;
		height: 100%;
	}
}
.main {
	padding: 30rpx 30rpx 60rpx 30rpx;
	width: 700rpx;
	margin: 20rpx auto 0;
	background: #ffffff;
	box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
	border-radius: 10rpx;
	.top {
		align-items: center;
		.userinfo {
			max-width: 70%;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #666666;
		}
		.type {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #52c696;
		}
	}
	.mainbox {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		margin-top: 30rpx;
		align-items: flex-start;
		.bg {
			flex-shrink: 0;
			width: 160rpx;
			height: 160rpx;
			background: #4cd964;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.main-info {
			justify-content: space-between;
			align-items: flex-start;
			width: 100%;
			.main-left {
				padding-left: 10rpx;
				.name {
					max-width: 338rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #3f454b;
				}
				.order {
					margin-top: 10rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #666666;
				}
				.ordertype {
					width: 120rpx;
					margin-top: 10rpx;
					background: #ffeae5;
					border-radius: 5rpx;
					font-size: 20rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ff6f0f;
					text-align: center;
				}
			}
			.main-right {
				text-align: right;
				padding-top: 6rpx;
				.price {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}
				.num {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
			}
		}
	}
	.item-btm {
		text-align: right;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
	}
}

</style>
