<template>
	<view class="verification">
		<view class="nav">
			<!-- 搜索栏 -->
			<view class="navbox">
				<view class="search">
					<u-input placeholder="搜索" border='none' v-model="search"  @input="searchText">
						<template slot="suffix" style='margin-right:40rpx;'>
							<u-image :showLoading="true" :showError='true' src="/static/icon/search.png" width="40rpx"
								height="32rpx"></u-image>
						</template>
					</u-input>
				</view>
				<view>
					<image src="/static/icon/scan.png" style="width: 48rpx ;height: 48rpx;" @click="scanCode"></image>
				</view>
			</view>
			<!-- 分段器 -->
			<view class="segmented">
					<view class="tab_nav">
						<view class="navTitle" v-for="(item,index) in items" :key="index">
							<view :class="{'active':isActive == index}" @click="checked(index)">
								{{item}}
							</view>
						</view>
					</view>
			</view>
		</view>
		
		<!-- 未核销列表 -->
		<view v-if="isActive === 0">
			<view class="card" v-for="item in orderList" >
				<view class="toptitle">
					<view>洲际天堂大饭店</view>
					<view>未核销</view>
				</view>
				<view class="shopCard">
					<image  src="/static/icon/Kudosbg.png"></image>
					<view style="margin-left: 24rpx;">
						<text class="name">端午佳节五香肉粽子，仅限前</text>
						<text class="tag">礼盒装 2000积分</text>
					</view>
				</view>
				<view class="points">
					<text class="totalName">共计:</text>
					<text class="totalContent">2000积分</text>
				</view>
				<view class="btn" @click="goOrderVF">
					<text>核销</text>
				</view>
			</view>
		</view>
		<!-- 已核销列表 -->
		<view v-if="isActive === 1">
			<view class="card" v-for="item in orderList" @click="goDetail">
				<view class="toptitle">
					<view>洲际天堂大饭店</view>
					<view>未核销</view>
				</view>
				<view class="shopCard">
					<image  src="/static/icon/Kudosbg.png"></image>
					<view style="margin-left: 24rpx;">
						<text class="name">端午佳节五香肉粽子，仅限前</text>
						<text class="tag">礼盒装 2000积分</text>
					</view>
				</view>
				<view class="points">
					<text class="totalName">共计:</text>
					<text class="totalContent">2000积分</text>
				</view>
				<view class="btn" v-if="false">
					<text>核销</text>
				</view>
			</view>
		</view>
		<!-- 我的列表 -->
		<view v-if="isActive === 2" >
			<view class="card" v-for="item in orderList" @click="goDetail">
				<view class="toptitle">
					<view>洲际天堂大饭店</view>
					<view>未核销</view>
				</view>
				<view class="shopCard">
					<image  src="http://t9.9026.com/imgs/Kudosbg.png"></image>
					<view style="margin-left: 24rpx;">
						<text class="name">端午佳节五香肉粽子，仅限前</text>
						<text class="tag">礼盒装 2000积分</text>
					</view>
				</view>
				<view class="points">
					<text class="totalName">共计:</text>
					<text class="totalContent">2000积分</text>
				</view>
				<view class="btn" v-if="false">
					<text>核销</text>
				</view>
			</view>
		</view>
		<!-- 已经到底啦 -->
		<view class="home-bottom">
			<uni-load-more :status="status" color="#CCCCCC" :content-text="contentText"/>
		</view>
	</view>
</template>

