<template>
  <div>
    <el-col>
      <el-row>
        <el-col :span="24">
          <el-card>
            <el-row>
              <h3>节点用量</h3>
            </el-row>
            <el-row>
              <el-col>
                <el-table
                  v-loading="tableLoading"
                  stripe
                  style="width: 100%"
                  :data="nodesList"
                  height="250"
                >
                  <el-table-column prop="host" label="host"></el-table-column>
                  <el-table-column prop="role" label="role"></el-table-column>
                  <el-table-column prop="node" label="node"></el-table-column>
                  <el-table-column
                    prop="node_cpu_utilisation"
                    label="CPU"
                  ></el-table-column>
                  <el-table-column
                    prop="node_disk_inode_utilisation"
                    label="inode 使用率"
                  ></el-table-column>
                  <el-table-column
                    prop="node_pod_utilisation"
                    label="容器组"
                  ></el-table-column>
                  <el-table-column
                    prop="node_memory_utilisation"
                    label="内存"
                  ></el-table-column>
                  <el-table-column
                    prop="node_disk_size_utilisation"
                    label="存储"
                  ></el-table-column>
                </el-table>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
    </el-col>
  </div>
</template>

<script>
import { getNodes } from "@/utils/token";
export default {
  name: "nodesort",

  data() {
    return {
      tableLoading: false,
    };
  },
  computed: {
    nodesList() {
      const nodes = this.$store.state.monitor.nodesList;
      var nodesList = [];
      for (var i = 0; i < nodes.length; i++) {
        const host = nodes[i].host;
        const node = nodes[i].node;
        const role = nodes[i].role;
        const node_cpu_utilisation = this.formatNumber(
          nodes[i].node_cpu_utilisation * 100
        );
        const node_disk_inode_utilisation = this.formatNumber(
          nodes[i].node_disk_inode_utilisation * 100
        );
        const node_pod_utilisation = this.formatNumber(
          nodes[i].node_pod_utilisation * 100
        );
        const node_memory_utilisation = this.formatNumber(
          nodes[i].node_memory_utilisation * 100
        );
        const node_disk_size_utilisation = this.formatNumber(
          nodes[i].node_disk_size_utilisation * 100
        );
        nodesList.push({
          host: host,
          node: node,
          role: role,
          node_cpu_utilisation: node_cpu_utilisation,
          node_disk_inode_utilisation: node_disk_inode_utilisation,
          node_cpu_utilisation: node_pod_utilisation,
          node_memory_utilisation: node_memory_utilisation,
          node_disk_size_utilisation: node_disk_size_utilisation,
        });
      }

      return nodesList;
    },
  },
  activated() {},

  mounted() {},

  methods: {
    formatNumber(num) {
      return Math.round(num * 100) / 100;
    },

    init() {
      this.$forceUpdate();
      // console.log('this.nodeList',this.nodesList);
    },
    //!这里还只是单节点的数据，日后修改为多节点的列表还需要修改一下数据结构
    initNodeList() {
      // console.log("nodesList", this.nodesList);

      const value = {
        host: this.nodes.host,
        node: this.nodes.node,
        role: this.nodes.role,
        node_cpu_utilisation: this.formatNumber(
          this.nodes.node_cpu_utilisation * 100
        ),
        node_disk_inode_utilisation: this.formatNumber(
          this.nodes.node_disk_inode_utilisation * 100
        ),
        node_pod_utilisation: this.formatNumber(
          this.nodes.node_cpu_utilisation * 100
        ),
        node_memory_utilisation: this.formatNumber(
          this.nodes.node_memory_utilisation * 100
        ),
        node_disk_size_utilisation: this.formatNumber(
          this.nodes.node_disk_size_utilisation * 100
        ),
      };
      this.$set(this.nodes, 0, value);
      // console.log('this.nodeList',this.nodesList)
    },
  },
};
</script>

<style lang="scss" scoped>
</style>