<template>
	<view class="page" :style="themeColor">
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout passwordLogi_flex_0">
			<view class='flex flex-wrap align-center passwordLogi_fd0_0'>
				<text class='passwordLogi_fd0_0_c0'>欢迎来到萬家商超商家端</text>
			</view>
			<view class='flex flex-direction flex-wrap align-stretch passwordLogi_fd0_1'>
				<text class='passwordLogi_fd0_1_c0'>账号</text>
				<view class='flex flex-wrap align-center justify-between'>
					<input style="width: 100%;" type="number" placeholder="请输入手机号" confirm-type="done" :maxlength="11"
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="mible" />
				</view>
			</view>
			<view class='flex flex-direction flex-wrap align-stretch passwordLogi_fd0_2'>
				<text class='passwordLogi_fd0_2_c0'>密码</text>
				<view class='flex flex-wrap align-center justify-between'>
					<benben-flex-password-diy v-model="Passworld"
						class-name="flex flex align-center passwordLogi_fd0_2_c1_c0" :placeholder="'请输入密码(6~12位字母+数字)'"
						:maxlength="12" :default-type='true' placeholder-style="color:#999;font-size:32rpx">
						<template #show>
							<text class='fu-iconfont2  passwordLogi_fd0_2_c1_c0_icon1' data-type="show">&#xE837;</text>
						</template>
						<template #hide>
							<text class='fu-iconfont2  passwordLogi_fd0_2_c1_c0_icon2' data-type="hide">&#xEBCC;</text>
						</template>
					</benben-flex-password-diy>
				</view>
			</view>
			<view class='flex flex-direction-row-reverse flex-wrap align-center passwordLogi_fd0_3'>
				<text v-if="isPublish!=1" class='passwordLogi_fd0_3_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dl/codeLogin/codeLogin`">验证码登录</text>
			</view>
			<view class='flex flex-wrap align-center passwordLogi_fd0_4'>
				<button class='flex-sub passwordLogi_fd0_4_c0' @tap.stop="validationLoginFunc()">立即登录</button>
			</view>
			<view class='flex flex-wrap align-center justify-center passwordLogi_fd0_5' v-if="isPublish!=1">
				<text class='passwordLogi_fd0_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dl/registerPage/registerPage`">注册账号</text>

				<view class='flex  passwordLogi_fd0_5_c1'></view>
				<text class='passwordLogi_fd0_5_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dl/forgotPassword/forgotPassword`">忘记密码</text>
			</view> 
		</view>

		<!---flex布局flex布局结束-->
		<!-- <view class="flex flex-direction align-center benben-position-layout flex passwordLogi_flex_1">
			<view class='flex flex-wrap align-center'>
				<view class='flex flex-wrap align-center passwordLogi_fd1_0_c0'>
				</view>
				<text class='passwordLogi_fd1_0_c1'>快捷登录</text>
				<view class='flex flex-wrap align-center passwordLogi_fd1_0_c2'>
				</view>
			</view>
			<image class='passwordLogi_fd1_1' :src='STATIC_URL+"119.png"' @tap.stop="wxLogin"></image>

		</view> -->
		<view class='flex flex-wrap align-center justify-center registerPage_fd1_5'>
			<benben-flex-switch-new class-name='flex flex registerPage_fd1_5_c0' v-model="is_tick" :disabled='false'
				:auto='true'>
				<template v-slot:checked>
		
					<view class='flex flex position-relative align-center'>
						<image class='registerPage_checkfd1_5_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"44.png"'>
						</image>
					</view>
		
				</template>
				<template v-slot:unchecked>
		
					<view class='flex flex position-relative justify-end align-center'>
						<image class='registerPage_noCheckfd1_5_c0_c1_c0' mode="aspectFit"
							:src='STATIC_URL+"117.png"'></image>
					</view>
		
				</template>
			</benben-flex-switch-new>
			<text class='registerPage_fd1_5_c1'>已阅读并同意</text>
			<text class='registerPage_fd1_5_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dl/registrationAgreemen/registrationAgreemen?type=9`">《用户注册协议》</text>
			<text class='registerPage_fd1_5_c3'>与</text>
			<text class='registerPage_fd1_5_c4' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dl/registrationAgreemen/registrationAgreemen?type=10`">《隐私政策》</text>
		</view>
		<view :style="{height: '300rpx'}"></view>

	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	import {ACCEPT_PLATFORM } from '@/common/config.js';
	export default {
		components: {},


		data() {
			return {
				"mible": "",
				"Passworld": "",
				"token": "",
				is_click: "",
				is_tick: false,
				isPublish:""  //0已上架 1上架中
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {

		},
		onShow() {
			this.getPublishStatus()
		},
		methods: {
			getPublishStatus() {  
				console.log(SYSTEM_CONFIG.appVersion);
				let _platform = uni.getSystemInfoSync().platform;
				this.$api.post(global.apiUrls.post673572b0bebd7, {
					app_version: SYSTEM_CONFIG.appVersion, 
					type: ACCEPT_PLATFORM == 'IOS' ? 'ios' : 'android'},
					) .then(res => {
					if (res.data.code == 1) {
						this.isPublish = res.data.data.is_listing;
						console.log('上架状态', res.data.data.is_listing);
					}
				})
			}, 
			//效验登录
			validationLoginFunc() {
				if (!validate(this.mible, 'require')) {
					this.$message.info('手机号不能为空');
					return false;
				}
				if (!validate(this.mible, 'phone')) {
					this.$message.info('请输入正确的手机号');
					return false;
				}
				if (!validate(this.Passworld, 'require')) {
					this.$message.info('密码不能为空');
					return false;
				}
				if (!validate(this.Passworld, 'password')) {
					this.$message.info('请输入密码(6~12位字母+数字)');
					return false;
				}
				if (this.is_tick === false) {
					this.$message.info('请先阅读并同意《用户协议》和 《隐私政策》');
					return false;
				}
				let clientId = 'clientId';
				let appSystem = 'appSystem';

				// #ifdef APP-PLUS
				clientId = plus.push.getClientInfo().clientid || '';
				console.log('getClientInfo', plus.push.getClientInfo());
				appSystem = uni.getSystemInfoSync().platform == 'ios' ? 1 : 2;
				// #endif 
				this.is_click = true;
				// postloginByAccount 账号密码登录接口
				this.$api.post(global.apiUrls.postloginByAccount, {
					account: this.mible,
					password:this.Passworld,
					client_id: clientId,
					appSystem,
					account_type:"mobile"
				}).then(res => {
					this.is_click = false;
					if (res.data.code == 1 && res.data.data) {
						global.tokenres=res.data.data.userinfo.user_token
						console.log(global.tokenres)
						this.authInfoCheck(res)
						// this.$message.info(res.data.msg); // 提示框
						// this.$store.commit('updateUserInfo', res.data.data.userinfo); // 修改vuex储存的用户信息
						// setTimeout(() => {
						//   uni.navigateBack(); // 返回上一页
						// }, 800);
					} else {
						this.$message.info(res.data.msg); // 错误提示框
					}
				});
			},
			
			authInfoCheck(){
        console.log(global.apiUrls.authInfoCheck);
				this.$api.post(global.apiUrls.authInfoCheck).then(res=>{
					if(res.data.code==1){
						this._loginSuccess(res)
					}
				})
			},
			
			Get5d8b062aefc08(userInfo){
				let clientId = '8989898989';
				let appSystem = 'appSystem';
				// #ifdef APP-PLUS
				clientId = plus.push.getClientInfo().clientid || '';
				console.log('getClientInfo', plus.push.getClientInfo());
				appSystem = uni.getSystemInfoSync().platform == 'ios' ? 1 : 2;
				// #endif
				this.$api.post(global.apiUrls.Get5d8b062aefc08,{
					client_id:clientId
				}).then(res=>{
					if(res.data.code==1){
						this.$message.info('登录成功');
						global.token = global.tokenres
						global.userInfo = userInfo
						this.$store.commit('updateUserInfo', userInfo); // 修改vuex储存的用户信息
						try {
							uni.setStorageSync('USER_TOKEN', global.token)
							uni.setStorageSync('USER_INFO', global.userInfo)
							uni.$emit('appLoginSuccess')
							console.log(222222222)
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/tabBar/takeouTorders/takeouTorders'
								})
							}, 1000)
						} catch (e) {
						
						}
					}
				})
			},
			
			// 登录成功
			_loginSuccess(res) {
				console.log(res.data.data)
				if (res.data.code == 1) {
					// global.token = res.data.data.userinfo.user_token;
					// 状态：-1=未提交 0=审核中 1=通过 2=驳回
					if (res.data.data.status == 0) {
						uni.navigateTo({
							url: '/pages/dl/certificationAudit/certificationAudit?stateUS=1'
						})
					} else if (res.data.data.status == 1) {
						
						this.Get5d8b062aefc08(res.data.data)
						
						
					} else if (res.data.data.status == 2) {
						// global.tokenres = res.data.data.userinfo.user_token
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/dl/certificationAudit/certificationAudit?stateUS=' + '2' +
									'&reason=' + res.data.data.reason,
							})
						}, 300)
					} else {
						// global.tokenres = res.data.data.userinfo.user_token
						uni.navigateTo({
							url: '/pages/dl/certifiedMerchant/certifiedMerchant?type=' + 0
						})
					}
				} else {
					this.$message.info(res.data.msg);
				}
			},
			/**
			 * @func 微信登录
			 */
			wxLogin() {
				let _this = this;
				// #ifdef APP-PLUS
				if (
					plus.runtime.isApplicationExist({
						pname: 'com.tencent.mm',
						action: 'weixin://'
					})
				) {
					uni.getProvider({
						service: 'oauth',
						success: function(res) {
							//支持微信、qq和微博等
							if (~res.provider.indexOf('weixin')) {
								_this.wx_login_fn(); // 去微信授权
							}
						},
						fail: function(err) {
							console.log(err);
						}
					});
				} else {
					_this.$api.msg(this.i18n['请安装微信后再使用此功能']);
				}
				// #endif
			},
			/**
			 * @func 微信授权登录
			 */
			wx_login_fn() {
				let _this = this;
				console.log(1111111111)
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						// 获取用户信息
						uni.getUserInfo({
			  		provider: 'weixin',
							success: function(infoRes) {
								let {
									nickName,
									avatarUrl,
									gender
								} = infoRes.userInfo;
								// #ifdef APP-PLUS
								let clientId = plus.push.getClientInfo().clientid || '';
								let appSystem = uni.getSystemInfoSync().platform == 'ios' ? 1 : 2;
								// #endif
								// postUserSocialLogin 第三方登录接口
								_this.$api.post(global.apiUrls.postUserSocialLogin, {
									type: 1,
									wx_unionid: infoRes.userInfo.unionId,
									qq_unionid: '',
									wb_unionid: '',
									clientId: clientId || '',
									appSystem: appSystem || '',
									nickname: nickName,
									avatar: avatarUrl,
									gender: gender
								}).then(res => {
									console.log(res)
									global.tempUserLoginInfo = infoRes
									.userInfo; // 修改global 的用户信息
									uni.hideLoading(); // 关闭loading
									if (res.data.code == 1) {
										if (res.data.data.userinfo.approve_status == 0) {
											uni.navigateTo({
												url: '/pages/dl/certificationAudit/certificationAudit?stateUS=1'
											})
										} else if (res.data.data.userinfo.approve_status ==1) {
											_this.$message.info(_this.i18n['登录成功']);
											global.token = res.data.data.userinfo.user_token
											global.userInfo = res.data.data.userinfo
											_this.$store.commit('updateUserInfo', res.data
												.data.userinfo); // 修改vuex储存的用户信息
											try {
												uni.setStorageSync('USER_TOKEN', global.token)
												uni.setStorageSync('USER_INFO', global.userInfo)
												uni.$emit('appLoginSuccess')
												console.log(222222222)
												setTimeout(() => {
													uni.switchTab({
														url: '/pages/tabBar/takeouTorders/takeouTorders'
													})
												}, 1000)
											} catch (e) {

											}
										} else if (res.data.data.userinfo.approve_status ==2) {
											global.tokenres = res.data.data.userinfo.user_token
											setTimeout(() => {
												uni.navigateTo({
													url: '/pages/dl/certificationAudit/certificationAudit?stateUS=' +
														'2' +
														'&reason=' + res
														.data.data.userinfo
														.reason,
												})
											}, 300)
										} else {
											global.tokenres = res.data.data.userinfo.user_token
											uni.navigateTo({
												url: '/pages/dl/certifiedMerchant/certifiedMerchant?type=' +0
											})
										}
									} else if (res.data.code == -999) {
										_this.$urouter.navigateTo({
											url: '/pages/dl/Bindphonenumber/Bindphonenumber',
											params: {
												unionId: infoRes.userInfo.unionId,
												openId: infoRes.userInfo.openId,
												sex: infoRes.userInfo.gender,
												nickName: infoRes.userInfo.nickName,
												avatarUrl: infoRes.userInfo.avatarUrl,
												authType: 'wx_unionid'
											}
										});
										// 点击手机号账号登录按钮 -1 hash参数无效
									} else if (res.code == -1) {
										_this.$message.info(res.data.msg); //
										return;
									}
								}).catch(err => {
									uni.hideLoading(); // 关闭loading
									console.log(err);
								});
							}
						});
					},
					fail: function(err) {
						console.log(err);
						uni.hideLoading(); // 关闭loading
					}
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: url(/static/images/81.png) no-repeat, rgba(255, 255, 255, 1);
		background-size: 100% auto !important;
	}
	.registerPage_fd1_5_c4 {
		color: #59A6F4;
		font-size: 22rpx;
		font-weight: 400;
		line-height: 32rpx;
	}
	
	.registerPage_fd1_5_c3 {
		color: rgba(102, 102, 102, 1);
		font-size: 22rpx;
		font-weight: 400;
		line-height: 32rpx;
	}
	
	.registerPage_fd1_5_c2 {
		color: #59A6F4;
		font-size: 22rpx;
		font-weight: 400;
		line-height: 32rpx;
	}
	
	.registerPage_fd1_5_c1 {
		color: rgba(102, 102, 102, 1);
		font-size: 22rpx;
		font-weight: 400;
		line-height: 32rpx;
	}
	
	.registerPage_noCheckfd1_5_c0_c1_c0 {
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		width: 24rpx;
		height: 24rpx;
	}
	
	.registerPage_checkfd1_5_c0_c0_c0 {
		width: 24rpx;
		height: 24rpx;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
	}
	
	::v-deep .registerPage_fd1_5_c0 {
		margin: 0rpx 8rpx 0rpx 0rpx;
	}
	
	.registerPage_fd1_5 {
		position: fixed;
		bottom: 40rpx;
		width: 100%;
		text-align: center;
		padding: 32rpx 0rpx 0rpx 0rpx;
	}
	.passwordLogi_flex_0 {
		padding: 296rpx 75rpx 0rpx 75rpx;
	}

	.passwordLogi_fd0_5_c2 {
		color: #999999;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 34rpx;
	}

	.passwordLogi_fd0_5_c1 {
		background: rgba(171, 163, 163, 1);
		width: 1rpx;
		height: 30rpx;
		margin: 0rpx 20rpx 0rpx 20rpx;
		transform: scaleX(0.5);
	}

	.passwordLogi_fd0_5_c0 {
		color: #999999;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 34rpx;
	}

	.passwordLogi_fd0_5 {
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.passwordLogi_fd0_4_c0 {
		background: rgba(255, 147, 0, 1);
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		height: 80rpx;
		line-height: 80rpx;
	}

	.passwordLogi_fd0_4 {
		padding: 48rpx 0rpx 0rpx 0rpx;
	}

	.passwordLogi_fd0_3_c0 {
		color: #333333;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 38rpx;
	}

	.passwordLogi_fd0_3 {
		margin: 32rpx 0rpx 0rpx 0rpx;
	}

	.passwordLogi_fd0_2_c1_c0_icon2 {
		width: 88rpx;
		line-height: 88rpx;
		text-align: center;
		font-size: 40rpx;
	}

	.passwordLogi_fd0_2_c1_c0_icon1 {
		width: 88rpx;
		line-height: 88rpx;
		text-align: center;
		font-size: 40rpx;
	}

	::v-deep .passwordLogi_fd0_2_c1_c0 {
		width: 600rpx;
		font-size: 32rpx;
		height: 50rpx;
	}

	.passwordLogi_fd0_2_c0 {
		margin: 0rpx 0rpx 24rpx 0rpx;
		color: #333333;
		font-size: 30rpx;
		font-weight: 600;
		line-height: 32rpx;
	}

	.passwordLogi_fd0_2 {
		border-bottom: 1px solid #eee;
		padding: 40rpx 0rpx 20rpx 0rpx;
	}

	.passwordLogi_fd0_1_c0 {
		margin: 0rpx 0rpx 24rpx 0rpx;
		color: #333333;
		font-size: 30rpx;
		font-weight: 600;
		line-height: 32rpx;
	}

	.passwordLogi_fd0_1 {
		border-bottom: 1px solid #eee;
		padding: 40rpx 0rpx 20rpx 0rpx;
	}

	.passwordLogi_fd0_0_c0 {
		color: #333333;
		font-size: 50rpx;
		font-weight: 600;
		line-height: 50rpx;
	}

	.passwordLogi_fd0_0 {
		margin: 0rpx 0rpx 24rpx 0rpx;
	}

	.passwordLogi_flex_1 {
		background: #fff;
		width: 750rpx;
		height: 300rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.passwordLogi_fd1_1 {
		width: 80rpx;
		height: 80rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.passwordLogi_fd1_0_c2 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}

	.passwordLogi_fd1_0_c1 {
		line-height: 32rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #999999;
		padding: 0rpx 7rpx 0rpx 7rpx;
	}

	.passwordLogi_fd1_0_c0 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}
</style>
