<template>
  <div class="user-box" :class="{ 'mobile-user': isMobile }">
    <div class="title">Basic information</div>
    <div class="formBox">
      <div class="item">
        <div class="label">Nickname：</div>
        <div class="val">{{ user.name }}</div>
      </div>
      <div class="item">
        <div class="label">Mobile phone number：</div>
        <div class="val">{{ user.contact }}</div>
        <span class="iconfont icon-sousuo" @click="handleEdit('info')"></span>
      </div>
      <div class="item">
        <div class="label">Change password：</div>
        <!-- <div class="val"></div> -->
        <span class="iconfont icon-sousuo" @click="handleEdit('password')"></span>
      </div>
      <div class="item">
        <div class="label">Company name：</div>
        <div class="val"> {{ user.companyName || "--" }}</div>
        <span class="iconfont icon-sousuo" @click="handleEdit('info')"></span>
      </div>
      <div class="item">
        <div class="label">Company position：</div>
        <div class="val">{{ user.addr || "--" }}</div>
        <span class="iconfont icon-sousuo" @click="handleEdit('info')"></span>
      </div>
      <div class="item">
        <div class="label">Email address：</div>
        <div class="val">{{ user.email }}</div>
        <span class="iconfont icon-sousuo" @click="handleEdit('info')"></span>
      </div>
      <!-- <div class="item">
        <div class="label">Contact number：</div>
        <div class="val">13512458745</div>
        <span class="iconfont icon-sousuo" @click="handleEdit('info')"></span>
      </div> -->
    </div>
  </div>
  <n-modal :show="editVisible" :title="editTitle" :showIcon="false" :close-on-esc="false" :mask-closable="false" @esc="editVisible = false" @mask-click="editVisible = false" @close="editVisible = false" class="modalCls" :class="{ 'login-dialog': isMobile }">
    <updatePwd v-if="editType == 'password'" @closeSginDialog="closeSginDialog"></updatePwd>
    <updateInfo :info="user" v-if="editType == 'info'" @closeSginDialog="closeSginDialog"></updateInfo>
  </n-modal>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue";
import { createDiscreteApi } from "naive-ui";
import { set } from "~/node_modules/nuxt/dist/app/compat/capi";
import updateInfo from "./update-info.vue";
import updatePwd from "./updatePwd.vue";
import { useI18n } from "#imports";
const message = createDiscreteApi(["message"]);
const { t } = useI18n();
const props = defineProps({
  isMobile: {
    type: Boolean,
    default: false,
  },
});

const user = ref({});
const editVisible = ref(false);
const editTitle = ref(t("myInfo.modify"));
const editType = ref("password");

const getUser = async () => {
  let { code, data } = await getUser_Api();
  if (code === 200) {
    user.value = data;
  }
};

const handleEdit = (type: string) => {
  editType.value = type;
  editVisible.value = true;
  if (type == "password") {
    editTitle.value = t("myInfo.password");
  } else {
    editTitle.value = t("reportPop.title");
  }
};

const closeSginDialog = () => {
  editVisible.value = false;
  editType.value = "";
  getUser();
};
getUser();
</script>

<style lang="scss" scoped>
@import "~/assets/css/tool.scss";
.user-box {
  height: 100%;
  .title {
    font-size: var(--size-24);
    font-family: Arial, Arial-Bold;
    font-weight: 700;
    color: #1a1a1a;
    line-height: var(--size-44);
    padding-bottom: var(--size-7);
    border-bottom: var(--size-1) solid #e6e6e6;
  }
  .formBox {
    padding-bottom: var(--size-150);
    .item {
      display: flex;
      align-items: center;
      border-bottom: var(--size-1) solid #f5f5f5;
      margin-bottom: var(--size-10);
      .label {
        font-size: var(--size-18);
        font-family: Arial, Arial-Regular;
        color: #666666;
        line-height: var(--size-63);
      }
      .val {
        font-size: var(--size-18);
        font-family: Arial, Arial-Regular;
        color: #1a1a1a;
        line-height: var(--size-63);
      }
      .iconfont {
        color: #00b0fd;
        display: inline-block;
        margin-left: var(--size-20);
        font-size: var(--size-18);
        cursor: pointer;
      }
    }
  }
}
.modalCls {
  width: var(--size-720) !important;
}

@include responseTo("phone") {
  .user-box {
    .formBox {
      padding-bottom: var(--size-30);
      margin-top: var(--size-15);
      .item {
        align-items: baseline;
        border-bottom: var(--size-1) solid #f5f5f5;
        margin-bottom: var(--size-10);
        .label {
          font-size: var(--size-14);
          font-family: Arial, Arial-Regular;
          color: #666666;
          line-height: var(--size-30);
          flex-shrink: 0;
          padding-bottom: var(--size-10);
        }
        .val {
          font-size: var(--size-14);
          font-family: Arial, Arial-Regular;
          color: #1a1a1a;
          line-height: var(--size-30);
          padding-bottom: var(--size-10);
        }
        .iconfont {
          color: #00b0fd;
          display: inline-block;
          margin-left: var(--size-20);
          font-size: var(--size-14);
          cursor: pointer;
        }
      }
    }
  }
}
</style>
