<template>
  <div class="page_container">
    <div class="bg-breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> 组织管理 </el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/system/organization' }"> 组织管理 </el-breadcrumb-item>
        <el-breadcrumb-item> 用户详情 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="page_content apaas_scroll">
      <div class="info_row">
        <div class="title">
          <div><span class="icon_box"></span> 账号信息</div>
          <div class="dashed_line"></div>
        </div>
        <div class="info_content">
          <div class="img_box">
            <img v-if="logo" :src="logo" style="height: 96px; width: 96px; border-radius: 99px" alt="" />
            <img
              v-else
              src="/src/assets/imgs/home_ic_user.png"
              style="height: 96px; width: 96px; border-radius: 99px"
              alt="" />
          </div>
          <div class="info_box">
            <bg-info :data="accountInfo"></bg-info>
          </div>
        </div>
      </div>
      <div>
        <div class="title">
          <div><span class="icon_box"></span> 个人信息</div>
          <div class="dashed_line"></div>
        </div>
        <div class="info_content">
          <div class="img_box"></div>
          <div class="info_box">
            <bg-info v-if="accountType === 2" :data="personInfo"></bg-info>
            <bg-info v-if="accountType === 3" :data="personInfo2"></bg-info>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, toRefs, ref, computed, onBeforeMount } from "vue";
import { useRoute } from "vue-router";
import axios from "@/request/http.js";
import { ElMessage } from "element-plus";
const route = useRoute();

const accountInfo = reactive([
  {
    name: "手机号",
    value: "",
    nameWidth: 130,
  },
  {
    name: "账号",
    value: "",
    nameWidth: 130,
  },
  {
    name: "角色",
    value: "",
    nameWidth: 130,
  },
  {
    name: "所属组织",
    value: "",
    nameWidth: 130,
  },
  {
    name: "创建人",
    value: "",
    nameWidth: 130,
  },
  {
    name: "创建账号",
    value: "",
    nameWidth: 130,
  },
  {
    name: "最后编辑时间",
    value: "",
    nameWidth: 130,
  },
  {
    name: "创建时间",
    value: "",
    nameWidth: 130,
  },
]);

const personInfo = reactive([
  {
    name: "姓名",
    value: "",
    nameWidth: 130,
  },
  {
    name: "邮箱",
    value: "",
    nameWidth: 130,
  },
  {
    name: "证据类型",
    value: "",
    nameWidth: 130,
  },
  {
    name: "身份证号",
    value: "",
    idCard: true,
    nameWidth: 130,
  },
  {
    name: "备注",
    value: "",
    full: true,
    nameWidth: 130,
  },
]);

const personInfo2 = reactive([
  {
    name: "姓名",
    value: "",
    nameWidth: 130,
  },
  {
    name: "邮箱",
    value: "",
    nameWidth: 130,
  },
  {
    name: "备注",
    value: "",
    full: true,
    nameWidth: 130,
  },
]);

const logo = ref("");
const accountType = ref(2); //1.业务系统账号 2.组织管理员账号 3.平台用户账号
const getDetail = () => {
  axios.get(`/apaas/system/v5/org/user/${route.query.id}`).then((res) => {
    if (res.data.code == 200) {
      const detail = res.data.data;
      accountInfo[0].value = detail.contact_phone;
      accountInfo[1].value = detail.system_account;
      accountInfo[2].value = detail.system_role && detail.system_role.length > 0 ? detail.system_role.join("、") : "";
      accountInfo[3].value = detail.organization;
      accountInfo[4].value = detail.created_by;
      accountInfo[5].value = detail.created_by_account;
      accountInfo[6].value = detail.updated_time;
      accountInfo[7].value = detail.created_time;
      personInfo[0].value = detail.contact_name;
      personInfo[1].value = detail.contact_email;
      personInfo[2].value = detail.document_type === 1 ? "身份证" : "";
      personInfo[3].value = detail.document_number;
      personInfo[4].value = detail.remark;
      personInfo2[0].value = detail.contact_name;
      personInfo2[1].value = detail.contact_email;
      personInfo2[2].value = detail.remark;
      logo.value = detail.logo;
      accountType.value = detail.is_admin;
    } else {
      ElMessage.error(res.data.data);
    }
  });
};

onBeforeMount(() => {
  if (route.query.id) {
    getDetail();
  }
});
</script>

<style scoped>
.page_content {
  padding: 15px;
  overflow: auto;
}
.info_content {
  display: flex;
}
.info_row {
  margin-bottom: 40px;
}
.img_box {
  width: 120px;
}
.info_box {
  width: 60%;
}

.title {
  font-size: 18px;
  color: #1a1a1a;
  font-weight: bold;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}
.dashed_line {
  flex: 1;
  height: 1px;
  margin: 0 10px;
  border-bottom: dashed 1px #dadee7;
}

.icon_box {
  display: inline-block;
  width: 4px;
  height: 14px;
  background-color: #3759be;
  border-radius: 2px;
  margin-right: 5px;
}
</style>
