<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="客户端ID" prop="clientId">
          <el-input
            v-model="queryParams.clientId"
            placeholder="请输入客户端ID"
            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 {listDiskInfo, delDiskInfo} from "@/api/agentCollect/collectData"
  export default {
    name: 'DiskData',
    components: {TableList},
    data() {
      return {
        tableList: [],
        loading: true,
        showSearch: true,
        // 列显隐信息
        columns: {
          id: {label: `ID`},
          clientId: {label: `客户端ID`, minWidth: '160', visible: true},
          createTime: {label: `创建时间`, minWidth: '160', visible: true},
          name: {label: `磁盘名称`, minWidth: '150', visible: true},
          serial: {label: `磁盘序列号`, minWidth: '150', visible: true},
          total: {label: `磁盘总大小(GB)`, minWidth: '150', visible: true},
          writeSpeed: {label: `磁盘写入速率(字节/秒)`, minWidth: '200', visible: true},
          readSpeed: {label: `磁盘读取速率(字节/秒)`, minWidth: '150', visible: true},
          writeTimes: {label: `磁盘写入次数`, minWidth: '150', visible: true},
          readTimes: {label: `磁盘读取次数`, minWidth: '150', visible: true},
          writeBytes: {label: `磁盘写入总字节数`, minWidth: '150', visible: true},
          readBytes: {label: `磁盘读取总字节数`, minWidth: '150', visible: true},
        },
        config: {
          tableButton: {
            top: [
              {content: '新增', fnCode: 'add', type: 'primary', icon: 'el-icon-plus', hasPermi: 'agentCollect:diskData:add'},
              {content: '删除', fnCode: 'delete', type: 'danger', icon: 'el-icon-delete', hasPermi: 'agentCollect:diskData:delete'},
              {content: '导出', fnCode: 'export', type: 'primary', icon: 'el-icon-download', hasPermi: 'agentCollect:diskData:export'},
            ],
            line: [
              {content: '修改', fnCode: 'edit', type: 'primary', icon: 'el-icon-edit', hasPermi: 'agentCollect:diskData: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});
        listDiskInfo(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/diskData/view'});
              break;
            case 'edit':
              // this.$router.push({
              //   path:'/agentCollect/diskData/view',
              //   query:{
              //     id: rowData.id
              //   }
              // });
              break;
            case 'delete':
              this.$modal.confirm('是否确认删除数据项？').then(function() {
                return delDiskInfo(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/diskInfo/export", {properties: dataList}, `磁盘数据_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("rocketmq/diskInfo/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>
