<template>
  <div class="user-base-info">
    <div class="title">基本信息</div>
    <div class="content-info">
      <div class="user-icon" @click="upload">
        <div class="box">
          <img v-if="infos.icon" :src="infos.icon" />
          <i v-else class="iconfont iconpaishe"></i>
        </div>
        <p v-if="infos.icon">修改头像</p>
        <p v-else>上传头像</p>
      </div>
      <div class="msg-info">
        <div class="top">
          <h1>欢迎&nbsp;&nbsp;{{ infos.phone || infos.email }}</h1>
          <div class="info-states">
            <div class="imgbox">
              <img
                v-if="infos.auth_suc === 1"
                src="/images/userCenter/state2.png"
              />
              <img
                v-else
                src="/images/userCenter/state1.png"
              />
            </div>
          </div>
        </div>
        <p>
          <span>UID账户：</span>
          {{ getuid }}
        </p>
      </div>
    </div>
    <common-dialog
      v-if="UploadPicturesShow"
      @closePopup="UploadPicturesShow = false"
      showMask
      type="element"
      :visible="UploadPicturesShow"
      :elementDialogProps="{
        title: '上传头像',
        width: '600px',
      }"
      :noPadding="true"
      :btnConfig="{
        type: 'noBorder', 
        btns: [{
            name: '取消',
            disabled: false,
            loading: false,
            type: 'default' as const,
        },
        {
            name: '确定',
            disabled: false,
            loading: false,
            type: 'primary' as const,
        }
        ],
        btnFunctions: [{
            name: '取消',
             click: async()=>{
                return callDialogMethod('headPortrait', 'cancel')
            },
        }, {
            name: '确定',
             click: async()=>{
                return callDialogMethod('headPortrait', 'Confirm')
            },
        }]
      }"
    >
      <head-portrait
        v-if="UploadPicturesShow"
        ref="headPortrait"
        @close="UploadPicturesShow = false"
        @logoUrl="logoUrl"
      ></head-portrait>
    </common-dialog>
  </div>
</template>

<script lang="ts">
import { $ajax } from "@/service";
import { syCommonDialog, GO_URLS } from "cqk-sy-ui";
import { ElMessage } from "element-plus";
import { defineComponent } from "vue";
import HeadPortrait from "./HeadPortrait.vue";

export default defineComponent({
  components: {
    CommonDialog: syCommonDialog,
    HeadPortrait,
  },
  props: ["infos"],
  data() {
    return {
      UploadPicturesShow: false,
    };
  },
  computed: {
    getuid() {
      return JSON.parse(String(sessionStorage.getItem("user"))).id;
    },
  },
  methods: {
    async callDialogMethod(refName: string, methodName: string) {
      return (this.$refs as any)[refName][methodName]();
    },
    // 显示图片上传组件
    upload() {
      this.UploadPicturesShow = true;
    },
    async logoUrl(data: any) {
      const res = await $ajax({
        type: "patch",
        url: GO_URLS.user + `/` + this.getuid,
        params: { icon: (data || {}).url },
      });
      if (res) {
        ElMessage({
          message: "头像上传成功",
          type: "success",
        });
        this.$emit("ToUpdate");
      }
    },
  },
});
</script>

<style scoped lang="scss">
.user-base-info {
  width: 49.5%;
  height: 350px;
  margin-right: 24px;
  border-radius: 4px;
}

.title {
  padding-left: 28px;
  line-height: 60px;
  color: #979797;
  font-size: 14px;
  background: #fff;
}
.content-info {
  position: relative;
  margin-top: 1px;
  height: 290px;
  background: #fff;
}
.user-icon {
  margin: 30px 45px 0 44px;
  float: left;
  cursor: pointer;
  .box {
    width: 80px;
    height: 80px;
    background: rgba(242, 244, 246, 1);
    box-shadow: 2px 2px 4px 0px rgba(0, 1, 3, 0.12);
    border-radius: 50%;
    border: 5px solid white;
    text-align: center;
    cursor: pointer;
    overflow: hidden;
    line-height: 80px;
    img {
      width: 100%;
      height: 100%;
    }
    i {
      font-size: 28px;
      color: #bfbfbf;
    }
  }
  p {
    text-align: center;
    font-size: 14px;
    font-weight: 400;
    color: rgba(121, 125, 132, 1);
    line-height: 35px;
    margin: 0;
  }
}
.msg-info {
  float: left;
}
.top {
  overflow: hidden;
}
.info-states {
  float: left;
  padding-top: 37px;
  padding-left: 10px;
  .imgbox {
    width: 73px;
    height: 26px;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
h1 {
  margin-top: 40px;
  margin-bottom: 40px;
  float: left;
  font-size: 20px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  color: rgba(37, 38, 49, 1);
  line-height: 1;
}
p {
  color: #252631ff;
  font-size: 14px;
  margin: 0;
  padding: 0;
  margin-top: 10px;
}
span {
  color: var(--text-gray)ff;
  font-size: 14px;
}
</style>
