<template>
	<view class="content">
		<view class="header-img">
			<u-image src="/static/hbheader.jpg" width="750" height="578"></u-image>
			<!-- 滚动区域 -->
			<view class="scroll-list" v-if="slist.length">
				<scrollBox :list="slist" bgColor="rgba(250, 224, 188, 0.6)"></scrollBox>
			</view>
			<view class="amount-box">
				{{rewardData?rewardData.rewardAmount:'0.00'}}
				<text>元</text>
			</view>
			<view class="view-gz" @click="showModal = true">查看活动规则>></view>
		</view>
		<view class="list-box">
			<view class="codes flex align_center">
				<view @click="openImg()">
					<u-image :src="hasRedPacket&&hasRedPacket.serviceQrcode" width="160" height="160"></u-image>
				</view>
				<view>
					<view>扫描添加客服微信，领取待发放红包</view>
					<view>点击二维码查看大图，长按识别二维码</view>
				</view>
			</view>
			<view class="tabbox">
				<view class="tabhead flex align_center justify_between">
					<view :class="curTab==0?'active':''" @click="tabChange(0)">所有红包</view>
					<view :class="curTab==1?'active':''" @click="tabChange(1)">已发红包</view>
					<view :class="curTab==2?'active':''" @click="tabChange(2)">待发红包</view>
				</view>
				<swiper class="tablist">
					<swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;">
						<scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
							<view class="totalBar" v-if="rewardData&&curTab==1&&total">
								共<text>{{total}}</text>个红包，合计<text>{{rewardData.paidAmount||0}}</text>元
							</view>
							<view class="totalBar" v-if="rewardData&&curTab==2&&total">
								共<text>{{total}}</text>个红包，合计<text>{{rewardData.unPaidAmount||0}}</text>元
							</view>
							<view class="flex align_center justify_between itemlist" v-for="item in list" :key="item.id">
								<view class="flex align_center">
									<view class="imgs flex align_center">
										<u-icon size="30" color="#fff" name="red-packet"></u-icon>
									</view>
									<view class="txts">
										<view class="txts-name">{{item.orderSourceName}}</view>
										<view class="txts-time">{{item.rewardCreateDate}}</view>
									</view>
								</view>
								<view class="amount">+{{item.totalRewardAmount}}</view>
							</view>
							<view style="padding: 20upx;">
								 <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
								 <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
							</view>
						</scroll-view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<!-- 活动规则 -->
		<u-popup v-model="showModal" closeable mode="center" border-radius="15" width="600rpx">
			<view style="padding: 20rpx;">
				<view style="text-align: center;padding: 20rpx 0pt;">活动规则</view>
				<view style="font-weight: bold;">【活动时间】</view>
				<view style="padding: 10rpx 20rpx;">即日起—2022年12月31日</view>
				<view style="font-weight: bold;">【活动内容】</view>
				<view style="padding: 10rpx 20rpx;">活动期间，凡是通过店内易码通货架取货和小程序下单的用户，即可获得最高百元现金红包。</view>
				<view style="font-weight: bold;">【领取方式】</view>
				<view style="padding: 10rpx 20rpx;">在活动页面，扫码或添加客服微信号，发送“姓名+修理厂名称+手机号+提现金额”，客服会在收到信息后1-3个工作日内，以微信红包的形式发放现金红包，您可在“已发放”“待发放”中查看红包金额。</view>
				<view style="font-weight: bold;">【注意】</view>
				<view style="padding: 10rpx 20rpx;">1．退货或已取消的订单不可领取红包；</view>
				<view style="padding: 10rpx 20rpx;">2．红包不可转让或为他人付款；</view>
				<view style="padding: 10rpx 20rpx;">3．活动仅限实名认证用户才能参与，因微信账号非实名导致用户无法收到和领取红包的，请联系腾讯客服完成实名认证；</view>
				<view style="padding: 10rpx 20rpx;">4．该活动最终解释权归广东易码通数字科技有限公司所有。</view>
				<view style="font-weight: bold;">【声明】</view>
				<view style="padding: 10rpx 20rpx;">广东易码通数字科技有限公司不会以任何理由向用户所要身份证、银行卡账户和密码等相关信息，请注意保护个人隐私。</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import scrollBox from '@/components/scrollBox.vue'
	import { findUserReward, getRewardOrderList, getRewardRollList } from '@/api/rewardRule.js'
	export default {
		components: {
			scrollBox,
		},
		data() {
			return {
				showModal: false,
				rewardData: null, // 奖励信息
				slist:[],
				status: 'loading',
				noDataText: '暂无数据',
				pageNo: 1,
				pageSize: 30,
				total: 0,
				rewardStatus: ['','paid','un_paid'], //un_paid 未发放，paid 已发放
				list: [],
				curTab:'0'
			}
		},
		onLoad(){
			this.getScrollLog()
			this.getUserReward()
			this.getEwardOrder()
		},
		computed: {
			hasRedPacket(){
				return this.$store.state.vuex_rewardRule
			}
		},
		methods: {
			openImg(url){
				uni.previewImage({
					urls:[this.hasRedPacket&&this.hasRedPacket.serviceQrcode||'']
				})
			},
			// 活动奖励信息
			getUserReward(){
				findUserReward().then(res => {
					this.rewardData = res.data
				})
			},
			tabChange(i){
				this.curTab = i
				this.list = []
				this.total = 0
				this.getEwardOrder(1)
				this.getUserReward()
			},
			// 查询列表
			getEwardOrder (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  // 状态条件
			  let params = {
			    pageNo: this.pageNo,
			    pageSize: this.pageSize,
				rewardStatus: this.rewardStatus[this.curTab]
			  }
			  this.status = "loading"
			  getRewardOrderList(params).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(res.data.list || [])
				  }else{
					  _this.list = res.data.list || []
				  }
				  _this.total = res.data.count || 0
				} else {
				  _this.list = []
				  _this.total = 0
				  _this.noDataText = res.message
				}
				_this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
			  })
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getEwardOrder()
				}else{
					this.status = "nomore"
				}
			},
			// 获取上方滚动扫描记录
			getScrollLog(){
				getRewardRollList({pageNo:1,pageSize:1000}).then(res => {
					this.slist = res.data || []
					this.slist.map(item => {
						item.placeText = item.userName + '刚刚得到了'+item.totalRewardAmount+'元 红包奖励'
					})
				})
			},
		}
	}
