<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索商品">
			</view>
			<view class="two">
				<tabs :tabs="tabs" @tabsChange="tabsChange">
					<view class="tabsList">
						<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
							<view class="list-scroll-view">
								<view class="list" v-for="(item,index) in list" :key="index">
									<view class="list_1">
										<view class="l">
											<text class="iconfont icon-shangdian"></text>
											<text>{{item.shop}}</text>
										</view>
										<view class="r">
											{{item.status=='1'?'待付款':'已付款'}}
										</view>
									</view>
									<view class="list_2">
										<view class="l">
											<image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode=""></image>
										</view>
										<view class="c">
											<view class="name">
												{{item.name}}
											</view>
										</view>
										<view class="r">
											<view class="price">
												¥{{item.price}}
											</view>
											<view class="num">
												×{{item.buy_num}}
											</view>
										</view>
									</view>
									<view class="other">
										<text>共{{item.market_num}}件商品</text>
										<text>总价¥{{item.money}}</text>
									</view>
									<view class="btn">
										<button type="default" size="mini">取消订单</button>
										<button type="default" size="mini">付款</button>
									</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</tabs>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	import tabs from '@/components/tabs/index.vue';
	export default {
		components: {
			tabs
		},
		data() {
			return {
				user: {},
				status: '',
				searchInfo: {},
				tabs: {
					active: '-0',
					menu: [ //菜单列表
						{
							title: '全部订单',
							active: '-0'
						},
						{
							title: '待发货',
							active: '0'
						},
						{
							title: '邮寄中',
							active: '1'
						},
						{
							title: '已收货',
							active: '2'
						}
					]
				},
				list: [ //订单列表
					{
						shop: '官方自营店',
						status: '1',
						url: [{
							name: "20220928155634.jpg",
							uri: "/files/point/20220928155634.jpg",
							url: "https://broadcast.waityou24.cn/files/point/20220928155634.jpg"
						}],
						name: '饮用水',
						price: 58,
						buy_num: 1,
						market_num: 1,
						money: 58
					}
				]

			};
		},
		onLoad: function(e) {
			const that = this;
			that.$set(that, `status`, e.status);
			// 监听用户是否登录
			that.watchLogin();
		},
		onShow: function() {},
		methods: {
			// 监听用户是否登录
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: function(res) {
						let user = that.$jwt(res.data);
						if (user) that.$set(that, `user`, user);
						that.$set(that.tabs, `active`, that.status);
						that.search();
					},
					fail: function(err) {
						uni.navigateTo({
							url: `/pages/login/index`
						})
					}
				});
			},
			// 查询列表
			async search() {
				const that = this;
				let user = that.user;
				let status = that.status;
				console.log(status);
			},
			// 分页
			toPage(e) {

			},
			// 输入框
			toInput(e) {
				const that = this;
				that.$set(that.searchInfo, `name`, e.detail.value)
			},
			// 取消订单
			toCancel(e) {
				console.log(e);
			},
			// 付款
			toPay(e) {
				console.log(e);
			},
			// 选择选项卡
			tabsChange(e) {
				const that = this;
				that.$set(that.tabs, `active`, e.active)
				that.$set(that, `status`, e.active);
				that.search()
			}
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			padding: 2vw;

			input {
				padding: 2vw;
				background-color: var(--f1Color);
				font-size: var(--font14Size);
				border-radius: 5px;
			}
		}

		.two {
			position: relative;
			flex-grow: 1;
			background-color: var(--f9Color);

			.tabsList {
				position: relative;
				width: 100vw;
				height: 82vh;

				.list {
					background-color: #fff;
					margin: 0 2vw 2vw 2vw;
					padding: 2vw;

					.list_1 {
						margin: 0 0 1vw 0;
						display: flex;
						flex-direction: row;
						justify-content: space-between;
					}

					.list_2 {
						margin: 0 0 1vw 0;
						display: flex;

						.l {
							width: 20vw;

							.image {
								width: 100%;
								height: 20vw;
								border-radius: 5px;

							}
						}

						.c {
							width: 60vw;
							padding: 0 2vw;
						}

						.r {
							width: 15vw;
							text-align: right;
						}
					}

					.other {
						margin: 0 0 2vw 0;
						text-align: right;

						text {
							font-size: 14px;

							padding: 0 0 0 2vw;
						}
					}

					.btn {
						text-align: right;
						margin: 2vw 0 0 0;
						border-top: 1px solid #f1fff1;

						button {
							margin: 2vw 0 0 2vw;
						}
					}
				}
			}
		}
	}

	// 	.two {
	// 		position: relative;
	// 		flex-grow: 1;
	// 		background-color: var(--f9Color);

	// 		.two_1 {
	// 			background-color: var(--fffColor);
	// 			padding: 2vw;
	// 			display: flex;
	// 			flex-direction: row;
	// 		}

	// 		.two_2 {
	// 			display: flex;
	// 			flex-direction: column;

	// 			.list {
	// 				width: 100vw;
	// 				margin: 2vw 0 0 0;
	// 				background-color: var(--mainColor);

	// 				.list_1 {
	// 					display: flex;
	// 					flex-direction: row;
	// 					justify-content: space-between;
	// 					padding: 2vw;

	// 					.name {
	// 						font-size: var(--font14Size);

	// 						text {
	// 							margin: 0 1vw 0 0;
	// 						}
	// 					}

	// 					.status {
	// 						font-size: var(--font14Size);
	// 						color: var(--ff0Color);
	// 					}
	// 				}

	// 				.list_2 {
	// 					display: flex;
	// 					flex-direction: row;
	// 					justify-content: space-between;
	// 					padding: 2vw;
	// 					background-color: var(--f8Color);

	// 					.image {
	// 						width: 20vw;
	// 						height: 20vw;
	// 						margin: 0 2vw 0 0;
	// 					}

	// 					.other {
	// 						display: flex;
	// 						flex-direction: column;
	// 						flex-grow: 1;

	// 						.name {
	// 							font-size: var(--font14Size);
	// 							font-weight: bold;
	// 							margin: 0 0 2vw 0;
	// 						}

	// 						.other_1 {
	// 							font-size: var(--font12Size);
	// 							color: var(--f85Color);
	// 						}
	// 					}

	// 					.money {
	// 						font-size: var(--font12Size);

	// 						.num {
	// 							text-align: right;
	// 						}
	// 					}
	// 				}

	// 				.list_3 {
	// 					display: flex;
	// 					justify-content: flex-end;
	// 					padding: 2vw;
	// 					border-bottom: 0.5vw solid var(--f9Color);
	// 					font-size: var(--font12Size);

	// 					text {
	// 						margin: 0 1vw;
	// 					}
	// 				}

	// 				.list_4 {
	// 					padding: 2vw;
	// 					text-align: right;

	// 					button {
	// 						margin: 0 1vw 0 2vw;
	// 					}
	// 				}
	// 			}
	// 		}
	// 	}
	// }

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}
</style>
