<template>
  <el-container>
    <el-header height="220">
      <el-row style="margin-top: 10px">
        <el-select
          v-model="queryInfo.path"
          clearable
          placeholder="查询条件"
          style="margin-left: 5px"
          @change="onSelectChange"
        >
          <el-option v-for="(item, index) in tableList" :key="index" :label="item" :value="item" />
        </el-select>
      </el-row>
      <el-row style="margin-top: 10px">
        <el-tag v-for="(item, index) in tableList" :key="index" style="margin-left: 5px" :type="'warning'" disable-transitions>
          {{ item }}
        </el-tag>
      </el-row>
    </el-header>
    <el-main>
      <el-table
        :data="dataList"
        border
        style="width: 100%"
      >
        <el-table-column
          fixed="left"
          label="No"
          type="index"
        />
        <el-table-column
          prop="application"
          label="应用"
        />
        <el-table-column
          prop="total"
          label="节点数量"
        />
        <el-table-column
          prop="hostPorts"
          label="节点地址"
        />
        <el-table-column
          prop="role"
          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"
              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"
      width="30%"
      center
    >
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>修改视频可见范围</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateScope">更新</el-button>
        </div>
        <div class="text item">
          <el-select v-model="form.scope" placeholder="选择可见范围">
            <el-option label="本人可见" value="1" />
            <el-option label="所有人可见" value="2" />
            <el-option label="VIP 可见" value="3" />
            <el-option label="验证码可见" value="4" />
          </el-select>
        </div>
      </el-card>
    </el-dialog>
  </el-container>
</template>

<script>
import { getDubboList, getZkList, getZkService } from '@/api/tnb'

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

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

<style>
</style>
