<template>
  <div class="settingMenu">
    <div class="menu">
      <div class="appInfo">
        <div class="img">
          <!-- <template v-if="name==='中台'">
            <img src="./images/1.png" alt="" style="width: 64px; height: 64px"/>
          </template>
          <template v-else-if="name==='U8C'">
            <img src="./images/2.png" alt="" style="width: 64px; height: 64px"/>
          </template>
          <template v-else-if="name==='U8'">
            <img src="./images/3.png" alt="" style="width: 64px; height: 64px"/>
          </template>
          <template v-else-if="name==='BIP'">
            <img src="./images/4.png" alt="" style="width: 64px; height: 64px"/>
          </template>
          <template v-else-if="name==='ERP'">
            <img src="./images/5.png" alt="" style="width: 64px; height: 64px"/>
          </template> -->
          <template>
            <img :src="imgUrl" alt="" style="width: 64px; height: 64px"/>
          </template>
        </div>
        <div class="appName">{{ name }}</div>
        <div class="version">{{ versionNumber }}</div>
      </div>
      <div class="menuList">
        <div class="item" v-for="(item, index) in settingMunu" :key="index" @click="menuClick(index, item)">
          <div class="icon" :class="{ actived: index == menuActived }">
            <svg-icon class="iconfont" :icon-class="item.icon" fill="currentColor"/>
          </div>
          <div class="title">{{ item.title }}</div>
        </div>
      </div>
    </div>
    <div class="content">
      <router-view @saveSuccess="saveSuccess" @flashActive="flashActive"></router-view>
    </div>
  </div>
</template>

<script>
import {getApiModuleApi} from "@/api/apiChunks/index.js";
import configData from "./configData";
// 应用信息
import applicationAdd from "./applicationAdd.vue";
// API接口清单
import apiList from "./apiList/apiAdmin.vue";
import request from "@/utils/request";

export default {

  data() {
    return {
      menuActived: 0,
      settingMunu: configData.settingMenu,
      query: this.$route.query,
      name: "",
      imgUrl: "",
      versionNumber: "",
    };
  },
  methods: {
    flashActive(val) {
      this.menuActived = val
    },
    async initEditFormData() {
      const res = await getApiModuleApi({
        tl: "sysApplicationService",
        as: "application",
        dj: "getApp"
      }, {id: this.$route.query.id})
      if (res.status === '200') {
        this.name = res.attribute.name
        this.versionNumber = res.attribute.versionNumber
        //下载logo
        return request({
          url: "/kangarooDataCenter/entranceController/fileDownloadNew?id=" + res.attribute.appLogo,
          method: "get",
          responseType: 'arraybuffer'
        }).then((res) => {
          this.imgUrl =
            "data:image/png/jpg;base64," + btoa(new Uint8Array(res).reduce((data, byte) => data + String.fromCharCode(byte), ""));
        })
      }
    },
    //菜单点击事件
    saveSuccess() {
      this.initEditFormData()
    },
    menuClick(index, item) {
      if (item.path && !this.$route.path.includes(item.path)) {
        this.menuActived = index;
        this.$router.replace({
          name: item.path,
          query: this.query
        });
      }
    },
  },
  components: {
    applicationAdd,
    apiList,
  },
  created() {
    this.initEditFormData()
  }
};
</script>

<style scoped lang='scss'>
.settingMenu {
  width: 100%;
  display: flex;
  position: relative;
  background: #fafafa !important;
  overflow: auto;

  .menu {
    position: fixed;
    width: 11%;
    height: 90vh;
    //margin-right: 1%;
    background-color: #fff;
    border-radius: 16px;
    overflow: auto;

    .appInfo {
      padding: 16px 0;
      border-bottom: 1px solid #f3f3f3;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      > .img {
        width: 64px;
        height: 64px;
      }

      .appName {
        margin-top: 8px;
        font-weight: 600;
        font-size: 18px;
      }

      > .version {
        margin-top: 1px;
        font-size: 12px;
        padding: 1px 2px;
        border: 1px solid #ff8b0f;
        color: #ff8b0f;
      }
    }

    .menuList {
      margin-top: 20px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .item {
        margin-bottom: 24px;

        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        > .icon {
          width: 64px;
          height: 64px;
          text-align: center;
          border-radius: 12px;
          display: flex;
          justify-content: center;
          align-items: center;

          > .iconfont {
            font-weight: 300;
            font-size: 37px;
            color: #000;
          }

          &:hover {
            background-color: #1478f6 !important;

            > .iconfont {
              color: #fff !important;
            }
          }
        }

        > .title {
          margin-top: 11px;
          color: #333333;
          font-size: 18px;
          font-weight: 600;
          user-select: none;
        }
      }

      .actived {
        background-color: #1478f6 !important;

        > .iconfont {
          color: #fff !important;
        }
      }
    }
  }

  .content {
    margin-left: 11.5%;
    width: 88%;
    border-radius: 16px;
  }
}
</style>
