<template>
	<view class="mg-lr-24">
		<view class="jifen-card mg-bot-46">
			<view class="u-f u-f-jcsb u-f-aic mg-bot-18">
				<view class="u-f u-f-jcfs u-f-aic">
					<image style="width: 76rpx;height: 76rpx;border-radius: 50%;" :src="userPointsInfo.avatarUrl"
						class="mg-right-10">
					</image>
					<text
						class="fs28 fw400 white-color">{{userPointsInfo.nickName ? userPointsInfo.nickName : User.userinfo.phoneNumber}}</text>
				</view>
			</view>
			<view class="jifen-card-content u-f u-f-jcsb u-f-aifs">
				<view class="u-f u-f-fdc u-f-aifs">
					<view class="u-f u-f-jcfs u-f-aic mg-bot-12">
						<text class="mg-right-10 fs24 fw400">当前可用积分</text>
						<text class="wenhao"></text>
					</view>
					<view class="fw700 light-black fs36 mg-bot-30">{{userPointsInfo.availablePoints}}</view>
					<view class="u-f u-f-jcfs u-f-aic fs24">
						<text class="light-gray mg-right-16">即将过期</text>
						<text class="light-black">{{userPointsInfo.expiringSoonPoints}}</text>
					</view>
				</view>
				<view class="u-f u-f-aic u-f-jcfe">
					<image style="width: 144rpx;height: 144rpx;" :mode="'widthFix'" src="../../static/common/jifen.png">
					</image>
				</view>
			</view>
		</view>

		<view class="mg-bot-20">
			<common-title :msg="'积分商城'"></common-title>
		</view>

		<view class="product-list u-f u-f-fww">
			<view class="product-wrap u-f u-f-aic u-f-jcsb u-f-fww" v-for="(item,index) in pointsGoodsList" :key="index"
				@click="goPrductDetail(item)">
				<view class="product-card u-f u-f-fdc">
					<view class="pc-image u-f u-f-jcc u-f-aic">
						<image style="width: 100%;height: 100%;border-radius: 20rpx 20rpx 0rpx 0rpx;"
							:mode="'aspectFill' " :src="item.pointsGoodsImg">
						</image>
					</view>
					<view style="padding: 20rpx;">
						<view class="pc-desc fw400 fs28 two-line-ellipsis">{{item.goodsName}}</view>
						<view class="pc-price">
							<text class="fs28 fw600">{{item.price}}</text>
						</view>
					</view>

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

<script>
	import commonTitle from "../.././components/common-title/common-title.vue"
	export default {
		components: {
			commonTitle
		},
		data() {
			return {
				userPointsInfo: {},
				pointsGoodsList: [],
				total: 0,
				pageNum: 1,
				pageSize: 10,

			}
		},

		onShow() {
			this.pageNum = 1
			this.getUserPointsInfo()
			this.getpointsGoodsList()
		},

		onReachBottom() {
			if (this.total > this.pointsGoodsList.length) {
				this.pageNum = this.pageNum + 1
				this.getOrderList(true)
			} else {
				wx.showToast({
					title: '没有更多啦！',
					icon: 'none'
				})
			}
		},

		methods: {

			//积分商城列表
			getpointsGoodsList(flag) {
				this.$http.post('/api/client/pointsRecord/pointsGoodsList', {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
				}).then(res => {
					this.pointsGoodsList = !flag ? res.data.data.rows : this.pointsGoodsList.concat(res.data.data
						.rows)
					this.total = res.data.data.total

				})

			},



			//用户积分详情
			getUserPointsInfo() {
				this.$http.post('/api/client/pointsRecord/getUserPointsInfo').then(res => {
					this.userPointsInfo = res.data.data
				})
			},


			goPrductDetail(item) {
				uni.navigateTo({
					url: '/pagesE/home-jifen-detail/home-jifen-detail?pointsGoodsId=' + item.id + '&goodsId=' +
						item.goodsId
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FAFBFF;
	}
</style>

<style lang="scss" scoped>
	.jifen-card {
		padding: 18rpx 12rpx 12rpx 12rpx;
		background: linear-gradient(92deg, #FF4502 0%, #FF8903 100%);
		border-radius: 18rpx 18rpx 18rpx 18rpx;

		.jifen-card-content {
			background-color: #FFF6EE;
			padding: 20rpx 18rpx 38rpx 18rpx;
			border-radius: 10rpx;
		}
	}

	.card-item {
		padding: 20rpx;
		flex: calc(50% - 62rpx);
		max-width: calc(50% - 62rpx);
		margin-right: 22rpx;

		&:nth-child(2n) {
			margin-right: 0;
		}
	}

	.product-list {
		margin: 0 24rpx;

		.product-wrap {
			width: calc(50% - 22rpx);
			margin-bottom: 20rpx;
			margin-right: 22rpx;

			&:nth-child(2n) {
				margin-right: 0;
			}

			.product-card {
				flex: 1;
				border-radius: 20rpx;
				background-color: #ffffff;

				.pc-image {
					width: 100%;
					height: 300rpx;
				}

				.pc-desc {
					color: #333333;
				}

				.pc-price {
					margin-top: 10rpx;
					color: #FF4502;
				}
			}
		}
	}
</style>