
<style scoped>  
.comp-login {background-color:#fff;height:100%;height:100vh;}

</style>
<template>     
  <div class="container comp-login jfBaseSize" v-cloak v-bind:style="vh?'height:100vh':'height: 100%;'"> 
     
    <div class="login-content">
      <p>
        <span>手机号</span>
        <input type="text" placeholder="请输入手机号码" class="inp" name="Mobile" id="Mobile" v-model="Mobile">
      </p>
      <p>
        <span>密　码</span>
        <input type="password" placeholder="请输入登录密码" class="inp" name="MemberPassword" id="MemberPassword"  v-model="MemberPassword">
      </p>
    </div>
    <!-- <img class="bg-img" :src="comp.props.bgImg.val"> -->
    <button class="item-btn"  @click="login()">手机登录</button>

    <div class="footer"><a href="javascript:void(0)" @click="goPage('12')">忘记密码</a> | <a href="javascript:void(0)" @click="goPage('11')">注册</a></div>
  </div>
</template>
<script>
import { Toast } from 'mint-ui';
import JfapiHelper from "@/assets/js/JfapiHelper.js";
import { base64 } from "@/assets/js/cryptoHelper";
import { debug } from 'util';
import '@/assets/js/libs/js.cookie';
import { Indicator } from 'mint-ui';
export default {
  name: "JfCompLogin",
  props: ["comp", "cfg", "selectedPage"],
  data() {
    return {
      Mobile: "",
      MemberPassword: "",
      vh:false,
    };
  },
  methods: {
     goPage(pagetype){
        this.$parent.changeSelectedPage(pagetype);
    },
    // 输入验证
    validation(){ 
      if(this.Mobile == ""){
        Toast('请输入手机号码');
        return true;
      }
      if(this.MemberPassword == ""){
        Toast('请输入密码');
        return true;
      }
      return false;
    },
      AutoLogin(){
         var locationto=this.$parent;
        var that=this;var OpenId="";var nickname="";var headimgurl="";
        var wxUserInfo=this.sup8.context.wxUser;
        if(wxUserInfo)
        {
            nickname=wxUserInfo.nickname;
            headimgurl=wxUserInfo.headimgurl;
            OpenId=wxUserInfo.openid;
        }
        if(OpenId=="")
        {
            return;
        }
        var GPRS=sessionStorage.getItem("gps");
        var url = "/integral/UserLoginByWeChatOpenId";
        var dataParams = {
            EnterpriseNo:that.sup8.context.enterpriseno,
            OpenId:OpenId,
            LanguageType:JfapiHelper.GetLanguageType(),
            IP:"",
            GPS:GPRS,
            NickName:nickname,
            HeadImage:headimgurl
        };
        var cbError=function(){Indicator.close();}
        var cbSuccess = function(res){
            if(res.flag)
            {
               localStorage.setItem("loginauto","1");
               localStorage.setItem('loginInfo', JSON.stringify(res.data));
              // 页面跳转
              locationto.changeSelectedPage("9");
            } Indicator.close();
        };
        //请求后端
        JfapiHelper.CommonCallServiceAuto(url,dataParams,cbSuccess,cbError,null,null)
      },
    // 用户登陆
	  login(isAuto = false) {
       var locationto=this.$parent;
       if(isAuto)
       {
           locationto.changeSelectedPage("9");return;
       }
		  //isAuto是true表示自动登陆
		  let that = this;
		  if (that.validation()) {
			  return;
		  };
      Indicator.open();
      try{
      var OpenId="";var location="";var nickname="";var headimgurl="";
      var wxUserInfo=this.sup8.context.wxUser;
      if(wxUserInfo)
      {
        OpenId=wxUserInfo.openid;
        nickname=wxUserInfo.nickname;
        headimgurl=wxUserInfo.headimgurl;
      }
       var GeoArea=that.sup8.context.geo;
       if(GeoArea)
       {
          GeoArea=GeoArea.addressComponent;
          location=GeoArea.country+GeoArea.province+GeoArea.city+GeoArea.district+GeoArea.street+GeoArea.street_number;
       }
       var GPRS=sessionStorage.getItem("gps");
      //var GPRS=that.sup8.UA.geo.latitude+","+that.sup8.UA.geo.longitude;
		  // 登陆请求
		  JfapiHelper.UserLoginAndBindOpenId({
			  EnterpriseNo: that.sup8.context.enterpriseno,
			  MemberName: that.Mobile,
			  Password: that.MemberPassword,
			  OpenId: OpenId,
        LanguageType:JfapiHelper.GetLanguageType(),
        GPS:location,
        IP:"",
        NickName:nickname,
        HeadImage:headimgurl
		  },
			  function (resultData) {
				  Indicator.close();
				  if (resultData.flag) {
					  localStorage.setItem('loginInfo', JSON.stringify(resultData.data));
					  // 页面跳转
					   locationto.changeSelectedPage("9");
				  } else {
					  Toast(resultData.msg || "登陆失败");
				  }
			  },
			  function (res) {
				  Toast("登陆失败");
				  Indicator.close(); 
			  }
      );
      }catch(e){
        Toast(e || "登陆失败"); Indicator.close(); 
      }
	  }
  },
  watch: {
    recordPwd:function(){
      if(!this.recordPwd){
        this.autoLogin = false;
      }
    }
  },
  created: function() {
     Indicator.close(); 
     this.AutoLogin();
  },
  mounted: function() {
      //如果登录了则自动跳转到首页
      // if(localStorage.getItem("loginInfo")!=null)
      // {
      //     //var loginInfo=JSON.parse(localStorage.getItem("loginInfo"));
      //     this.login(true);
      // }
      var that=this;
      var isDesign = location.pathname.indexOf('design');
      if (!(isDesign>-1)) {
          that.$set(that,'vh',true);
      }else{
          that.$set(that,'vh',false);
      }
      setTimeout(()=>{
        let offsetHeight = document.body.offsetHeight;
        let scrollHeight = document.body.scrollHeight;
        this.height = scrollHeight>offsetHeight?scrollHeight+"px":offsetHeight+"px";
      },1000);
  }
};
</script>

