<template>
	<!-- <web-view src="http://niunian.hk.fq99.top"></web-view> -->
	<view class="loginPage">
		<!-- <view class="barBox" :style="{'height':systemInfo.statusBarHeight+'px'}"> -->
		<view class="barBox">
		</view>
		<view class="loginBox">
			<view class="loginTitle">
				<image class="loginLogo" src="@/static/login/logo.pic.jpg" mode="heightFix"></image>
				智慧工地服务平台
			</view>
			<view class="btns">
				<view class="user feedback" @click="goto('user')">我是用户</view>
				<view class="supplier feedback black" @click="goto('supplier')">我是供应商</view>
			</view>
		</view>
		<!-- <view class="bottomTitle" @click="showModal=true">
			云服务器设置
		</view> -->
		<!-- <view class="modalBox" v-show="showModal">
			<view class="modalContent">
				<view class="modalTitle">
					云服务器设置
					<uni-icons @click="showModal=false" class="closeImg" type="closeempty" size="26"></uni-icons>
				</view>
				<form @submit="saveServerData">
					<view class="uni-form-item">
						<input class="uni-input" name="ipPort" v-model="ipPort"
							placeholder="格式为http://127.0.0.1:8080" />
					</view>
					<button form-type="submit" type="primary" class="btn">保存</button>
				</form>
			</view>
		</view> -->
	</view>
</template>

