"use strict";const e=require("../../common/vendor.js"),l=require("../../api/login.js"),c=require("../../common/assets.js"),g={data(){return{userName:"",password:"",registrationID:"",unionid:"",userPhone:"",loginType:0,isApp:!1,agree:!1,isAgreePrivacy:!1,isIos:!1,from:"",source:"",appleKey:""}},onLoad(i){this.from=i.from||"";let n=this;e.index.$on("getRegistrationID",function(o){n.registrationID=o})},onShow(){this.$isLogin()&&this.goPage()},onUnload(){e.index.$off("getRegistrationID")},mounted(){},methods:{initUniverify(){const i=n=>{univerifyManager.getCheckBoxState({success(o){console.log("getCheckBoxState res: ",o),o.state&&univerifyManager.close()}})};univerifyManager.onButtonsClick(i),univerifyManager.offButtonsClick(i)},login(){if(this.$isEmpty(this.userName)){e.index.showToast({title:"请输入帐号",icon:"none"});return}if(this.$isEmpty(this.password)){e.index.showToast({title:"请输入密码",icon:"none"});return}if(!this.agree){e.index.showToast({title:"请同意相关协议",icon:"none"});return}var i={phone:this.userName,password:this.password,loginType:1},n=this;e.index.showLoading({title:"处理中..."}),l.loginByApp(i).then(o=>{e.index.hideLoading(),console.log("qxj res:"+JSON.stringify(o)),o.code==200?(e.index.setStorageSync("AppToken",o.token),e.index.setStorageSync("userInfo",JSON.stringify(o.user)),e.index.$emit("refreshIM"),e.index.$emit("showHealthButler"),n.goPage()):e.index.showToast({title:o.msg,icon:"none"})},o=>{console.log("qxj rej:"+JSON.stringify(o))})},quickAppleLogin(){let i=this;if(!this.agree){e.index.showToast({title:"请同意相关协议",icon:"none"});return}e.index.getProvider({service:"oauth",success:function(n){n.provider.indexOf("apple")&&e.index.login({provider:"apple",success:function(o){i.appleKey=o.authResult.openid,i.loginByAppleAct(o.authResult)},fail:function(o){console.log(o)}})}})},async loginByAppleAct(i){let n="";if(plus.runtime.isAgreePrivacy()){const a=await e.index.getPushClientId();e.index.setStorageSync("registrationID",a.cid),this.registrationID=a.cid;let t=await e.index.getDeviceInfo();t!=null&&(n+=t.deviceBrand?t.deviceBrand:"",n+=t.deviceModel?" "+t.deviceModel:"",n+=t.system?" "+t.system:"")}const o={loginDevice:n,jpushId:this.registrationID,source:this.source,appleKey:i.openid};e.index.showLoading({title:"登陆中"}),loginByApple(o).then(a=>{e.index.hideLoading(),a.user!=null?(e.index.hideLoading(),e.index.setStorageSync("AppToken",a.token),e.index.setStorageSync("userInfo",JSON.stringify(a.user)),e.index.closeAuthView(),e.index.$emit("refreshIM"),e.index.$emit("showHealthButler"),e.index.$emit("refreshUserInfo",{}),this.goPage()):a.isNew&&this.bindMobile("apple")}).catch(()=>{e.index.hideLoading()})},loginWeixin(){if(!this.agree){e.index.showToast({title:"请同意相关协议",icon:"none"});return}e.index.login({provider:"weixin",onlyAuthorize:!0,success:async i=>{e.index.showLoading({title:"处理中..."});const n={code:i.code,jpushId:this.registrationID,source:this.source};this.loginByWeChatAct(n)},fail:i=>{if(console.log("qxj loginWeixin fail:",JSON.stringify(i)),i.code==1e3){e.index.showModal({title:"登录失败",content:`${i.errMsg} ,错误码:${i.code}`,confirmText:"开通指南",cancelText:"确定",success:n=>{n.confirm&&setTimeout(()=>{plus.runtime.openWeb("https://ask.dcloud.net.cn/article/37965")},500)}});return}if(i.code=="30005"){e.index.showModal({showCancel:!1,title:"预登录失败",content:i.errMsg});return}i.code!="30003"&&e.index.showModal({showCancel:!1,title:"登录失败",content:JSON.stringify(i)})},complete:()=>{}})},goToRegister(){this.$navTo("./register")},goToFindPass(){this.$navTo("./findpass")},doUniverify(i){e.tr.callFunction({name:"loginByMobile",data:{access_token:i.access_token,openid:i.openid}}).then(n=>{e.index.closeAuthView(),n.result.errCode==0?this.userName=n.result.phoneNumber:e.index.showToast({title:n.result.message,icon:"none"})}).catch(n=>{console.error("调用云函数失败:",n),console.error("错误信息:",n.errMsg)})},loginByWeChatAct(i){l.loginByWeChat(i).then(n=>{n.code==200?n.user!=null?(e.index.hideLoading(),e.index.setStorageSync("AppToken",n.token),e.index.setStorageSync("userInfo",JSON.stringify(n.user)),e.index.closeAuthView(),e.index.$emit("refreshIM"),e.index.$emit("showHealthButler"),e.index.$emit("refreshUserInfo",{}),this.goPage()):(this.unionid=n.unionid,n.isNew&&this.bindMobile()):(e.index.hideLoading(),e.index.showToast({title:n.msg,icon:"none"}))},n=>{})},bindMobile(i){},loginByUniverify(i,n){e.tr.callFunction({name:"loginByMobile",data:{access_token:i.access_token,openid:i.openid}}).then(o=>{console.log("qxj doUniverify:",JSON.stringify(o)),o.result.errCode==0?(userPhone=o.result.phoneNumber,n==3?this.setPhoneAct(3,userPhone,this.unionid):this.setPhoneAct(1,userPhone,this.unionid)):e.index.showToast({title:o.result.message,icon:"none"})}).catch(o=>{console.error("调用云函数失败:",o),console.error("错误信息:",o.errMsg)})},setPhoneAct(i,n,o){let a={phone:n,unionId:o};i==3&&(a={phone:n,unionId:o,appleKey:this.appleKey}),setPhone(a).then(t=>{e.index.hideLoading(),t.code==200?(e.index.setStorageSync("AppToken",t.token),e.index.setStorageSync("userInfo",JSON.stringify(t.user)),e.index.closeAuthView(),e.index.$emit("refreshIM"),this.goPage()):(e.index.showToast({title:t.msg,icon:"none"}),e.index.closeAuthView())},t=>{})},getRegistrationID(){this.registrationID=e.index.getStorageSync("registrationID"),(this.registrationID==null||this.registrationID=="")&&e.index.getPushClientId({success:i=>{e.index.setStorageSync("registrationID",i.cid),this.registrationID=i.cid}})},goBack(){console.log("qxj goBack"),e.index.$emit("showHealthButler"),e.index.redirectTo({url:"/pages/auth/loginIndex"})},handleAgree(){this.agree=!this.agree,this.isIos&&(this.agree?(plus.runtime.agreePrivacy(),this.getRegistrationID()):plus.runtime.disagreePrivacy())},goToWeb(i){e.index.setStorageSync("url",i==0?"https://userapp.his.cdwjyyh.com/web/userAgreement":"https://userapp.his.cdwjyyh.com/web/privacyPolicy"),e.index.navigateTo({url:"/pages/index/h5"})},goPage(){let i=getCurrentPages();i[i.length-1];let n=e.index.getStorageSync("openUrl");if(n)e.index.navigateTo({url:n,success:function(o){e.index.removeStorageSync("openUrl")}});else{e.index.reLaunch({url:"/pages/list/index",animationType:"none",animationDuration:2e3});return}this.$updateMsgDot(),this.$setSource()}}};function d(i,n,o,a,t,r){return e.e({a:e.o(s=>r.goBack()),b:t.userName,c:e.o(s=>t.userName=s.detail.value),d:t.password,e:e.o(s=>t.password=s.detail.value),f:e.o((...s)=>r.login&&r.login(...s)),g:e.o(s=>r.goToRegister()),h:t.isApp&&t.isAgreePrivacy},t.isApp&&t.isAgreePrivacy?e.e({i:c._imports_0$4,j:e.o((...s)=>r.loginWeixin&&r.loginWeixin(...s)),k:t.isIos},t.isIos?{l:c._imports_1$4,m:e.o((...s)=>r.quickAppleLogin&&r.quickAppleLogin(...s))}:{}):{},{n:c._imports_0$3,o:!t.agree,p:c._imports_1$3,q:t.agree,r:e.o((...s)=>r.handleAgree&&r.handleAgree(...s)),s:e.o(s=>r.goToWeb(0)),t:e.o(s=>r.goToWeb(1))})}const h=e._export_sfc(g,[["render",d],["__scopeId","data-v-2cc9f8c3"]]);wx.createPage(h);