<template>
  <h-view class="public-style userRegister" title="用户注册">
    <h-content>
      <list-item class="reg-content">
        <div class="reg-entry">
          <div
            style="margin-right:10px"
            :class="['item-entry',{'add-bg-color':isClick1}]"
            @click="goPersonalPage()"
          >
            <img src="../../../assets/userRegister/people.png" v-show="isHighLight"/>
            <img src="../../../assets/userRegister/people-light.png" v-show="!isHighLight"/>
            <span class="text-entry">个人</span>
          </div>
          <div :class="['item-entry',{'add-bg-color':isClick2}]" @click="goCompanyPage()">
            <img src="../../../assets/userRegister/company.png" v-show="isHighLight1"/>
            <img src="../../../assets/userRegister/company-light.png" v-show="!isHighLight1"/>
            <span class="text-entry">企业</span>
          </div>
        </div>
        <div class="tips">
          <p class="tips-item">
            <img src="../../../assets/userRegister/tips.png" alt/>
            <span>温馨提示：</span>
          </p>
          <p class="tips-item">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您可选择用户类型进行用户信息注册及实名认证。</p>
        </div>
      </list-item>
      <!-- <div @click="goJump()">测试跳转</div> -->
    </h-content>
  </h-view>
</template>

<script>
  import {getUrlParam} from "@/scripts/utils";

  export default {
    data() {
      return {
        isClick1: false,
        isClick2: false,
        isHighLight: true,
        isHighLight1: true,
        isReadOnlyPersonal: false,
        isReadOnlyCompany: false,
        userInfo: null,
        userInfo1: null,
        ctitype: ""
      };
    },
    components: {},
    activated: function () {
      // console.log(1111111111111111111111)
      // if (window.localStorage.openId) {
      // this.getUserInfo('1111');
      // };
    },
    created() {
      this.wxConfig();
      if (window.localStorage.openId) {
        this.getUserInfo();
      }
    },
    updated: function () {
    },
    methods: {
      // 获取token
      // getToken() {
      //   let vm = this;
      //   let url = process.env.loginPathRl + "admin";
      //   let param = {};
      //   return vm.hlsHttp.post(url, param).then(function(res) {
      //     window.localStorage.setItem("access_token_rl", res.access_token);
      //   });
      // },
      // 获取openId
      // getOpenId(code) {
      //   let vm = this;
      //   let url = process.env.basePathRl + "getOpenId";
      //   let param = {
      //     apiKey: "handexinxi",
      //     code: code
      //   };
      //   vm.hlsHttp.post(url, param).then(function(res) {
      //     // console.log(1111111)
      //     // window.localStorage.openId = "oBdoRwI9gj9Brbe9iqlDCg5G2dDc";
      //     // window.localStorage.openId = "oBdoRwFp6UN_KzchaPIEPynR9poM"
      //     // if(window.localStorage.openId){
      //     //     vm.getUserInfo();
      //     // }
      //     if (res.resultCode == "00") {
      //       window.localStorage.openId = res.result;
      //       if (window.localStorage.openId) {
      //         vm.getUserInfo();
      //       }
      //     } else {
      //       return;
      //     }
      //   });
      // },
      goPersonalPage() {
        this.isClick1 = true;
        this.isClick2 = false;
        this.isHighLight = false;
        this.isHighLight1 = true;
        // console.log('hddhhshshshsh',this.isReadOnlyPersonal)
        if (this.ctitype) {
          if (this.ctitype == 1) {
            if (this.isReadOnlyPersonal) {
              this.$router.push({
                name: "ReadonlyPersonalReg",
                params: {
                  userInfo: this.userInfo
                }
              });
            } else {
              this.$router.push({
                name: "PersonalRegister",
                params: {
                  userInfo: this.userInfo
                }
              });
            }
          } else if (this.ctitype == null) {
            this.$router.push({
              name: "PersonalRegister",
              params: {
                userInfo: this.userInfo
              }
            });
          } else {
            return;
          }
        } else {
          this.$router.push({
            name: "PersonalRegister"
          });
        }
      },
      goCompanyPage() {
        this.isClick2 = true;
        this.isClick1 = false;
        this.isHighLight1 = false;
        this.isHighLight = true;
        if (this.ctitype) {
          if (this.ctitype == 2) {
            if (this.isReadOnlyCompany) {
              this.$router.push({
                name: "ReadonlyCompanyReg",
                params: {
                  userInfo: this.userInfo1
                }
              });
            } else {
              this.$router.push({
                name: "CompanyRegister"
              });
            }
          } else if (this.ctitype == null) {
            this.$router.push({
              name: "CompanyRegister"
            });
          } else {
            return;
          }
        } else {
          this.$router.push({
            name: "CompanyRegister"
          });
        }
      },
      getUserInfo() {
        let vm = this;
        let url =
          process.env.rootPath +
          "/sign/info/hclc/query/by/openid?openId=" +
          window.localStorage.openId;
        vm.hlsPopup.showLoading("请稍等");
        vm.$post(url).then(function (res) {
          vm.hlsPopup.hideLoading();
          if (res.rows) {
            if (res.rows.length > 0) {
              console.log(res.rows);
              var results = res.rows[0];
              var historyFlag = data.historyFlag;
              if (historyFlag == 'N') {
                vm.ctitype = results.ctitype;
                if (results.ctitype == 1) {
                  vm.userInfo = results;
                } else if (results.ctitype == 2) {
                  vm.userInfo1 = results;
                }
                if (results.ctitype == 1 && results.faceAuthStatus == "SUCCESS") {
                  vm.isReadOnlyPersonal = true;
                } else if (
                  results.ctitype == 2 &&
                  results.faceAuthStatus == "SUCCESS" &&
                  results.orgAuthStatus == "SUCCESS"
                ) {
                  vm.isReadOnlyCompany = true;
                } else {
                  return;
                }
              }
            }
          }
        });
      },
      // 调用微信接口的基础配置
      wxConfig() {
        let clientUrl = "";
        let u = navigator.userAgent;
        let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
        let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isAndroid) {
          //这个是安卓操作系统
          console.log("机型：android");
          clientUrl = location.href;
        }
        if (isIOS) {
          //这个是ios操作系统
          console.log("机型：ios");
          clientUrl = location.href.split("#")[0];
        }
        // let url = $config.rootPath + '/js/sdk/getWxConfig?wxCode=' + $config.wxCode + '&clientUrl=' + clientUrl
        let url = process.env.basePathRl + "getSignature";
        let param = {
          apiKey: "handexinxi",
          url: clientUrl
        };
        hlsHttp.post(url, param).then(function (res) {
          wx.config({
            beta: true,
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.result.appId, // 必填，公众号的唯一标识
            timestamp: res.result.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.result.nonceStr, // 必填，生成签名的随机串
            signature: res.result.signature, // 必填，签名，见附录1
            jsApiList: [
              "chooseImage",
              "previewImage",
              "downloadImage",
              "getLocalImgData",
              "uploadImage",
              "hideOptionMenu"
            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
          });
          wx.ready(function () {
            wx.hideOptionMenu();
          });
        });
      }
    }
  };
