<template>
	<view class="content">
		<view class="logo">
			<!-- <image style="height:104rpx;width:104rpx" src="/static/czzn-img/login/logo.jpg" mode="aspectFit" /> -->
			<view class="app-name">{{$t('login.e')}}</view>
		</view>
		<view style="margin:0 auto;height:104rpx">
			<u-radio-group v-model="serverForm.type" >
				<!-- #ifndef MP-WEIXIN-->
				<u-radio name="1" :label="$t('base.common.tenant')"></u-radio>
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN-->
				<u-radio name="2" :label="$t('base.common.cloud')"></u-radio>
				<!-- #endif -->
			</u-radio-group>
		</view>
		<view class="inp_box">
			<view class="inp_box">
				 <view @click="showPopup('popupServicePrefixName')" style="padding-left:10px">{{serverForm.prefix}}://
				</view>
				<input type="text" class="ip" v-model.trim="serverForm.ip" :placeholder="this.$t('login.ip')" />
				<input type="text" class="port" v-model.trim="serverForm.port" :placeholder="this.$t('login.port')" />
			</view>
		</view>
		<view  class="btn-wrap">
			<button class="bind-btn" @click="submit('serverForm')">{{$t('base.common.submit')}}
			</button>
		</view>
		<PopupSelect ref="popupServicePrefixName" :hasSearch='false' style="width:100px" :option="serverPrefixList"
				@onConfirm="onServicePrefixConfirm" />
	</view>
</template>

<script>
	import {
		changeUrl
	} from '../../utils/config.js'
	import PopupSelect from '../../components/popup-select/index'
	export default {
		components: {
			PopupSelect
		},
		data() {
			return {
				time: 0,
				timer: '',
				isGetCode: false,

				option: [{
					text: '',
					value: 1,
				}],
				serverForm: {
					type: "2",
					ip: "",
					prefix: "http",
					port: "",
				},
				serverPrefixList: [{
						value: "http",
						text: "http"
					},
					{
						value: "https",
						text: "https"
					}
				],
			}
		},
		onLoad(options) {
			if (uni.getStorageSync('server')) {
				this.serverForm = uni.getStorageSync('server')
			}
			//<!-- #ifndef MP-WEIXIN-->
			this.serverForm.type='1'
			//<!-- #endif -->
		},
		watch: {
			// "serverForm.type": function(item,oldItem) {
			// 	debugger
			// 	console.log(item,oldItem,this.serverForm.ip)
			// 	if (item == 2) {
			// 		if (this.serverForm.ip=="") {
			// 			this.serverForm.ip = 'https://saas.createtobest.com'
			// 		}
			// 	}
			// 	if(oldItem==2 && item==1){
			// 		this.serverForm.ip=""
			// 	}
			// }
		},
		methods: {
			showPopup(refs) {
				this.$refs[refs].showPicker = true
			},
			onServicePrefixConfirm(value) {
				var name = ''
				if (value.value) {
					name = value.value
				}
				this.serverForm.prefix = name
			},
			// onFormTypeChange(item) {
			// 	console.log("选择的信息为、", item);
			// 	//
			// 	if (item == 2) {
			// 		this.serverForm.ip = 'https://saas.createtobest.com'
			// 	} else {
			// 		if (uni.getStorageSync('serverAddress')) {
			// 			this.serverForm.ip = uni.getStorageSync('serverAddress')
			// 			if (this.serverForm.ip == "https://saas.createtobest.com") {
			// 				this.serverForm.ip = ""
			// 			}

			// 		} else {
			// 			this.serverForm.ip = ""
			// 		}
			// 	}
			// },
			backLogin() {
				changeUrl();
				uni.reLaunch({
					url: "/pages/login/login"

				})
			},
			submit() {
				console.log("输入的信息。", this.serverForm);
				if (!this.serverForm.ip) {
					uni.showToast({
						title: this.$t('login.ipPlaceholder'),
						icon: 'none',
						duration: 2000
					})
					return;
				}
				var address = this.serverForm.prefix + "://" + this.serverForm.ip;
				if (this.serverForm.port) {
					address = address + ":" + this.serverForm.port
				}
				uni.setStorageSync('server', this.serverForm);
				uni.setStorageSync('serverStatus', this.serverForm.type);
				uni.setStorageSync('serverAddress', address);
				uni.setStorageSync('serverPrefix', this.serverForm.type == 1 ? "/admin" : "/ymt");
				this.backLogin();
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		box-sizing: border-box;
		padding: 0rpx 48rpx 80rpx;
		height: 100%;
	}

	/* #endif*/
</style>
<style lang="scss" scoped>
	@import '../../common/css/login.scss';

	.bgc {
		position: absolute;
		height: 77%;
		width: 160%;
		bottom: 0;
		left: -30%;
		z-index: -50;
		background-color: #4680F9;
		border-top-left-radius: 200px;
		border-top-right-radius: 200px;
	}
</style>
