<template>


      <div >
         <!--注册登录组件1开始-->
         <div class="common_login_pc_1"><!--使用此组件，请复制此div-->


            <div class="qr-login-after"  v-show="isLogin===1"><!--登录后-->
               <span class="qlf-title">{{time}}好，欢迎您登录~</span>
               <span class="qlf-sp1">
                 <img v-if="userData.photo" :src="userData.photo" alt="">
                 <img v-else src="../../theme-chalk/src/images/percenter-logo.png" alt="">
                </span>
               <span class="qlf-sp2">{{userData.custName}}</span>
               <span class="qlf-sp3">账号：{{userData.phone}}<a href="javascript:void(0)" @click="findPwd">【修改密码】</a></span>
               <span class="qlf-sp4">
                  <a href="javascript:void(0)" @click="logout" class="quit-btn">退出账号</a>
                  <a :href="classHref" class="goto-btn">{{className}}</a>
               </span>
            </div>
             <div class="qr-login" v-show="isLogin===0">
                <div class="qr-login-hd">
                   <ul style="text-align:center;">
                      <!--<li :class="{on:isWx===true}"  @click="isWx=true">二维码登录</li> -->
                      <li   @click="isWx=false">账号登录</li>
                   </ul>
                </div>
                <div class="qr-login-bd">
                   <div class="qr-login-qr" v-if="hasWx && isWx">
                      <span class="sp1"><img src="../../theme-chalk/src/images/login-qr.jpg" alt=""></span>
                      <span class="sp2">微信扫码登录</span>
                      <span class="sp3"><a @click="regAccount" href="javascript:void(0)">没有账号，立即注册</a></span>
                   </div>
                   <div class="qr-login-input" v-else>
                      <span class="sp2">
                         <!--<span class="sp1"><span>请输入手机号/身份证号码</span> -->
                         <input type="text" style="width:100%" v-model="loginName" placeholder="输入手机号/身份证号">
                      </span>
                      <span class="sp2">
                         <input type="password" style="width:100%" v-model="password" placeholder="输入密码">
                      </span>
                      <span class="sp3"><a href="javascript:void(0);"  @click="findPwd">找回密码</a></span>
                      <span class="sp4">
                         <a href="javascript:void(0);" @click="logins" class="a1">登录</a>
                         <a @click="regAccount" href="javascript:void(0)" class="a2">没有账号，立即注册</a>
                      </span>
                   </div>
                </div>
            </div>


              <div class="common_login_pc_1_pop common_popbg" style="display:none;"><!--弹窗-->
               <div class="common_pop">
                  <span class="common_pop_close"></span>
                  <span class="sp1">选择要登录的账号</span><!--弹窗标题-->
                  <span class="sp2">
                     <a href="" class="a1">绑定已有账号</a>
                     <a href="" class="a2">创建新账号</a>
                  </span>
                  <div class="register-pop-part-inp">
                     <select name="" id="" class="select1">
                        <option value="">helloworld01</option>
                        <option value="">helloworld02</option>
                     </select>
                  </div>
                  <div class="register-pop-part-inp"><!--添加class：wrong-inp 为错误提醒-->
                     <!-- <span class="wrong-tip">请输入正确的手机号</span> -->
                     <input type="text" placeholder="请输入正确的手机号" class="inp1">
                  </div>
                  <div class="register-pop-part-inp">
                     <input type="text" placeholder="手机验证码" class="inp2">
                     <input type="button" value="获取验证码" class="inp3">
                  </div>
                  <div class="register-pop-part-inp">
                     <input type="password" placeholder="请输入您的密码" class="inp1">
                  </div>
                  <div class="register-pop-part-inp">
                     <input type="password" placeholder="请设置新密码" class="inp1">
                  </div>
                  <div class="register-pop-part-inp">
                     <input type="password" placeholder="请重复新密码" class="inp1">
                  </div>
                  <button class="register-pop-part-sub">绑定并登录</button>
               </div>
            </div>

         </div>
         <!--注册登录组件1结束-->
            <el-login ref="child" @setOpen="setOpen" @isphone="isPhone" @isname="isName" @iscard="isCard"  @iscode="isCode" @dataNull="dataNull" :isCard="iscard" :isPhone="isphone" :isName="isname" :isCode="iscode" :open="isOpen"></el-login>



      </div>



</template>

