<template>
	<view class="content">
		<view class="headr">
			<view class="money-box">
				<view class="body-title">
					<view class="goback-box" @click="toBack"><image class="goback" src="../../static/icon/fanhui.png" mode=""></image></view>
					<view class="header">订单数据</view>
				</view>
			</view>
			<!-- <picker mode="date" :value="now_date" @change="bindDateChange" :fields="'month'" :end="date">
				<view class="uni-input choose-time">{{ now_date }} ></view>
			</picker> -->
			<!-- <view class="uni-input choose-time" @click="show = true">{{ now_date }}</view> -->
			<view class="month">
				<image src="../../static/icon/sdata.png" mode=""></image>
				<view class="store-data">
					<view class="data">{{ num }}</view>
					<view class="tit">本月订单</view>
				</view>
			</view>
		</view>
		<view class="search-wrapper" @click="showInput" v-if="!is_show">
			<image src="../../static/icon/sousuo.png" mode=""></image>
			<view class="">输入关键字</view>
		</view>
		<view class="search-wrapper" v-if="is_show">
			<input type="text" value="" v-model="keyword" focus />
			<view class="btn" @click="search">搜索</view>
		</view>
		<view class="list-wrapper">
			<scroll-view scroll-y="true" :style="{ height: height }" class="swiper-box" @scrolltolower="loadData">
				<!-- 空白页 -->
				<!-- <empty v-if=" loaded && dataList.length == 0"></empty> -->
				<view v-for="(item, index) in dataList" class="item">
					<view class="item-top flex">
						<view class="user-name clamp">订单编号：{{ item.order_id }}</view>
						<view class="top-status">{{ item.status_name != '待评价' ? item.status_name : '已完成' }}</view>
					</view>
					<view class="item-body flex" v-for="(ls, ind) in item._info">
						<image :src="ls.cart_info.productInfo.image" mode=""></image>
						<view class="goods-info">
							<view class="good-name clamp2">{{ ls.cart_info.productInfo.store_name }}</view>
							<view class="good-price">￥{{ ls.cart_info.productInfo.ot_price }}</view>
							<view class="good-num">x{{ ls.cart_info.cart_num }}</view>
						</view>
					</view>
					<view class="item-btm">共{{ item.total_num }}件商品 合计：￥{{ item.total_price }}</view>
					<view class="buy_info">下单人：{{ item.user_for_big_screen.nickname }}</view>
				</view>
				<uni-load-more :status="loadingType"></uni-load-more>
			</scroll-view>
		</view>
		<u-calendar v-model="show" mode="range" @change="change"></u-calendar>
	</view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
