<template>
	<view>
		<view class="empty-page" v-if="!isOpenMember">
			<image src="../../static/icon/vip.png" mode=""></image>
			<text>没有会员中心信息</text>

			<view class="cu-btn btn-bg-color round" style="width: 48%;height: 80rpx;position: fixed;bottom: 20%;">
				<u-icon name="plus-circle" size="40"></u-icon>
				<text class="margin-left-10 text-lg">创建会员中心</text>
			</view>
		</view>

		<block v-else>
			<view class="top-menu">
				<view class="">
					<text>{{detail.memberCount}}</text>
					<text>会员数量</text>
				</view>

				<view class="">
					<text>{{detail.totalPointValue}}</text>
					<text>积分总价值</text>
				</view>
			</view>
			<view class="padding-20 text-bold text-xl">
				<text>会员列表</text>
			</view>

			<view class="card">
				<view class="flex">
					<view class="area1 title">
						会员名称
					</view>
					<view class="area2 title">
						积分数
					</view>
					<view class="area3 title">
						价值
					</view>
				</view>

				<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
					:down="downOption" :up="upOption">
					<view class="item" v-for="(item,index) in dataList" :key="index">
						<view class="area1 flex text-bold">
							<image class="img-avatar" :src="item.avatar">
							</image>
							<view class="center padding-left-10">
								<text>{{item.nickName}}</text>
							</view>
						</view>
						<view class="area2 center text-bold text-lg"
							style="justify-content: flex-start;margin-left: 10rpx;color: #F37A1E;">
							<image class="img-points" src="../../static/icon/points-value.png"></image>
							<text class="margin-left-10">{{item.pointTotal | numFilter}}</text>
						</view>

						<view class="area3  center text-lg">
							<text class="text-price text-bold">{{item.pointValue | numFilter}}</text>
						</view>
					</view>
				</mescroll-body>
			</view>
		</block>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				isOpenMember: false,
				detail: {},
				dataList: [],

				downOption: {
					use: false,
					auto: false // 不自动加载
				},
				upOption: {
					use: false,
					auto: false // 不自动加载
				},
			}
		},
		onLoad() {
			this.fetchShopDetail()
		},
		filters: {
			numFilter(value) {
				let realVal = "";
				if (!isNaN(value) && value !== "") {
					// 截取当前数据到小数点后两位,改变toFixed的值即可截取你想要的数值
					realVal = parseFloat(value).toFixed(2);
				} else {
					realVal = "--";
				}
				return realVal;
			},
		},

		methods: {
			fetchShopDetail() {
				let params = {
					id: this.vuex_mallId
				}
				this.$api.mall.detail(params).then(res => {
					if (res.data.isOpenMember == 1) {
						this.isOpenMember = true
						this.detail = res.data
						//加载会员中心
						this.useOption()
					}
				})
			},
			downCallback() {
				setTimeout(() => {
					this.mescroll.resetUpScroll();
				}, 800)
			},
			useOption() {
				this.downOption = {
					use: true,
					auto: true
				}
				this.upOption = {
					use: true,
					auto: true
				}
			},
			upCallback(mescroll) {
				let params = {
					mallId: this.vuex_mallId,
					current: mescroll.num,
					size: mescroll.size,
				}
				try {
					this.$api.memberCenter.list(params).then(res => {
						let data = res.data.records
						let total = res.data.total
						mescroll.endBySize(data.length, total);
						if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
						this.dataList = this.dataList.concat(data); //追加新数据
					})
				} catch (e) {
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn-bg-color {
		background-color: #EE9230;
		color: #FFFFFF;
	}

	.empty-page {
		height: 50vh;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		color: #CCCCCC;

		image {
			width: 120rpx;
			height: 120rpx;
			margin-bottom: 20rpx;
		}
	}

	.top-menu {
		border-radius: 20rpx;
		margin: 30rpx 20rpx;
		padding: 50rpx;
		display: flex;
		justify-content: space-around;
		background-image: linear-gradient(to right, #272A46, #30355D);

		view {
			display: flex;
			flex-direction: column;
			text-align: center;

			text:first-child {
				margin-bottom: 10rpx;
				color: #FFFFFF;
				font-weight: 800;
				font-size: 40rpx;
			}

			text:last-child {
				font-size: 26rpx;
				color: #D0D4EE;
			}
		}
	}

	.card {
		width: 100%;
		background-color: #FFFFFF;
		padding: 30rpx;
		font-size: 26rpx;

		.text-area {
			display: flex;
			justify-content: flex-start;
			align-items: center;
		}

		.title {
			padding-left: 20rpx;
			color: #666666;
		}

		.area1 {
			width: 50%;
		}

		.area2 {
			width: 30%;
		}

		.area3 {
			width: 20%;
		}

		.item {
			padding: 30rpx 20rpx;
			display: flex;
			border-bottom: 1rpx solid #DDDDDD;

			.img-avatar {
				width: 70rpx;
				height: 70rpx;
				border-radius: 50%;
			}

			.img-points {
				width: 35rpx;
				height: 35rpx;
			}
		}
	}
</style>
