<template>
  <div class="page_container">
    <bg-breadcrumb></bg-breadcrumb>
    <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-detail-table2 class="detail_info" :list="accountInfo">
              <template #state="{ data }">
                <p class="detail-module">
                  <span>{{ data.label }}</span>
                  <span :class="data.value ? 'active' : 'disabled'">{{ data.value ? "启用" : "禁用" }}</span>
                </p>
              </template>
            </bg-detail-table2>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

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

const accountInfo = reactive([
  {
    key: "name",
    label: "姓名",
    value: "",
  },
  {
    key: "organization",
    label: "所属组织",
    value: "",
  },
  {
    key: "system_account",
    label: "账号",
    value: "",
  },
  {
    key: "phone",
    label: "手机号",
    value: "",
  },

  {
    key: "system_role",
    label: "角色",
    value: "",
  },
  {
    key: "state",
    label: "是否启用",
    value: "",
    slot: "state",
  },
  {
    key: "created_name",
    label: "创建人",
    value: "",
  },
  {
    key: "created_time",
    label: "创建时间",
    value: "",
  },
]);

const logo = ref("");
const getDetail = () => {
  axios.get(`/v1/api/user/${route.query.id}`).then((res) => {
    if (res.data.code == 200) {
      const detail = res.data.data;
      accountInfo[0].value = detail.name;
      accountInfo[1].value = detail.organization;
      accountInfo[2].value = detail.system_account;
      accountInfo[3].value = detail.phone;
      accountInfo[4].value =
        detail.system_role_name && detail.system_role_name.length > 0 ? detail.system_role_name.join("、") : "";
      accountInfo[5].value = detail.state;
      accountInfo[6].value = detail.created_name;
      accountInfo[7].value = detail.created_time;
      logo.value = detail.logo;
    } else {
      ElMessage.error(res.data.data);
    }
  });
};

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

<style scoped lang="scss">
.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;
}
.detail-module {
  height: 100%;
  display: flex;
  span {
    height: 100%;
    display: inline-block;
    padding-left: 15px;
    box-sizing: border-box;
    &:nth-of-type(1) {
      background-color: #f7f7f9;
      min-width: 114px;
      border-right: solid 1px #dadee7;
    }
    &:nth-of-type(2) {
      flex-grow: 1;
      &::before {
        display: inline-block;
        content: "";
        width: 8px;
        height: 8px;
        margin-right: 4px;
        border-radius: 4px;
      }
      &.active {
        color: #3759be;
        &::before {
          background-color: #3759be;
        }
      }
      &.disabled {
        color: #ff9f51;
        &::before {
          background-color: #ff9f51;
        }
      }
    }
  }
}
</style>
