<template>
	<view class="normal-login-container">
		<view class="title-content">
			<text class="title">哈密市重点项目<br>建设及工作可视<br>化管理平台</text>
		</view>

		<view class="login-form-content">
			<view class="welcome-text" @click="goToLogin()">
				<u-icon name="arrow-left" color="#C6C6CD" size="26"></u-icon>
				<text>更换服务地址</text>
			</view>

			<view class="item-text">输入新的服务地址</view>
			<view class="input-item flex align-center">
				<input v-model="serverAddress" class="input" type="text" placeholder="不填写将使用系统默认地址" maxlength="30" />
			</view>

			<button class="login-btn cu-btn block bg-blue lg round" @click="setServerAddress()">设置</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";

	import {
		onLoad,
	} from "@dcloudio/uni-app"

	function goToLogin() {
		uni.navigateBack({})
	}

	let serverAddress = ref(null)

	function setServerAddress() {
		try {
			uni.setStorageSync('serverAddress', serverAddress.value)
			uni.showToast({
				title: "更改成功，即将重启。",
				icon: "error",
				duration: 2000
			})
			setTimeout(() => {
				plus.runtime.restart();
				// uni.reLaunch({
				// 	url: '/pages/login/index'
				// })
			}, 2000)
		} catch {
			uni.showToast({
				title: "设置服务地址失败。",
				icon: "error",
				duration: 2000
			})
		}
	}

	onLoad(() => {
		serverAddress.value = uni.getStorageSync('serverAddress');
	})
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #EAF0FA;
	}

	.normal-login-container {
		position: relative;
		width: 100%;
		height: 100%;
		background: linear-gradient(108deg, #192DE8 0%, #1DA0FF 53%, #84D8FF 100%);

		.title-content {
			width: 100%;
			height: 46%;
			z-index: 1;
			background: url('@/static/login_bg.png');
			background-size: 100% 100%;

			.title {
				position: absolute;
				top: 8.5%;
				left: 7.4%;
				font-size: 52rpx;
				font-weight: 700;
				color: #FFFFFF;
			}
		}

		.login-form-content {
			position: absolute;
			top: 32%;
			left: 0;
			width: 100%;
			height: 68%;
			padding: 40rpx 7%;
			background-color: #fff;
			border-radius: 40rpx 40rpx 0rpx 0rpx;

			.welcome-text {
				display: flex;
				align-items: center;
				margin: 60rpx 0;
				font-size: 44rpx;
				font-weight: 700;
				color: #C6C6CD;

				text {
					margin-left: 20rpx;
				}
			}

			.item-text {
				font-size: 36rpx;
				font-weight: 400;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				color: #343437;
			}

			.input-item {
				height: 90rpx;
				margin: 20rpx auto 30rpx;
				font-size: 28rpx;
				background-color: #f5f6f7;
				border-radius: 16rpx;

				.input {
					width: 100%;
					font-size: 14px;
					line-height: 20px;
					text-align: left;
					padding-left: 15px;
				}
			}

			.forget-pass-item {
				text-align: right;
			}

			.forget-pass {
				color: #1869F6;
				border-bottom: 2rpx solid #1869F6;
			}

			.login-btn {
				margin-top: 50rpx;
				height: 45px;
				background: #1869F6;
				border-radius: 16rpx;
			}

			.xieyi {
				color: #333;
				margin-top: 20px;
			}

			.login-code {
				height: 38px;
				float: right;

				.login-code-img {
					height: 38px;
					position: absolute;
					margin-left: 10px;
					width: 200rpx;
				}
			}
		}
	}
</style>