<template>
	<view class="orderList">
		<view class="nav">
			<navigation-bar-view ref="nav"></navigation-bar-view>
			<view class="header">
				<view class="search-box">
					<input placeholder="请输入手机号" @input="changeMobile"/>
				</view>
				<view class="search-btn" @click="search">搜索</view>
			</view>
			
		</view>
		
		<view style="height: 21.8vw"></view>

		<block v-for="(item, i) in list" :key="i">
			<view class="cell" @click="toDetail(item)">
				<view class="top">
					<view class="order-sn">订单号：{{item.orderSn}}</view>
					<view class="status">
						<text v-if="item.rentStatus == 1">租赁中</text>
						<text v-if="item.rentStatus == 2">已取出</text>
						<text v-if="item.rentStatus == 0">未开始</text>
					</view>
				</view>
				<view class="center">
					<view class="take-code" v-if="item.rentSn">
						<view class="label">取物码：</view>
						<view class="code">{{item.rentSn}}</view>
					</view>
					<view class="message">
						<text>格口类型：</text>
						<text v-if="item.cabinetType == 1">小格子</text>
						<text v-if="item.cabinetType == 2">中格子</text>
						<text v-if="item.cabinetType == 3">大格子</text>
						<text v-if="item.rentType == 1">(预存{{item.rentTimes / 60}}小时)</text>
						<text v-if="item.rentType == 2">(预存{{item.rentNums}}次)</text>
					</view>
					<view class="message">
						<text>存放箱号：</text>
						<text>{{item.caseSn}}</text>
					</view>
					<view class="message">存放时间：{{item.payTime}}</view>
					<view class="message">联系方式：{{item.mobile}}</view>
				</view>
				<!-- <view class="bottom"> -->
				<!-- <view class="btn">取消订单</view> -->
				<!-- <view class="btn">删除订单</view> -->
				<!-- </view> -->
			</view>
		</block>
		<view style="height: 3.3vw;"></view>
	</view>
</template>

<script>
	import navigationBarView from '../../components/navigationBarView.vue';
	export default {
		components: {
			navigationBarView
		},
		data() {
			return {
				list: [],
				page: 1,
				mobile: ''
			}
		},
		onLoad() {
			this.getData()
		},

		onPullDownRefresh() {
			this.page = 1;
			this.getData()
		},

		onReachBottom() {
			this.page++
			this.getData();
		},


		methods: {
			getData() {
				uni.showLoading({
					title: "加载中..."
				})
				let sn = uni.getStorageSync('sn');
				this.$api.managerDeviceList({
					deviceSn: sn,
					page: this.page,
					mobile: this.mobile
				}).then(res => {
					let list = this.list;
					if (this.page == 1) {
						list = []
					} else if (!res.page.data.length) {
						this.page--
					}
					for (let i = 0; i < res.page.data.length; i++) {
						list.push(res.page.data[i])
					}
					this.list = list;
					uni.stopPullDownRefresh()

				}, err => {

				})
			},
			
			changeMobile(e) {
				this.mobile = e.detail.value;
			},
			
			search() {
				this.page = 1;
				this.getData();
			},

			toDetail(e) {
				console.log(e);
				uni.navigateTo({
					url: '/pages/order/details?isAdmin=1&id=' + e.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.orderList {
		min-height: 100vh;
		background-color: #eee;

		.nav {
			position: fixed;
			top: 0;
			left: 0;
			background-color: #FFFFFF;
		}

		.header {
			position: fixed;
			top: 11.3vw;
			display: flex;
			align-items: center;
			justify-content: space-around;
			width: 100vw;
			height: 10.5vw;
			background-color: #FFFFFF;

			.search-box {
				flex: 1;
				border-radius: 1vw;
				margin-left: 3.3vw;

				input {
					font-size: 3.2vw;
				}
			}

			.search-btn {
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 3.3vw;
				width: 16vw;
				height: 6.6vw;
				border-radius: 6.6vw;
				background: linear-gradient(to right, #FEE704, #FDD001);
				font-size: 3.2vw;
			}

			// .title {
			// 	display: flex;
			// 	align-items: center;
			// 	font-size: 3.5vw;
			// 	color: #161920;
			// }
		}

		.cell {
			padding: 0 3.3vw;
			border-radius: 1.6vw;
			background-color: #FFFFFF;
			margin: 3.3vw 4vw 0;

			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 10.7vw;
				border-bottom: .3vw solid #eee;

				.order-sn {
					color: #999999;
					font-size: 3.5vw;
				}

				.status {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 16vw;
					height: 5.6vw;
					border-radius: 5.6vw;
					background: linear-gradient(to right, #FEE704, #FDD001);
					font-size: 3.2vw;
				}
			}

			.center {
				padding-top: 4.5vw;
				padding-bottom: 4.5vw;

				.take-code {
					display: flex;
					align-items: center;
					margin-bottom: 4.4vw;
					font-weight: bold;
					line-height: 4vw;

					.label {
						font-size: 4vw;
					}

					.code {
						color: #FFB706;
						font-size: 4.8vw;
					}
				}

				.message {
					margin-bottom: 3.1vw;
					color: #666666;
					font-size: 3.5vw;
					line-height: 3.5vw;
				}
			}

			.bottom {
				display: flex;
				justify-content: flex-end;
				padding-bottom: 3.2vw;

				.btn {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 22.7vw;
					height: 8.3vw;
					border-radius: 8.3vw;
					border: .3vw solid #CCCCCC;
					color: #222222;
					font-size: 3.5vw;
				}
			}
		}
	}
</style>