<script>
	import util from './../../../utils/util.js'
	export default{
		data(){
			return{
				// 搜索
				search:'',
				// 分段器标题
				items: ['未核销', '已核销', '我的'],
				isActive: 0,
				// 组件uni-load-more
				status: 'noMore',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '——  已经到底啦  ——'
				},
				// 订单列表
				orderList:[],
			}
		},
		onLoad() {
			this.getMyOrder(1)
		},
		methods:{
			// 获取订单列表
			getMyOrder(type){
				this.$api.orders.getOrderList({
					page:1,
					confirm_status:type||'',
					keyword:this.search
				}).then(res=>{
					console.log(res,type,"订单列表")
					if(res.code==0){
						this.orderList=res.data.data
					}
				})
			},
			//菜单index切换
			checked(index) {
				console.log(index)
				this.isActive = index
				this.getMyOrder(index+1)
			},
			// 搜索防抖
			searchText:util.debounce(function(){
				this.goSearch()
			},1000),
			// 搜索
			goSearch(){
				this.$api.orders.getOrderList({
					confirm_status:this.isActive+1,
					page:1,
					keyword:this.search
				}).then(res=>{
					console.log(res,"搜索活动项目列表")
					if(res.code==0){
						this.orderList=res.data.data
					}
				})
			},
			// 跳转核销订单
			goOrderVF(){
				uni.navigateTo({
					url:'/pages/my/verification/orderVerification'
				})
			},
			// 跳转核销详情
			goDetail(){
				uni.navigateTo({
					url:'/pages/my/verification/verificationDetail'
				})
			},
			// 扫码
			scanCode(){
				uni.scanCode({
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	$pageColor:#F9F9F9;
	$bgColor:#FFFFFF;
	
	// flex布局居中对齐
	@mixin flexlayout {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.verification {
		height: 100%;
		background: $pageColor;
	}
	// ::v-deep .segmented-control__item{
	// 	justify-content: center !important;
	// 	margin: 0 30rpx;
	// }
		
	.nav {
		height: 216rpx;
		width: 750rpx;
		background: $bgColor;
		box-shadow: 0px 4rpx 8rpx 0px rgba(0,0,0,0.04);
		border-radius: 0px 0px 16rpx 16rpx;
		.navbox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 30rpx;
			box-sizing: border-box;
			margin-bottom: 15rpx;
			// 搜索
			.search {
				height: 124rpx;
				width: 614rpx;
				background-color: $bgColor;
				@include flexlayout;
			
				::v-deep .u-input {
					width: 690rpx !important;
					height: 68rpx !important;
					background: #F1F1F1;
					border-radius: 74rpx;
				}
			
				::v-deep .u-input__content__field-wrapper {
					padding-left: 36rpx;
				}
				::v-deep .u-input__content__field-wrapper__field{
					color:#999999 !important;
					font-size: 28rpx !important;
				}
			}
		}
		.segmented {
			width: 750rpx;
			box-sizing: border-box;
			//菜单切换
			.tab_nav {
				width: 750rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding:0 30rpx;
				font-family: PingFang-SC-Heavy, PingFang-SC;
			}
		
			.tab_nav .navTitle {
				@include flexlayout()
				width: 128rpx;
				flex: none;
				height: 28rpx;
				font-size: 32rpx;
				color: #666;
				position: relative;
			}
		
			.active {
				color: #D9A94D;
				font-weight: bold;
				box-sizing: border-box;
				&::after {
					display: inline-block;
					content: '';
					width: 48rpx;
					height: 12rpx;
					background: linear-gradient(90deg, #F3D69F 0%, #D9A94D 100%);
					border-radius: 6px;
					position: absolute;
					bottom: -28rpx;
					left: 42rpx;
				}
			}
		}
	}
	.card{
		margin-top: 24rpx;
		// width: 750rpx;
		// height: 426rpx;
		background: $bgColor;
		border-radius: 16rpx;
		padding:32rpx 28rpx 24rpx 28rpx;
		box-sizing: border-box;
		.toptitle{
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang-SC-Bold, PingFang-SC;
			font-weight: bold;
			color: #080F18;
		}
		.shopCard{
			margin-top: 28rpx;
			width: 694rpx;
			height: 164rpx;
			background: #F4F5F6;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			
			image{
				width: 132rpx;
				height: 132rpx; 
				margin-left: 16rpx;
				display: inline-block;
				border-radius: 12rpx;
			}
			.name{
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #080F18;
				display: block;
			}
			.tag{
				font-size: 24rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #666666;
			}
		}
		.points{
			display: flex;
			justify-content: flex-end;
			align-items: center;
			margin-top: 30rpx;
			.totalName{
				font-size: 22rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #080F18;
				margin-right: 10rpx;
			}
			.totalContent{
				font-size: 30rpx;
				font-family: PingFang-SC-Heavy, PingFang-SC;
				font-weight: 800;
				color: #080F18;
			}
		}
		.btn{
			width: 170rpx;
			height: 60rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			border: 2rpx solid #D0D0D0;
			margin-left: 524rpx;
			margin-top: 15rpx;
			@include flexlayout()
			text{
				font-size: 26rpx;
				font-family: PingFang-SC-Medium, PingFang-SC;
				font-weight: 500;
				color: #080F18;
			}
		}
	}
	.home-bottom {
		padding-top: 80rpx;
		background-color: #f9f9f9;
	}
</style>
