<template>
	<view>
		<view class="order_status_list">
			<view class="order_status_item" :class="requestParam.status==0?'active':''" @click="setStatus(0)"> 全部 </view>
			<view class="order_status_item" :class="requestParam.status==1?'active':''" @click="setStatus(1)"> 待跟进 </view>
			<view class="order_status_item" :class="requestParam.status==8?'active':''" @click="setStatus(8)"> 已完成 </view>
		</view>
		<view class="to_bottom" v-if="!orderList.length"> -----还没有订单-----</view>
		<view class="order_list">
			<view class="order_item" v-for="(item,index) in orderList" :key="index" >
				<view class="order_title" @click="item.product_list.length > 1">
					<view class="business_name">
						{{item.business_name}}
					</view>
					<view class="order_starus">
						{{item.state}}
					</view>
				</view>
				<view  class="product_list" :class="item.contents_class?'active':''">
					<view class="product_item" v-for="product_info in item.product_list" :key="product_info.item_id"  >
						<navigator :url="'/pages/product/index?product_id='+product_info.product_id" >
							<image class="product_img" :src="product_info.product_thumb" mode=""></image>
						</navigator>
						<view class="product_info">
							<navigator :url="'/pages/product/index?product_id='+product_info.product_id"  class="product_name">
								{{product_info.product_name}}
							</navigator>
							<navigator :url="'/pages/product/index?product_id='+product_info.product_id" class="product_spec">
								{{product_info.product_spec}}
							</navigator>
						</view>
						<view class="buy_num">
							x{{product_info.buy_num}}
						</view>
					</view>
				</view>
				<view class="show_more" v-if="item.product_list.length > 1" @click.stop="changeHeight(index)">
					<uni-icons :type="item.contents_class?'up':'down'" size="20" ></uni-icons>
				</view>
				<view class="order_price">
					<span>￥{{item.pay_total}}</span>
				</view>
			</view>
		</view>
		<view class="to_bottom" v-if="isLast"> -----到底啦-----</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 产品列表
				orderList:[],
				// 请求参数
				requestParam:{
					page:1,
					status:0,
				},
				// 是否最后一页
				isLast:false,
				// 是否请求中
				isReqing:false,
			};
		},
		onLoad() {
			// 初始化页码为1
			this.requestParam.page	= 1;
			// 是否是最后一页
			this.isLast			 	= false;
			// 设置请求中
			this.isReqing			= true;
			// 登录提示
			if( !this.$checkAccess.alterLogin() )  return ;
			// 请求列表
			this.$http.request('api/orders/get_list',this.requestParam).then((re)=>{
				// 设置非请求中
				this.isReqing		= false;
				// 成功结果
				if( re.code == 'success' ){
					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
					this.orderList = re.data.data;
				}
			});
		},
		onShow() {
			// 登录提示
			if( !this.$checkAccess.alterLogin() )  return ;
			// 没有数据的话，或者请求中，不允许刷新
			if( this.orderList.length > 0 || this.isReqing ) return ;
			// 设置请求中
			this.isReqing			= true;
			// 请求列表
			this.$http.request('api/orders/get_list',this.requestParam).then((re)=>{
				// 设置非请求中
				this.isReqing		= false;
				// 成功结果
				if( re.code == 'success' ){
					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
					this.orderList = re.data.data;
				}
			});
		},
		onPullDownRefresh() {
			// 登录提示
			if( !this.$checkAccess.alterLogin() )  return ;
			// 如果请求中，不允许请求，
			if( this.isReqing )		return false;
			// 初始化页码为1
			this.requestParam.page	= 1;
			// 是否是最后一页
			this.isLast			 	= false;
			// 设置请求中
			this.isReqing			= true;
			// 请求列表
			this.$http.request('api/orders/get_list',this.requestParam).then((re)=>{
				// 设置非请求中
				this.isReqing		= false;
				// 成功结果
				if( re.code == 'success' ){
					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
					this.orderList = re.data.data;
				}
			});
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			// 登录提示
			if( !this.$checkAccess.alterLogin() )  return ;
			// 如果页码是0，避免第一页重复
			if( this.requestParam.page < 1 ) return;
			// 最后一页不请求
			if( this.isLast )		return;
			// 请求中，不再请求
			if( this.isReqing )		return;
			// 增加一页
			this.requestParam.page	= this.requestParam.page+1;
			// 设置请求中
			this.isReqing			= true;
			// 请求列表
			this.$http.request('api/orders/get_list',this.requestParam).then((re)=>{
				// 设置非请求中
				this.isReqing		= false;
				// 成功结果
				if( re.code == 'success' ){
					if(re.data.last_page <= this.requestParam.page ) this.isLast = true;
					// 追加数据
					this.orderList.push(... re.data.data);
				}
			});
		},
		methods:{
			setStatus(status){
				// 登录提示
				if( !this.$checkAccess.alterLogin() )  return ;
				// 请求中，不再请求
				if( this.isReqing ) 		return;
				// 初始化页码为1
				this.requestParam.page		= 1;
				// 是否是最后一页
				this.isLast			 		= false;
				// 状态变更
				this.requestParam.status	= status;
				// 设置请求中
				this.isReqing				= true;
				// 请求列表
				this.$http.request('api/orders/get_list',this.requestParam).then((re)=>{
					// 设置非请求中
					this.isReqing			= false;
					// 成功结果
					if( re.code == 'success' ){
						if(re.data.last_page >= this.requestParam.page ) this.isLast = true;
						this.orderList = re.data.data;
					}
				});
			},
			changeHeight(index){
				this.orderList[index].contents_class  = this.orderList[index].contents_class ? 0:1;
			}
		}
	}
