"use strict";const e=require("../../common/vendor.js"),s=require("../../api/user.js"),t=require("../../utils/utils.js"),n=require("../../store/uaeUserStore.js");if(require("../../utils/request.js"),require("../../store/index.js"),require("../../utils/functions.js"),require("../../utils/IDCardVerification.js"),require("../../utils/base64.js"),require("../../config/host.js"),require("../../utils/md5.js"),!Array){(e.resolveComponent("tips")+e.resolveComponent("tiplist"))()}const r=e.defineComponent({__name:"login",setup(r){const i=n.useUserStore(),{HANDLE_ACCTOKEN:o,HANDLE_REFTOKEN:a,HANDLE_USERINFO:u}=i;let c=e.ref(null),l=e.reactive({tenantId:"",password:"",username:"",isremember:!0,showck:!1,warehouseList:[],checkitem:{}});const d=e.ref(null);async function m(){if(!l.checkitem.id)return e.index.showToast({title:"没有选择仓库,请先选择仓库",icon:"none"}),void t.utils.ttsspke("没有选择仓库,请先选择仓库");await s.preserveCurrentWarehouse(l.checkitem),e.index.setStorageSync("checkname",l.checkitem),e.index.switchTab({url:"/pages/index/index"})}async function h(){try{let t={grant_type:"password",scope:"all",username:l.username,password:l.password,tenantId:l.tenantId};e.index.showLoading({mask:!0,title:"登录中"});let n=await s.oauthtoken(t);if(console.log(n),null==n?void 0:n.refresh_token){if(function(s){if(e.index.setStorageSync("access_token",s.access_token),o("userinfo.access_token"),e.index.setStorageSync("refresh_token",s.refresh_token),a(s.refresh_token),e.index.setStorageSync("userinfo",s),u(s),e.index.removeStorageSync("authbuts"),e.index.removeStorageSync("homerouter"),l.isremember){let s={tenantId:l.tenantId,password:l.password,username:l.username};e.index.setStorageSync("loginuser",s)}}(n),e.index.setStorageSync("checkname",{warehouse_id:n.detail.warehouse_id,warehouse_name:n.detail.warehouse_name,name:n.detail.warehouse_name}),n.detail.warehouse_id)return void e.index.switchTab({url:"/pages/index/index"});let t=await s.getMyWarehouseList({});if(l.warehouseList=t.data,1==l.warehouseList.length){await s.preserveCurrentWarehouse(l.warehouseList[0]);return e.index.setStorageSync("checkname",l.warehouseList[0]),void e.index.switchTab({url:"/pages/index/index"})}l.showck=!0}else c.value.setdetails({title:"提示",content:"请确认账号密码正确,多次错误后禁止登录",confirmTxt:"确认",isshow:!0,isshowcancel:!1,success:()=>{c.value.setisshow(!1)},cancel:()=>{c.value.setisshow(!1)},close:()=>{c.value.setisshow(!1)}}),console.log("登录错误")}catch(t){console.log("err :>> ",t)}finally{e.index.hideLoading()}}function w(){l.isremember=!l.isremember}function f(){e.index.navigateBack()}e.onLoad((()=>{let s=e.index.getStorageSync("loginuser");s&&(l.password=s.password,l.tenantId=s.tenantId,l.username=s.username)})),e.onShow((()=>{const e=setTimeout((()=>{clearTimeout(e)}),2e3)})),e.onPullDownRefresh((()=>{const s=setTimeout((()=>{l.username="",l.tenantId="",l.password="",e.index.stopPullDownRefresh(),clearTimeout(s)}),500)}));const{checkitem:g,warehouseList:p,showck:k,username:x,password:v,tenantId:S,isremember:_}=e.toRefs(l);return(s,t)=>e.e({a:e.o(f),b:e.unref(S),c:e.o((s=>e.isRef(S)?S.value=s.detail.value:null)),d:e.unref(x),e:e.o((s=>e.isRef(x)?x.value=s.detail.value:null)),f:e.unref(v),g:e.o((s=>e.isRef(v)?v.value=s.detail.value:null)),h:e.unref(_)?"/static/ck.png":"/static/nock.png",i:e.o(w),j:e.o(h),k:e.unref(k)},e.unref(k)?{l:e.f(e.unref(p),((s,t,n)=>({a:e.t(s.name),b:e.o((e=>function(e){l.checkitem=e}(s))),c:e.n(s.name==e.unref(g).name?"items xzck":"items")}))),m:e.o(m),n:e.o((()=>{})),o:e.o((e=>k.value=!1))}:{},{p:e.sr(c,"e4dba176-0",{k:"tip"}),q:e.sr(d,"e4dba176-1",{k:"tiplists"})})}});wx.createPage(r);