"use strict";const e=require("../../../../common/vendor.js"),n=require("../../../api/member/auth.js"),i=require("../../../api/member/social.js"),o=require("../../../api/member/user.js");let t=[];function a(n){e.index.setStorageSync("openid",n)}async function s(){const{code:e,data:n}=await i.SocialApi.getSocialUser(34);if(0===e)return n}const c=async(n=!0)=>{if(e.index.canIUse("getUpdateManager")){const i=e.index.getUpdateManager();i.onCheckForUpdate((function(o){o.hasUpdate?(i.onUpdateReady((function(){e.index.showModal({title:"更新提示",content:"新版本已经准备好，是否重启应用？",success:function(e){e.confirm&&i.applyUpdate()}})})),i.onUpdateFailed((function(){}))):n||e.index.showModal({title:"当前为最新版本",showCancel:!1})}))}};const r={load:function(){c(),async function(){const{error:e,data:n}=await third.wechat.subscribeTemplate();0===e&&(t=n)}()},login:async()=>new Promise((async(i,o)=>{const t=await e.index.login();if("login:ok"!==t.errMsg)return i(!1);const s=await n.AuthUtil.socialLogin(34,t.code,"default");return 0===s.code?(a(s.data.openid),i(!0)):i(!1)})),bind:()=>new Promise((async(n,o)=>{const t=await e.index.login();if("login:ok"!==t.errMsg)return n(!1);const s=await i.SocialApi.socialBind(34,t.code,"default");return 0===s.code?(a(s.data),n(!0)):n(!1)})),unbind:async e=>{const{code:n}=await i.SocialApi.socialUnbind(34,e);return 0===n},bindUserPhoneNumber:e=>new Promise((async(n,i)=>{const{code:t}=await o.UserApi.updateUserMobileByWeixin(e.code);0===t&&n(!0),n(!1)})),mobileLogin:async i=>new Promise((async(o,t)=>{if("getPhoneNumber:ok"!==i.errMsg)return o(!1);const s=await e.index.login();if("login:ok"!==s.errMsg)return o(!1);const c=await n.AuthUtil.weixinMiniAppLogin(i.code,s.code,"default");return 0===c.code?(a(c.data.openid),o(!0)):o(!1)})),getInfo:s,getOpenid:async function(n=!1){let i=e.index.getStorageSync("openid");if(!i&&n){const e=await s();e&&e.openid&&(i=e.openid,a(i))}return i},subscribeMessage:function(n){let i=[];"string"==typeof n&&i.push(t[n]),"object"==typeof n&&n.forEach((e=>{void 0!==t[e]&&i.push(t[e])})),0!==i.length&&e.index.requestSubscribeMessage({tmplIds:i,fail:e=>{console.log(e)}})}};exports.service=r;