<script>
import formMixin from "../../../src/mixins/formMixin";
import lenye_base from "lenye_base";
import * as $ from "fy-kit";
import login from "../../login";
import msg from "../../message";

export default {
  name: "ElQrlogin",
  mixins: [formMixin],
  components: {
    login,
    msg
  },
  props: {
     placeholder: {
      type: String,
      default: "总访问量a"
    }
  },
  data() {
    return {
      isWx: false,
      hasWx: true,
      isOpen: false,
      isphone: false,
      iscard:false,
      isname:false,
      iscode: false,
      loginName: "",
      password: "",
      ucIdcard:'',
      ucName: '',
      ucCertNo: '',
      isLogin:null,
      className:'进入个人中心',
      classHref:'/personcenter',
      userData:{},
      time:''
    };
  },
  computed: {
    defaultAttrs() {
      return {
        placeholder: this.t("ele-form.input") + this.desc._label
      };
    }
  },
  mounted() {

    if(localStorage.userData){
      this.toCenter();
    }else{
      this.isLogin = 0;
    }
  },
  //common/pageQuery.do
  methods: {
     logout() {

      localStorage.clear();
      lenye_base.user_data.loginOut();
      // todo
      setTimeout(function() {
         window.parent.location = "/?type=sy";
         window.location.href = "/?type=sy";
      },1000)

     // window.location.reload();
    },
    updatePwd(){
      msg.warning("等待接口中...")
    },
     info(){

        $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/base-service/api/cust/userSelf/detail.do",
          lenye_base.base_data.getformatting({})
        )
        .then(res => {
            if(res.success =='1'){
                this.userData = res.data;
            }else{
                msg.error(res.message);
            }
        })
    },
     toCenter() {
      this.time =  $.date.f24(new Date());
      this.info();
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/base-service/api2/custUserIdentity/queryUserIdentities.do",
          lenye_base.base_data.getformatting({})
        )
        .then(res => {
          if (res.success === "1") {
            // this.datas = res.data;
            if (res.data && res.data[0] && res.data[0].idtCode) {
              if (res.data[0].idtCode == "company") {
                 this.classHref = "/comcenter";
                 this.className = "进入企业中心";
              } else {
                 this.classHref = "/merchantcenter";
                this.className = "进入机构中心";
              }
            } else {
              this.className = "进入个人中心";
              this.classHref='/personcenter';
            }
            this.isLogin = 1;
            lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/base-service/api2/common/getUserToken.do', lenye_base.base_data.getformatting(), function(e) {
              if (e.success === '1') {
                lenye_base.user_data.setuserData({
                  'token':e.data
                });
              }
            });
          } else {
            msg.error(res.message);
          }


        });
    },
    query() {
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/cert-service/common/ctUserCert/queryManagePage.do", // 缺common 接口
          lenye_base.base_data.getformatting({
            sites: lenye_base.site_data.getsiteData().siteId,
            ucIdcard:this.ucIdcard,
            ucName: this.ucName,
            ucCertNo: this.ucCertNo
          })
        )
        .then(res => {
          if (res.success != "1") {
            msg.error(res.message);
          }
        });
    },
    logins() {
      //debugger;
      if (!this.loginName) {
        msg.warning("用户名不能为空！");
        return false;
      } else if (!this.password) {
        msg.warning("密码不能为空！");
        return false;
      }
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/base-service/login/passwordLogin.do",
          lenye_base.base_data.getformatting({
            loginName: this.loginName,
            password: this.password
          })
        )
        .then(res => {
          if (res.success === "1") {
            msg.success("登录成功！");



            localStorage.userData =JSON.stringify(res.data);
            lenye_base.user_data.loginSuccess(res.data);

            window.location.reload();

            this.toCenter();

          } else {
            msg.error(res.message);
          }
        });
    },
    setOpen(data) {
      this.isOpen = data;
    },
    regAccount() {
      this.common();
      this.$refs.child.reg();
    },
    common(){
       this.isOpen = true;
      this.$refs.child.clearData();
    },
    findPwd() {
      this.common();
      this.$refs.child.pwd();
    },
    isPhone(data) {
      this.isphone = data;
    },
     isName(data) {
      this.isname = data;
    },
    isCode(data) {
      this.iscode = data;
    },
    isCard(data){
      this.iscard = data;
    },
    dataNull(data) {
      this.isphone = data;
      this.iscode = data;
    }
  }
};
</script>