<script>
	import Vue from 'vue'
	import uniIcons from "@/components/uni-icons/uni-icons.vue"
	export default {
		components: {
			uniIcons
		},
		data() {
			return {

				ipPort: '',
				showModal: false,
				systemInfo: {
					statusBarHeight: 0
				},
				clientid: ''
			}
		},
		onLoad() {
			let _this = this;
			// #ifdef APP-PLUS
			// add:添加登录CID绑定功能  实现推送 2022年4月20日 10:47:41 罗劲章// add:添加登录CID绑定功能  实现推送 2022年4月20日 10:47:41 罗劲章
			plus.push.getClientInfoAsync((info) => {
				const clientid = info["clientid"];
				console.log(clientid, "cidcidcidcidcid")

				_this.clientid = clientid

			});
			// #endif
			if (uni.getStorageSync('userInfo')) {
				let userInfo = JSON.parse(uni.getStorageSync('userInfo'));
				let {
					accountType
				} = userInfo;
				if (accountType == 5 || accountType == 6 || accountType == 10) {
					// 用户端
					uni.reLaunch({
						url: '/pages/projectEnd/projectIndex/projectIndex'
					})
				} else if (accountType == 11) {
					// 供应商
					uni.reLaunch({
						url: '/pages/supplier/supplier'
					})
				} else {
					// 集团
					uni.redirectTo({
						url: '/pages/projectManage/projectManage'
					})
				}
			}
		},
		mounted() {
			this.systemInfo = uni.getStorageSync('systemInfo')
			uni.setStorageSync('language', 'zh_CN')
			if (uni.getStorageSync('account')) {
				this.account = uni.getStorageSync('account')
				this.password = uni.getStorageSync('password')
			}
			if (uni.getStorageSync('ipPort')) {
				this.ipPort = uni.getStorageSync('ipPort');
				// let val={
				// 	detail:{
				// 		value:{
				// 			account:this.account,
				// 			password:this.password
				// 		}
				// 	}
				// }
				// this.formSubmit(val);

			} else {
				// this.ipPort='183.95.84.54:9500'
				// uni.setStorageSync('ipPort',this.ipPort)
			}


		},
		methods: {
			goto(type) {
				// 跳转用户和供应商注册页面 存储选择的类型
				uni.setStorageSync("Type", type);
				uni.navigateTo({
					url: `/pages/login/compatibleLogin?type=${type}`
				})
			},
			saveServerData(e) {
				uni.setStorageSync('ipPort', e.detail.value.ipPort)
				Vue.prototype.url_config = uni.getStorageSync('ipPort') + '/'
				getApp().globalData.siteUrl = uni.getStorageSync('ipPort') + '/'
				this.showModal = false
			},
			formSubmit(e) {
				// console.log(e)
				var json = {
					account: e.detail.value.account,
					password: e.detail.value.password,
					clientId: this.clientid
				}

				this.sendRequest({
					url: "xmgl/base/login",
					data: json,
					method: "POST",
					success: (res) => {
						// #ifdef APP-PLUS
						// add:添加登录CID绑定功能  实现推送 2022年4月20日 10:47:41 罗劲章// add:添加登录CID绑定功能  实现推送 2022年4月20日 10:47:41 罗劲章
						plus.push.getClientInfoAsync((info) => {
							const cid = info["clientid"];
							// console.log(cid,"cidcidcidcidcid")
							// const cid = "f4b3246189fc051c5875a35e198ca223";
							const userId = res.result.userId;
							const jsonParams = {
								clientId: cid,
								alias: userId
							}
							//触发绑定请求 
							this.sendRequest({
								url: "xmgl/push/bindAlias", //替换掉后端彭定生的接口
								data: jsonParams,
								method: "POST",
							})
						});
						// #endif

						uni.setStorageSync('account', e.detail.value.account);
						uni.setStorageSync('password', e.detail.value.password);
						uni.setStorageSync('userInfo', JSON.stringify(res.result));
						if (res.result.accountType == 5 || res.result.accountType == 6 || res.result
							.accountType == 10) {
							if (res.result.styleType == 1) {
								uni.redirectTo({
									url: '/pages/projectEnd/projectIndex/projectIndex'
								})
							} else {
								uni.redirectTo({
									url: '/pages/projectEnd/projectIndex/projectIndex'
								})
							}
							// uni.redirectTo({
							// 	url: '/pages/workstation/workstationIndex/workstationIndex'
							// })
						} else {
							uni.redirectTo({
								url: '/pages/projectManage/projectManage'
								// url: '/pages/projectEnd/projectIndex/projectIndex'
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.loginPage {
		position: relative;
		height: 100vh;
		color: $uni-text-color;
		background: url("@/static/WechatIMG15.jpg");
		background-size: cover;
	}

	.feedback {
		&:active {
			position: relative;
			overflow: hidden;

			&::after {
				content: "";
				position: absolute;
				left: 0;
				top: 0;
				right: 0;
				bottom: 0;
				background-color: rgba(255, 255, 255, .08);
			}
		}

		&.black {
			&:active {
				&::after {
					background-color: rgba(0, 0, 0, .05);
				}
			}
		}
	}

	.loginBox {
		padding: 100px 0 0;
	}

	.loginTitle {
		font-size: 30px;
		font-weight: 500;
		display: flex;
		align-items: center;
		justify-content: center;

		.loginLogo {
			height: 60rpx;
			width: auto;
			margin-right: 10rpx;
		}
	}

	.btns {
		padding: 40rpx 30rpx;
		position: fixed;
		left: 20rpx;
		right: 20rpx;
		bottom: 50rpx;

		>view {
			padding: 20rpx 0;
			border-radius: 8rpx;
			text-align: center;
			margin-top: 60rpx;
		}

		.user {
			background-color: #5e81ee;
			color: #fff;
		}

		.supplier {
			background-color: #f7f8f9;
			color: #333;
		}
	}

	.uni-input {
		border-bottom: 1px solid #ddd;
		padding: 10px 15px;
		border-radius: 3px;
		margin-bottom: 25px;
		font-size: 16px;
	}

	.btn {
		margin-top: 40px;
	}

	.bottomTitle {
		position: fixed;
		bottom: 20px;
		left: 50%;
		transform: translateX(-50%);
		font-size: 15px;
	}

	.modalContent {
		.uni-input {
			border: 1px solid #ddd;
		}

		.btn {
			margin-top: 0;
		}
	}

	.barBox {
		background-color: #2a2b5b;
	}
</style>