</script>

<style lang="less">
	.order_status_list{
		display: block;
		height: 60rpx;
		color: #666666;
		line-height: 60rpx;
		background: #FFFFFF;
		padding: 10rpx 35rpx;
		.order_status_item{
			float: left;
			font-size: 28rpx;
			padding: 0rpx 20rpx;
		}
		.order_status_item.active{
			color: #000000;
			font-weight: bold;
		}
	}
	.order_list{
		display:block;
		overflow: hidden;
		margin: 0rpx auto;
		.order_item{
			display: block;
			background: #FFFFFF;
			margin: 0rpx auto;
			padding: 0rpx 35rpx;
			margin-bottom: 10rpx;
			.order_title{
				width: 100%;
				height: 60rpx;
				display: block;
				overflow: hidden;
				line-height: 60rpx;
				.business_name{
					float: left;
					font-size: 32rpx;
				}
				.order_starus{
					color: #999999;
					float: right;
					font-size: 24rpx;
				}
			}
			.product_list{
				display: block;
			    height: 100rpx;
				overflow: hidden;
				margin: 15rpx auto;
				.product_item{
					display: block;
					height: 100rpx;
					overflow: hidden;
					.product_img{
						float: left;
						width: 80rpx;
						height: 80rpx;
						display: block;
						margin-top: 10rpx;
						margin-right: 30rpx;
					}
					.product_info{
						float: left;
						width: 480rpx;
						height: 100rpx;
						display: block;
						overflow: hidden;
						.product_name{
							display: block;
							height: 60rpx;
							display: block;
							font-size: 28rpx;
							line-height: 60rpx;
							overflow: hidden;
						}
						.product_spec{
							color: #999999;
							height: 40rpx;
							display: block;
							font-size: 24rpx;
							line-height: 40rpx;
							overflow: hidden;
						}
					}
					.buy_num{
						float: right;
						height: 100rpx;
						color: #999999;
						font-size: 26rpx;
						text-align: right;
						position: relative;
						line-height: 100rpx;
					}
				}
			}
			.product_list.active{
				height: auto !important;
			}
			.order_price{
				height: 60rpx;
				display: block;
				color: #E03519;
				font-size: 28rpx;
				text-align: right;
				line-height: 60rpx;
			}
			.show_more{
				display: block;
				font-size: 20rpx;
				text-align: center;
				padding: 20rpx 0rpx;
			}
		}
	}
</style>
