
<style scoped>  
.comp-key {background-color:#fff;height:100%;height:100vh;}
.input-box {background:#FFF;}
.comp-key {padding:0;margin:0;}
.key-content{padding:0 3%;}
.key-content .KeyList ul{list-style-type: none;padding: 0;margin: 0;}
.key-content .KeyList img{width: 100%;height:7rem;}
.bannerbg{margin-bottom:1rem;background-image:url('http://image.supercarrier8.com/h5_key/topbanner.png');background-size:100% 100%;background-repeat:no-repeat;height: 6.4rem;}
.key-content .RegIn{font-size: 1.2rem;}
.key-content .selectin{margin: 0.5rem 0;}
</style>
<template>     

  <div class="container comp-key jfBaseSize" v-cloak v-bind:style="vh?'height:100vh':'height: 100%;'"> 
    <div class="bannerbg" style="background-image:url('http://image.supercarrier8.com/h5_key/topbanner.png');"></div>
    <div class="key-content">
        <div class="RegIn">渠道注册入口</div>
        <div class="selectin">请选择对应身份进入</div>
     
        <div class="KeyList">
           <ul>
             <li v-for="(item,index) in comp.props.items.val" :key="index"><a v-bind:href="item.actionType"><img v-bind:src="item.imgUrl"/></a></li>
           </ul>
        </div>
    </div>
   </div>
</template>
<script>
import { Toast } from 'mint-ui';
import channelHelper from "@/assets/js/channelHelper.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: "Key_key",
  props: ["comp", "cfg", "selectedPage"],
  data() {
    var wxUserInfo=this.sup8.context.wxUser;
    var UserPhoto="";
    if(wxUserInfo)
    {
      UserPhoto=wxUserInfo.headimgurl;
    }else{
      UserPhoto="http://image.supercarrier8.com/h5_key/icon_headDefault.png";
    }
    return {
      imgs: [],
      UserPhoto:UserPhoto,
      PhoneNo: "",
      Password: "",
      vh:false,
    };
  },
  methods: {
     goPage(pagetype){
        this.$parent.changeSelectedPage(pagetype);
    },
    Autokey(){
         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 = "/channel/KeyPersonUserLoginByOpenId";
        var dataParams = {
            EntranceId:0,
            EnterpriseNo:that.sup8.context.enterpriseno,
            OpenId:OpenId,
            LanguageType:channelHelper.GetLanguageType(),
            IP:"",
            GPS:GPRS,
            NickName:nickname,
            HeadImage:headimgurl
        };
        var cbError=function(){Indicator.close();}
        var cbSuccess = function(res){
            if(res.flag)
            {
               /** 如果是消费者身份则重写登录缓存信息 */
               if(res.data.MemberType=="0")
               {
                  res.data.PetName=res.data.NickName;
                  res.data.Phone=res.data.Mobile;
                  res.data.UserLogo=res.data.HeadImage;
               }
               localStorage.setItem("keyauto","1");
               localStorage.setItem('loginInfo', JSON.stringify(res.data));
               location.href=channelHelper.GetDashUrl()+"/key?eno="+res.data.EnterpriseNo+"&entranceid="+res.data.MemberType;
            } Indicator.close();
        };
        //请求后端
        channelHelper.CommonCallServiceAuto(url,dataParams,cbSuccess,cbError,null,null)
      },
      updateDom() {
          var that = this;
          //alert(this.comp.props.bgImg.val);
          // 将当前设置的背景图片加到body标签下
          $(".bannerbg").css({
            "background-image":`url(${this.comp.props.bgImg.val})`
          });
      }
  },
  watch: {
    "comp.props.bgImg.val": function() {
      this.updateDom();
    }
  },
  created: function() {
     var that=this;
     that.mergeCompProps(that.comp);
     that.comp.props.items.val = that.comp.props.items.val || [];
     Indicator.close(); 
     this.Autokey();
  },
  mounted: function() {
      this.updateDom();
      //如果登录了则自动跳转到首页
      // if(localStorage.getItem("keyInfo")!=null)
      // {
      //     //var keyInfo=JSON.parse(localStorage.getItem("keyInfo"));
      //     this.key(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(()=>{
        $("#PhoneNo").removeAttr("readonly");$("#Password").removeAttr("readonly");
        let offsetHeight = document.body.offsetHeight;
        let scrollHeight = document.body.scrollHeight;
        this.height = scrollHeight>offsetHeight?scrollHeight+"px":offsetHeight+"px";
      },500);
  }
};
</script>