</script>

<style lang="less">
	.content{
		padding: 0;
		background-color: #fae0bc;
		.header-img{
			position: relative;
			color: #fff;
			.amount-box{
				position: absolute;
				width: 100%;
				text-align: center;
				font-size: 80rpx;
				text{
					font-size: 40rpx;
				}
				top: 50%;
				color: #f5563d;
			}
			.view-gz{
				position: absolute;
				width: 100%;
				text-align: center;
				bottom: 45rpx;
				font-size: 30rpx;
			}
			.scroll-list{
				width:100%;
				position: absolute;
				left:10rpx;
				top:-10rpx;
			}
		}
		.list-box{
			padding: 30rpx;
			.codes{
				margin-bottom: 40rpx;
				> view{
					&:first-child{
						padding: 10rpx;
						background-color: #fff;
					}
					&:last-child{
						padding: 0 20rpx;
						> view{
							padding: 10rpx 0;
							font-size: 26rpx;
						}
					}
				}
			}
			.tabbox{
				background-color: #fff5e7;
				box-shadow: 0 0 10rpx #e75115;
				border-radius: 15rpx;
				.tabhead{
					border-bottom: 1rpx solid #f0b675;
					> view{
						width: 30%;
						color: #5a4f49;
						padding: 20rpx 0;
						text-align: center;
					}
					.active{
						color: #e7463c;
						border-bottom: 4rpx solid #e7463c;
						font-weight: bold;
					}
				}
				.tablist{
					height: 70vh;
					padding: 20rpx 0;
					.itemlist{
						border-bottom: 1rpx solid #fff;
						padding: 20rpx 30rpx;
						.txts-name{
							color: #e7463c;
						}
						.txts-time{
							font-size: 24rpx;
							color: #666;
							margin-top: 10rpx;
						}
						.amount{
							color: #e7463c;
							font-weight: bold;
							font-size: 32rpx;
						}
					}
					.txts{
						padding:0 20rpx;
					}
					.imgs{
						background-color: #fe9790;
						border-radius: 100rpx;
						padding: 10rpx;
						width: 50rpx;
						height: 50rpx;
						text-align: center;
					}
				}
				.totalBar{
					background-color: #fff;
					padding: 10rpx 20rpx;
					border-radius: 60rpx;
					margin: 0 30rpx;
					color: #e7463c;
				}
			}
		}
	}
</style>
