<template>
	<view class="common-page">
		<image :src="bgUrl" style="width: 100%; height: 252rpx" mode="aspectFill">
		</image>
		<view class="display-flex-content-center">
			<image src="https://work.hkmop.com/static/imgs/pt_title.png" style="width: 432rpx; height: 95rpx"
				mode="aspectFill">
			</image>
		</view>
		<view class="list-box">
			<CommercePart :data="data"></CommercePart>
		</view>
	</view>
</template>

<script>
	import CommercePart from "@/components/CommercePart.vue";
	import {
		getAdData
	} from '@/common/api/home.js'
	import {
		getPointsGoodsList
	} from '@/common/api/good.js'
	export default {
		components: {
			CommercePart
		},
		data() {
			return {
				pageOptions: {},
				bgUrl: '',
				data: [],
				page: 1,
				pageSize: 6,
				total: 0
			}
		},
		onLoad(options) {
			this.pageOptions = options
			this.getBanner()
			this.getData(true)
		},
		onReachBottom() {
			this.getData()
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			let userInfo = uni.getStorageSync('userInfo')
			userInfo = userInfo && JSON.parse(userInfo) || {}
			let params = {}
			if (userInfo.id) {
				params = {
					id: userInfo.id
				}
			}
			let configs = uni.getStorageSync('configs') || {}
			return {
				title: configs.shop_share_title,
				path: `/subPages/pointsZone/pointsZone${this.$stringPageOptions(params)}`
			}
		},
		onShareTimeline() {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			let userInfo = uni.getStorageSync('userInfo')
			userInfo = userInfo && JSON.parse(userInfo) || {}
			let params = {}
			if (userInfo.id) {
				params = {
					id: userInfo.id
				}
			}
			let configs = uni.getStorageSync('configs') || {}
			return {
				title: configs.shop_share_title,
				path: `/subPages/pointsZone/pointsZone${this.$stringPageOptions(params)}`
			}
		},
		methods: {
			getBanner() {
				getAdData({
					pstn_id: 4
				}).then(res => {
					this.bgUrl = res.data.length && res.data[0].pic
				})
			},
			getData(initFlag) {
				if (!initFlag) {
					if (this.page * this.pageSize < this.total) {
						this.page++
					} else {
						return
					}
				} else {
					this.page = 1
					this.total = 0
					this.data = []
				}
				const sendData = {
					pageSize: this.pageSize,
					page: this.page
				}
				getPointsGoodsList(sendData).then(res => {
					this.data = this.data.concat(res.data.list)
					this.total = res.data.page.total
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.common-page {
		background-color: #F39800;
		height: 100vh;
		// overflow-y: auto;

		.list-box {
			padding: 20rpx 20rpx 30rpx;
		}
	}
</style>