</script>
<style lang="less" type="text/less">
  @import "../../../styles/vue-1px.less";

  .userRegister {
    .reg-content {
      padding: 20px;
      padding-top: 150px;
      .reg-entry {
        display: -webkit-flex;
        display: flex;
        .add-bg-color {
          background-color: #999999;
          color: #fffff !important;
        }
        .item-entry {
          width: 50%;
          border: 1px solid #ddd;
          position: relative;
          border-radius: 5px;
          img {
            width: 50px;
            height: 50px;
            margin: 10px;
          }
          .text-entry {
            position: absolute;
            top: 30px;
            right: 30%;
          }
        }
      }
      .tips {
        margin-top: 70px;
        margin-left: 30px;
        color: #999999;
        font-size: 12px;
        .tips-item {
          line-height: 24px;
        }
        img {
          width: 22px;
          height: 22px;
          margin-right: 15px;
        }
      }
    }
  }

  // iPhoneX适配
  @media (device-width: 375px) and (device-height: 812px) and (-webkit-min-device-pixel-ratio: 3) {
    .platform-ios {
      #home {
      }
    }
  }

  // iPhoneX Max适配
  @media (device-width: 414px) and (device-height: 896px) {
    .platform-ios {
      .platform-ios {
        #home {
        }
      }
    }
  }
</style>
