<template>
  <div class="app-container pageTopForm">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" label-width="80px" class="demo-ruleForm">
      <el-col :span="8">
        <el-form-item label="容器名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入容器名称"
            clearable
            @keyup.enter.native="handleQuery">
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item class="lastBtnSty">
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-col>
    </el-form>
    <!-- 表格数据 -->
    <TableList :columns="columns" :config="config" :queryParams="queryParams" :tableList="tableList" @fnClick="callback" @fnRenderList="getList" @value-change="handleValueChange"></TableList>
  </div>
</template>

<script>
  import TableList from "@/components/table/index.vue";
  import {listDockerInfo, delDockerInfo} from "@/api/agentCollect/collectData"
  export default {
    name: 'DockerData',
    components: {TableList},
    data() {
      return {
        tableList: [],
        loading: true,
        showSearch: true,
        // 列显隐信息
        columns: {
          id: {label: `ID`},
          name: {label: `容器名称`, minWidth: '200', visible: true},
          createTime: {label: `创建时间`, minWidth: '160', visible: true},
          status: {label: `容器状态`, minWidth: '160', visible: true},
          cpuUtil: {label: `容器CPU使用率(%)`, minWidth: '150', visible: true},
          memUtil: {label: `容器内存使用率(%)`, minWidth: '150', visible: true},
          netInSpeed: {label: `容器网络接收速率(KB/s)`, minWidth: '200', visible: true},
          netOutSpeed: {label: `容器网络发送速率(KB/s)`, minWidth: '200', visible: true},
          clientId: {label: `设备唯一标识`, minWidth: '160', visible: true},
        },
        config: {
          tableButton: {
            top: [
              {content: '新增', fnCode: 'add', type: 'primary', icon: 'el-icon-plus', hasPermi: 'agentCollect:dockerData:add'},
              {content: '删除', fnCode: 'delete', type: 'danger', icon: 'el-icon-delete', hasPermi: 'agentCollect:dockerData:delete'},
              {content: '导出', fnCode: 'export', type: 'primary', icon: 'el-icon-download', hasPermi: 'agentCollect:dockerData:export'},
            ],
            line: [
              {content: '修改', fnCode: 'edit', type: 'primary', icon: 'el-icon-edit', hasPermi: 'agentCollect:dockerData:edit'},
            ]
          }
        },
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          total: 0,
        }
      }
    },
    created() {
      this.getList();
    },
    activated() {
      // this.getList();
    },
    methods: {
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        let newParams = Object.assign({},{...this.queryParams}, {total: 0});
        listDockerInfo(newParams).then(response => {
          this.tableList = response.rows;
          this.queryParams.total = response.total;
          this.loading = false;
        })
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryRef");
        this.handleQuery();
      },

      // 处理子组件传递的新值
      handleValueChange(newValue) {
        // 父组件更新自身数据，实现同步
        this.showSearch = newValue;
        // console.log('父组件拿到新值:', newValue);
      },
      callback(result, rowData, selectChange, selectList) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'add':
              // this.$router.push({path:'/agentCollect/dockerData/view'});
              break;
            case 'edit':
              // this.$router.push({
              //   path:'/agentCollect/dockerData/view',
              //   query:{
              //     id: rowData.id
              //   }
              // });
              break;
            case 'delete':
              this.$modal.confirm('是否确认删除数据项？').then(function() {
                return delDockerInfo(selectChange)
              }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功")
              }).catch(() => {});
              break;
            case 'export':
              // let dataList = [];
              // Object.keys(this.columns).forEach(item => {
              //   if (item.visible) {
              //     dataList.push(item.prop);
              //   }
              // });
              // this.download("rocketmq/dockerInfo/export", {properties: dataList}, `容器数据_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("rocketmq/dockerInfo/export", paramsList, `容器数据_${new Date().getTime()}.xlsx`, null, 'json');
              break;
            default:
          }
        }
      }
    }
  }
</script>

<style scoped>
  ::v-deep .lastBtnSty .el-form-item__content{
    margin-left: unset!important;
  }
</style>
