<template>
	<view class="centenr">
		<view class="Candywrapper">
			<view class="top-box" @click="goIntegral">

				<view class="">积分余额</view>
				<view class="d-s">{{cardBalance.points || 0}}<u-icon name="arrow-right"></u-icon> </view>
			</view>
			<view class="f-box" v-for="(item,index) in integralGiftList" :key="index" @click="goDetails(item)">
				<view class="f-top">{{item.storeName}}可用</view>
				<view class="f-bs">
					<image v-if="item.coverImage" :src="baseUrl+item.coverImage" mode="aspectFit"
						style="width: 60px; height: 60px; "></image>
					<image v-else src="../../static/logo.png" style="width: 60px; height: 60px; "></image>
					<view class="r-box">
						<view class="">
							<view class="m_">{{item.giftName}}</view>
							<view class="p_" >{{item.goodsName || ''}}</view>
							<view class="q_">{{item.giftType}}</view>
						</view>
						<view class="">
							<view class="an_">
								{{item.exchangePoints}}积分
							</view>
							<u-line-progress :percentage="50" :showText="false" height="6"
								activeColor="#FA6400"></u-line-progress>
							<view class="hui_">券已领{{item.receiveRatio}}</view>
						</view>

					</view>
				</view>
			</view>

			<u-empty v-if="integralGiftList.length == 0" style="margin: 5px auto;" mode="data"
				icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import config from '@/config'
	import request from '../../utils/request'
	export default {
		data() {
			return {
				baseUrl: config.baseUrl,
				query: {
					chainStoreId: '',
					couponType: '',
					useStatus: 0,
					pageNo: 1,
					pageSize: 10
				},
				cardBalance: {},
				queryParam: {
					storeId: uni.getStorageSync('storeId'),
					status: '启用',
					categoryId: '',
					giftName: '',
					deliveryMethod: '',
					page: 1,
					pageSize: 30
				},
				integralGiftList: [],
				total: 0
			}
		},
		onPullDownRefresh() {
			//下拉刷新
			this.queryParam = {
				storeId: uni.getStorageSync('storeId'),
				status: '启用',
				categoryId: '',
				giftName: '',
				deliveryMethod: '',
				page: 1,
				pageSize: 30
			}
			this.getIntegralGiftList()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// 触底加载
			if (this.queryParam.page >= this.total) {
				uni.showToast({
					title: '没有下一页数据',
					icon: 'none'
				})
			} else {
				this.queryParam.page++
				this.getIntegralGiftList()
			}
		},
		onShow() {
			this.query.chainStoreId = uni.getStorageSync('chainStoreId');
			this.getUserBalance()
			this.getIntegralGiftList()
		},
		methods: {

			// 获取积分商城列表
			getIntegralGiftList() {
				request({
					url: 'business/integral/integralGift/queryByPageByStoreId',
					method: 'get',
					params: this.queryParam
				}).then((res) => {
					if (res.code == 200) {
						this.integralGiftList = res.data.records
						this.total = res.data.total
						console.log(res, 100);
					}
				})
			},
			// 获取余额信息
			getUserBalance() {
				request({
					url: '/business/userManager/user/getUserBalanceApplet',
					method: 'get',
					params: this.query
				}).then(res => {
					if (res.code == 200) {
						this.cardBalance = res.data
					}
				})
			},
			goIntegral() {
				uni.navigateTo({
					url: '/pagesMy/integral/integral'
				})
			},
			goDetails(data) {
				uni.navigateTo({
					url: '/pagesHome/PointsRedemption/details?giftId='+data.id
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.centenr {
		width: 100%;
		height: 100vh;
		background: #F9F9F9;
	}

	.Candywrapper {
		background: #F9F9F9;
		box-sizing: border-box;
		padding: 10px;
	}

	.top-box {
		width: 100%;
		box-sizing: border-box;
		padding: 10px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;

	}

	.d-s {
		display: flex;
		align-items: center;

	}

	.f-box {
		width: 100%;
		box-sizing: border-box;
		padding: 10px;
		background: #fff;
		margin: 10px auto;
		border-radius: 4px;
	}

	.f-top {
		box-sizing: border-box;
		padding: 5px 0px;
		border-bottom: 1px dashed #eee;
		margin-bottom: 15px;
	}

	.f-bs {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.r-box {
		width: 80%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.m_ {
		font-size: 16px;
		color: #333333;
		font-weight: bold;
		margin-bottom: 5px;
	}

	.p_ {
		font-size: 12px;
		color: #666666;
	}

	.q_ {
		font-size: 12px;
		color: #E02020;
	}

	.an_ {
		width: 80px;
		height: 25px;
		background: #FA6400;
		border-radius: 4px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		margin-bottom: 5px;
	}

	.hui_ {
		font-size: 10px;
		color: #666666;
	}
</style>