import { order } from '@/api/info.js';
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		let start = new Date(new Date().toLocaleDateString()).getTime();
		let a = new Date();
		let month = a.getMonth() + 1;
		let date = a.getDate();
		let year = a.getFullYear() + '';
		if (month < 10) {
			month = '0' + month;
		} else {
			month = month + '';
		}
		if (date < 10) {
			date = '0' + date;
		} else {
			date = date + '';
		}
		return {
			show: false, //日历
			is_show: false, //搜索是否显示
			keyword: '', //搜索关键字
			height: '', //滚动区域高度
			dataList: [], //月订单
			num: 0, //订单总数
			loadingType: 'more',
			page: 1,
			limit: 1000,
			now_date: year + '-' + month,
			date: year + '-' + month, //选择的日期不能超过今天
			real_name: '',
			store_id: '',
			waiter_id: ''
		};
	},
	components: {
		empty,
		uniLoadMore
	},
	computed: {
		...mapState(['userInfo'])
	},
	onReady(res) {
		var _this = this;
		uni.getSystemInfo({
			success: resu => {
				const query = uni.createSelectorQuery();
				query.select('.list-wrapper').boundingClientRect();
				query.exec(function(res) {
					console.log(res, 'ddddddddddddd');
					_this.height = resu.windowHeight - res[0].top + 'px';
					console.log('打印页面的剩余高度', _this.height);
				});
			},
			fail: res => {}
		});
	},
	onLoad(option) {
		if (option.id) {
			this.store_id = option.id;
		} else {
			this.store_id = this.userInfo.store_id;
		}
		if (option.waiter_id) {
			this.waiter_id = option.waiter_id;
		}
		this.loadData();
	},
	methods: {
		bindDateChange(e) {
			console.log(e);
			this.now_date = e.detail.value;
			this.loadingType = 'more';
			this.page = 1;
			this.dataList = [];
			this.loadData();
		},
		showInput() {
			this.is_show = true;
		},
		search() {
			console.log('search');
			this.real_name = this.keyword;
			this.dataList = [];
			this.page = 1;
			this.loadingType = 'more';
			this.loadData();
		},
		loadData() {
			let obj = this;
			console.log('加载数据');
			if (obj.loadingType == 'noMore' || obj.loadingType == 'loading') {
				return;
			}
			obj.loadingType = 'loading';
			console.log(obj.now_date);
			order({ page: obj.page, limit: obj.limit, data: obj.now_date, store_id: obj.store_id, real_name: obj.real_name, waiter_id: obj.waiter_id }).then(({ data }) => {
				console.log(data);
				obj.num = data.length;
				obj.dataList = obj.dataList.concat(data);
				obj.page++;
				if (data.length == obj.limit) {
					obj.loadingType = 'more';
				} else {
					obj.loadingType = 'noMore';
				}
			});
		},
		toBack() {
			uni.navigateBack({});
		},
		bindDateChange(e) {
			console.log(e.detail, 'dddddddddddd');
			this.now_date = e.detail.value;
			this.dataList = [];
			this.page = 1;
			this.loadingType = 'more';
			this.loadData();
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background-color: #f5f5f5;
}

.headr {
	height: 468rpx;
	background: linear-gradient(180deg, #ff4c4c 0%, #ff7474 100%);
	position: relative;
	.money-box {
		padding-top: var(--status-bar-height);
		color: #ffffff;
		text-align: center;
		justify-content: center;
		position: relative;
		.body-title {
			height: 80rpx;
			text-align: center;
			font-size: 35rpx;
			position: relative;
			.header {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #fffeff;
				height: 80rpx;
				font-size: 32rpx;
				font-weight: 700;
				z-index: 9;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.goback-box {
				position: absolute;
				z-index: 10;
				left: 24rpx;
				top: 0;
				height: 80rpx;
				display: flex;
				align-items: center;
			}
			.goback {
				width: 30rpx;
				height: 36rpx;
			}
		}
	}
	.time {
		width: 100%;
		color: #ffffff;
		padding-left: 30rpx;
		font-size: 28rpx;
	}
	.month {
		position: absolute;
		top: 40rpx;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
		height: 275rpx;
		width: 275rpx;

		image {
			width: 100%;
			height: 100%;
		}

		.store-data {
			position: absolute;
			height: 275rpx;
			width: 275rpx;
			text-align: center;
			color: #fff;
			top: 0;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.data {
				font-size: 50rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
				padding-bottom: 20rpx;
			}

			.tit {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ffffff;
			}
		}
	}
}

.search-wrapper {
	width: 702rpx;
	height: 66rpx;
	background: #ffffff;
	box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
	border-radius: 33px;
	margin: 20rpx auto;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;

	// line-height: 35px;
	image {
		height: 33rpx;
		width: 33rpx;
		margin-right: 22rpx;
	}

	input {
		width: auto;
		flex-grow: 1;
		padding-left: 30rpx;
	}

	.btn {
		width: 150rpx;
		text-align: center;
		//background-color: red;
		color: #ff4c4c;
	}
}

.list-wrapper {
	.swiper-box {
		// background-color: #bfa;
		.item {
			width: 702rpx;
			padding: 0 28rpx;
			background: #ffffff;
			box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
			border-radius: 10rpx;
			margin: 0 auto 15rpx;

			&:last-of-type {
				margin: 0 auto;
			}

			.item-top {
				line-height: 83rpx;
				max-height: 83rpx;

				.user-name {
					flex-grow: 1;
					height: 83rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #666666;
					padding-right: 30rpx;
				}

				.top-status {
					width: 100rpx;
					flex-shrink: 0;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ff4c4c;
				}
			}

			.item-body {
				justify-content: flex-start;

				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 15rpx;
					background-color: #eee;
					flex-shrink: 0;
					margin-right: 9rpx;
				}

				.goods-info {
					width: 100%;
					height: 160rpx;
					position: relative;

					.good-name {
						width: 311rpx;
						line-height: 37rpx;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #3f454b;
					}

					.good-id {
						// width: 273px;
						line-height: 40rpx;
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #666666;
					}

					.tag {
						margin-top: 6rpx;
						width: 102rpx;
						line-height: 34rpx;
						background: #dbf3e9;
						border-radius: 5rpx;
						text-align: center;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #ff4c4c;
					}

					.good-price,
					.good-num {
						position: absolute;
						top: 0;
						right: 0;
						line-height: 1.5;
						text-align: right;
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
					}

					.good-num {
						color: #666666;
						top: 39rpx;
					}
				}
			}

			.item-btm {
				text-align: right;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				padding-bottom: 10rpx;
				border-bottom: 2px solid #f8f8f8;
			}
			.buy_info {
				padding: 20rpx 10rpx;
			}
		}
	}
}
.choose-time {
	line-height: 1.5;
	padding-left: 30rpx;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
	width: 230rpx;
}
</style>
