<template>
	<view class="page">
		<!-- 其他功能 -->
		<block v-for="(item, index) in list" :key="index">
			<uni-card :border="false" :is-shadow="false" :padding="0">
				<uv-cell :title="item.remark" :label="item.createTime" :value="`-${item.money}`" :cellStyle="{ padding: '10px 0' }" :border="false"></uv-cell>
			</uni-card>
		</block>
		<!-- 登录组件 -->
		<ws-login ref="login" :logo="logo" @done="reload" />
	</view>
</template>

<script>
import * as Api from '@/api/user/balance-log';
import { openUrl } from '@/utils/common';
import { useUserStore } from '@/store/modules/user';

const userStore = useUserStore();

export default {
	data() {
		return {
			userCardId: 0,
			list: [],
			isLogin: false,
			logo: uni.getStorageSync('app_logo'),
		};
	},
	onLoad(o) {
		this.userCardId = o.id;
		this.reload();
	},
	methods: {
		async reload(e) {
			const app = this;
			const { userCardId } = this;
			// 当前登录用户信息
			const userInfo = await userStore.fetchUserInfo();
			if (Object.keys(userInfo).length > 0) {
				app.isLogin = true;
				app.userInfo = userInfo;
			} else {
				app.isLogin = false;
				app.$refs.login.open('bottom');
				return false;
			}

			// 获取会员卡使用记录
			Api.pageUserBalanceLog({}).then((res) => {
				app.list = res.list;
			});
		},
		navTo(item) {
			if (!this.isLogin) {
				this.$refs.login.open('bottom');
				return false;
			}
			openUrl(item);
		}
	}
};
</script>
<style>
page {
	background-size: 100%;
	background-repeat: no-repeat;
	background-color: #f0f2f5;
	width: 750rpx;
	overflow-x: hidden;
}
</style>
<style lang="scss">
</style>
