import{o as a,c as e,w as t,n as s,i as o,a as r,f as l,k as n,r as i,U as m,y as u}from"./index-4ddb689d.js";import{_ as d,a as c,b as p}from"./u-form.f3146f4d.js";import{r as f}from"./uni-app.es.24af5d4f.js";import{A as h}from"./index.1169d7d7.js";import{i as v,p as b}from"./user.2171e17f.js";import{i as _}from"./upload.3f305180.js";import{_ as k}from"./_plugin-vue_export-helper.1b428a4d.js";import"./u-icon.e981d1c2.js";const g={nickName:[{required:!0,message:"请输入用户昵称",trigger:["blur","change"]}]};const I=k({components:{AvatarImage:h},data:()=>({disabled:!1,avatarUrl:"",tempFile:null,form:{avatarId:"",nickName:""},rules:g}),onLoad(){this.getUserInfo()},onReady(){this.$refs.uForm.setRules(this.rules)},methods:{getUserInfo(){const a=this;v().then((e=>{const t=e.data.userInfo;a.avatarUrl=t.avatar_url,a.form.avatarId=t.avatar_id,a.form.nickName=t.nick_name}))},onClickAvatar(){this.chooseImage()},onChooseAvatar({detail:a}){},chooseImage(){const a=this;uni.chooseImage({count:1,sizeType:["original","compressed"],sourceType:["album","camera"],success({tempFiles:e}){a.tempFile=e[0],a.avatarUrl=a.tempFile.path}})},uploadFile(){const a=this;return _([a.tempFile]).then((e=>(a.form.avatarId=e[0],a.tempFile=null,!0))).catch((()=>(a.disabled=!1,!1)))},async handleSubmit(){const a=this;!0!==a.disabled&&a.$refs.uForm.validate((async e=>{e&&(a.disabled=!0,a.tempFile&&!(await a.uploadFile())||b({form:a.form}).then((e=>{a.$toast(e.message),setTimeout((()=>{a.disabled=!1,uni.navigateBack()}),1500)})).catch((e=>a.disabled=!1)))}))},onInputNickName(a){a&&(this.form.nickName=a)}}},[["render",function(h,v,b,_,k,g){const I=o,N=i("avatar-image"),F=m,y=f(u("u-form-item"),d),j=f(u("u-input"),c),C=f(u("u-form"),p);return a(),e(I,{class:"container",style:s(h.appThemeStyle)},{default:t((()=>[r(I,{class:"page-title"},{default:t((()=>[l("个人信息")])),_:1}),r(I,{class:"form-wrapper"},{default:t((()=>[r(C,{model:k.form,ref:"uForm","label-width":"140rpx"},{default:t((()=>[r(y,{label:"头像"},{default:t((()=>[r(F,{class:"btn-normal","open-type":"chooseAvatar",onClick:v[0]||(v[0]=a=>g.onClickAvatar()),onChooseavatar:g.onChooseAvatar},{default:t((()=>[r(N,{url:k.avatarUrl,width:100},null,8,["url"])])),_:1},8,["onChooseavatar"])])),_:1}),r(y,{label:"昵称",prop:"nickName"},{default:t((()=>[r(j,{modelValue:k.form.nickName,"onUpdate:modelValue":v[1]||(v[1]=a=>k.form.nickName=a),type:"nickname",maxlength:"30",placeholder:"请输入昵称",onInput:g.onInputNickName,onBlur:g.onInputNickName},null,8,["modelValue","onInput","onBlur"])])),_:1})])),_:1},8,["model"])])),_:1}),r(I,{class:"footer"},{default:t((()=>[r(I,{class:"btn-wrapper"},{default:t((()=>[r(I,{class:n(["btn-item btn-item-main",{disabled:k.disabled}]),onClick:v[2]||(v[2]=a=>g.handleSubmit())},{default:t((()=>[l("保存")])),_:1},8,["class"])])),_:1})])),_:1})])),_:1},8,["style"])}],["__scopeId","data-v-99cb96e6"]]);export{I as default};