<script setup>
import {upload_img} from "@/apis/index.js";
import {useUserStore} from '@/stores/userStore.js'
import {storeToRefs} from "pinia";
import defaultImg from "@/assets/images/zu1171@2x.png"
const userStore = useUserStore()
const {recentPhoto} = storeToRefs(userStore);
const afterRead = async (file) => {
  const res = await upload_img({
    file: file.file,
    source: "artwork",
    type: 'image'
  })
  if (res.status === 0) {
    recentPhoto.value=res.data.ori_url
  }
}
</script>

<template>
  <div class="two-content">
    <van-uploader :afterRead="afterRead">
      <div class="content1">
        <div class="wrap1">
          <div v-show="!recentPhoto" class="wrap1_1">

            <img  class="wrap1_1_2"  :src="defaultImg">
          </div>
          <div v-show="recentPhoto" class="wrap1_2">
            <img  class="wrap1_2_1"  :src="recentPhoto">
          </div>
          <div class="wrap1_3" v-show="recentPhoto">更换</div>
        </div>
        <div class="wrap2">上传近照</div>
      </div>
    </van-uploader>
    <div class="bottom-text">*点击相机上传/拍摄近照</div>
  </div>
</template>

<style scoped lang="scss">
.two-content {
  margin-bottom: 115px;
}

.bottom-text {
  text-align: right;
  margin-top: 8px;
  color: #FFFFFF;
  font-size: 12px;
}

.content1 {
  box-sizing: border-box;
  width: 332px;
  height: 377px;
  background-color: #fff;
  border-radius: 10px;
  padding: 16px 20px 10px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;

  .wrap2 {
    margin-top: 6px;
    color: #2159C4;
    font-size: 10px;
  }
  .wrap1 {
    overflow: hidden;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border: 2px solid #2159C4;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    .wrap1_3{
      border-radius: 20px;
      font-size: 14px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      width: 48px;
      height: 32px;
      background-color: #2159C4;
      position: absolute;
      bottom: 12px;
      right: 12px;
    }
    .wrap1_2{
     display: flex;
      align-items: center;
      justify-content: center;
      img{
        max-width: 293px;
        height: 330px;
      }
    }
    .wrap1_1 {
      width: 256px;
      height: 297px;
      background-image: url("@/assets/images/zu1174@2x.png");
      background-size: cover;
      display: flex;
      justify-content: center;
      align-items: center;
      .wrap1_1_1{
        margin: -18px;
        width: 100%;
        max-height: 297.5px;
      }
      .wrap1_1_2 {
        width: 75px;
        height: 75px;
      }
    }
  }
}
</style>
