<template>
  <el-container>
    <el-header height="220">
      <h3>对象列表</h3>
      <el-row style="margin-top: 10px">
        <el-button type="plain" icon="el-icon-files">存储节点</el-button>
        <el-select
          v-model="selectedValue"
          style="margin-left: 5px"
          @change="onSelectChange"
        >
          <el-option v-for="(item, index) in tableList" :key="index" :label="item.label" :value="item.value" />
        </el-select>
      </el-row>
    </el-header>
    <el-main>
      <el-table
        :data="dataList"
        border
        height="480"
        style="width: 100%"
      >
        <el-table-column
          fixed="left"
          label="No"
          type="index"
        />
        <el-table-column
          prop="nodeAddr"
          label="文件名"
        />
        <el-table-column
          prop="httpPort"
          label="修改时间"
        />
        <el-table-column
          prop="rpcPort"
          label="大小"
        />
        <el-table-column
          prop="status"
          label="文件类型"
        />
        <el-table-column
          fixed="right"
          label="操作"
          width="280"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >磁盘详情</el-button>
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >禁用</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>

    <!-- 修改视频可见范围对话框 -->
    <el-dialog
      append-to-body
      :visible.sync="showEditScopeDialog"
      center
    >
      <div>
        <h3>存储节点磁盘详情</h3>
        <el-table
          :data="tableList"
          border
          height="480"
          style="width: 100%"
        >
          <el-table-column
            fixed="left"
            label="No"
            type="index"
          />
          <el-table-column
            prop="fsType"
            label="文件系统"
          />
          <el-table-column
            prop="volume"
            label="磁盘分区"
          />
          <el-table-column
            prop="storeDir"
            label="存储目录"
          />
          <el-table-column
            prop="total"
            label="分区容量"
          >
            <template slot-scope="scope">
              <el-progress :percentage="scope.row.percent"></el-progress>
            </template>
          </el-table-column>
          <el-table-column
            prop="totalInode"
            label="inode 容量"
          >
            <template slot-scope="scope">
              <el-progress :percentage="scope.row.percentInode"></el-progress>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
import { getUserNodeKeyValue } from '@/api/oss'

export default {
  name: 'AdminStoreObject',
  data() {
    return {
      queryInfo: {
        path: null
      },
      // 屏幕宽度, 为了控制分页条的大小
      screenWidth: document.body.clientWidth,
      currentPage: 1,
      pageSize: 12,
      totalSize: 0,
      dataList: [],
      tableList: [],
      nextId: 0,
      // **********************************************************************
      showEditScopeDialog: false,
      form: {
        videoId: null,
        scope: 1
      }
    }
  },
  created() {
    document.title = '存储节点'
    this.getData()
  },
  methods: {
    getData() {
      this.tableList = []
      getUserNodeKeyValue().then(resp => {
        if (resp.code === 0) {
          this.tableList = resp.data

          this.selectedValue = this.tableList[0].value
          this.dataList = []
        } else {
          this.$message.error(resp.msg)
        }
      })
    },
    onRefresh() {
      this.getData()
    },
    handleCurrentChange(pageNumber) {
      this.currentPage = pageNumber
      this.getData()
      // 回到顶部
      scrollTo(0, 0)
    },
    handleEdit(index, row) {
      this.showEditScopeDialog = true
    },
    handleDelete(index, row) {
      this.$confirm('确定要删除 ' + row.title + '?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message.info('handleDelete')
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    onAddChannel() {
      this.showEditScopeDialog = false
    },
    onSelectChange() {
      this.dataList = []
    },
    handleClose() {
    }
  }
}
</script>

<style>
</style>
