<template>
	<view class="qrcode-page">
		<!-- 自定义导航栏 -->
		<view class="custom-navbar" :style="{ paddingTop: statusBarHeight + 'px' }">
			<view class="navbar-content">
				<view class="nav-back" @click="goBack">
					<image class="back-icon" src="/static/ic_back.png" mode="aspectFit"></image>
				</view>
				<text class="navbar-title">客服二维码</text>
				<view class="nav-placeholder"></view>
			</view>
		</view>
		<view :style="{ height: (statusBarHeight + 44) + 'px' }"></view>
		<view class="page-body">
			<view v-if="qrcodeUrl" class="qrcode-card">
				<text class="qrcode-title">客服二维码</text>
				<image class="qrcode-image" :src="qrcodeUrl" mode="aspectFit" @click="previewImage"></image>
				<text class="qrcode-tip">长按识别二维码联系客服</text>
			</view>
			<view v-else class="empty-tip">
				<text>暂无客服二维码</text>
			</view>
		</view>
	</view>
</template>

<script>
import { getQrcode } from '../../utils/api'

export default {
	data() {
		return {
			qrcodeUrl: '',
			statusBarHeight: 0
		}
	},
	onLoad() {
		const sysInfo = uni.getSystemInfoSync()
		this.statusBarHeight = sysInfo.statusBarHeight || 0
		this.loadQrcode()
	},
	methods: {
		goBack() { uni.navigateBack() },
		/** 加载客服二维码 */
		async loadQrcode() {
			try {
				const res = await getQrcode()
				this.qrcodeUrl = res?.value || res?.url || ''
			} catch (e) {
				// 静默处理
			}
		},
		/** 预览图片 */
		previewImage() {
			if (!this.qrcodeUrl) return
			uni.previewImage({ urls: [this.qrcodeUrl] })
		}
	}
}
</script>

<style scoped>
/* 自定义导航栏 */
.custom-navbar {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	z-index: 999;
	background: #FFB700;
}
.navbar-content {
	height: 44px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 20rpx;
}
.nav-back {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}
.back-icon {
	width: 40rpx;
	height: 40rpx;
}
.navbar-title {
	font-size: 34rpx;
	font-weight: bold;
	color: #363636;
}
.nav-placeholder {
	width: 60rpx;
}
.qrcode-page {
	height: 100vh;
	background-color: #f5f5f5;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.page-body {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 40rpx;
}

.qrcode-card {
	background-color: #ffffff;
	border-radius: 20rpx;
	padding: 60rpx 40rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 100%;
}

.qrcode-title {
	font-size: 34rpx;
	color: #333333;
	font-weight: bold;
	margin-bottom: 40rpx;
}

.qrcode-image {
	width: 400rpx;
	height: 400rpx;
	margin-bottom: 30rpx;
}

.qrcode-tip {
	font-size: 26rpx;
	color: #999999;
}

.empty-tip {
	text-align: center;
}

.empty-tip text {
	font-size: 28rpx;
	color: #999999;
}
</style>
