<template>
	<view class="content">
		<view class="head">
			<view class="user-info">
				<up-image :show-loading="true" :src="src" width="100rpx" height="100rpx" shape="circle"></up-image>
				<text style="margin-left: 42rpx;font-size: 32rpx;font-weight: bold;">{{mobile}}</text>
			</view>

			<view class='money'>
				<view style="color: #7B5232;font-size:24rpx;display: flex;align-items: center;width: 90vw;">
					<text>账户余额(元)</text>
					<text style="font-size:52rpx;margin-left: 20rpx;">{{now_money}}</text>
				</view>
				<view @click="navgo('/pages/gift/index')" class=""
					style='height: 52rpx;width: 148rpx;color: white;background-color: #7B5232;border-radius: 30rpx;line-height: 52rpx;text-align: center;'>
					购买
				</view>
			</view>
		</view>
		<view class="detail">
			<view style="font-weight: bold;font-size: 32rpx;">
				账户详情
			</view>
			<view style="margin:16rpx 0 30rpx 0;color: #777777;">
				<text>
					累计消费 <text style="font-weight: bold;color: black;">￥{{order}}</text>
				</text>
				<text style="margin-left:68rpx ;">
					累计购买 <text style="font-weight: bold;color: black;">￥{{recharge}}</text>
				</text>
			</view>

			<view class="detail-card">
				<view class="" v-for="(item,index) in orderLists" :key='index'>
					<view class="detail-li">
						<up-image :show-loading="true"
							src="https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/b6932202406082138255928.png"
							width="60rpx" height="60rpx" shape="circle" v-if='(+item.amount) >0'></up-image>

						<up-image :show-loading="true" v-else
							src="https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/28097202406082141549267.png"
							width="60rpx" height="60rpx" shape="circle"></up-image>

						<view class="detail-li-r">
							<view class="top" style="margin-bottom: 14rpx;">
								<text>{{item.title}}</text>
								<text style='font-size: 32rpx;font-weight: bold;'
									v-if="item.type=='in'">+{{item.amount}}</text>
								<text style='font-size: 32rpx;font-weight: bold;' v-else>-{{item.amount}}</text>
							</view>
							<view class="top">
								<text style='font-size: 24rpx;'>{{item.create_time}}</text>
								<text style='font-size: 24rpx;'>余额{{item.balance}}元</text>
							</view>
						</view>
					</view>
					<view style="margin: 20rpx 0;">
						<up-line color="#F3F3F3"></up-line>
					</view>
				</view>

			</view>
		</view>

	</view>
</template>

<script setup>
	import {
		userInfoApi,
		chargeListApi,
		capitalCountAPi
	} from "@/api/user.js"
	import {
		onPullDownRefresh
	} from "@dcloudio/uni-app"
	import {
		ref
	} from "vue"
	const src = ref('https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/841c0202406081905268790.png') //
	const now_money = ref(0)
	const mobile = ref('')
	const order = ref(0)
	const recharge = ref(0)
	const getUser = () => {
		userInfoApi().then(res => {
			now_money.value = res.data.now_money
			src.value = res.data.avatar
			mobile.value = res.data.mobile
		})
	}

	const orderLists = ref([])
	const getLists = () => {
		chargeListApi().then(res => {
			orderLists.value = res.data.data
		})
	}


	const getShop = () => {
		capitalCountAPi().then(res => {
			order.value = res.data.order
			recharge.value = res.data.recharge
		})
	}

	const navgo = (url) => {
		uni.navigateTo({
			url
		})
	}

	onPullDownRefresh(() => {
		getUser()
		getLists()
		getShop()
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 2000)
	})

	getUser()
	getLists()
	getShop()
</script>

<style lang='scss'>
	.content {
		width: 710rpx;
		margin: 20rpx auto;
		box-sizing: border-box;
		min-height: 100vh;

		.head {
			height: 272rpx;
			background-size: 100% 100%;
			background-image: url('https://lihai001.oss-cn-chengdu.aliyuncs.com/attach/841c0202406081905268790.png');
			box-sizing: border-box;
			padding: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.user-info {
				display: flex;
				align-items: center;
			}


			.money {
				display: flex;
				align-items: center;



			}
		}

		.detail {
			margin-top: 50rpx;


			.detail-card {
				background-color: white;
				padding: 34rpx 20rpx;
				border-radius: 12rpx 12rpx 0rpx 0rpx;


				.detail-li {
					display: flex;
					align-items: center;
					color: #333333;
					font-size: 30rpx;

					.top {
						display: flex;
						justify-content: space-between;
					}

					.detail-li-r {
						margin-left: 30rpx;
						width: 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
					}
				}
			}
		}

	}
</style>