<template>
  <div class="app-container pageTopForm">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" size="small" label-width="130px">
      <el-col :span="12">
        <el-form-item label="模版名称" prop="templateName">
          <el-input
            v-model="queryParams.templateName"
            placeholder="请输入模版名称"
            clearable
            @keyup.enter.native="handleQuery"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item class="lastBtnSty">
          <el-button type="primary" size="mini" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-col>
    </el-form>
    <TableList :columns="columns" :config="config" :modelIdent="this.$options.name" :queryParams="queryParams" :tableList="tableList" @fnClick="callback" @fnRenderList="getList" @value-change="handleValueChange">
      <template #tempType="{ row, column }">
        <dict-tag :options="dict.type.rm_topology_type" :value="row.connectedDeviceType"/>
      </template>
    </TableList>
  </div>
</template>

<script setup>
  import TableList from "@/components/table/index.vue"
  import {listMonitorTemp, delMonitorTemp} from "@/api/disRevenue/resource"
  export default {
    name: 'MonitorTemp',
    components: {TableList},
    dicts: ['rm_topology_type'],
    data() {
      return {
        loading: true,
        showSearch: true,
        tableList: [],
        queryParams: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        },
        // 列显隐信息
        columns: {
          id: { label: `ID`,width: '50'},
          templateName: { label: `模版名称`,minWidth: '150', visible: true },
          description: { label: `描述`,visible: false, minWidth: '200'},
          monitorItems: { label: `监控项`, minWidth: '100', visible: true },
          discoveryRules: { label: `自动发现项`, minWidth: '100', visible: true },
          resourceGroupName: { label: `包含资源`, minWidth: '200'},
          createTime: { label: `创建时间`, minWidth: '160'},
          updateTime:{ label: `修改时间`, minWidth: '160'}
        },
        config: {
          searcherForm: [
            {label: '模版名称', prop: 'roleName', type: 'selset', options: []}
          ],
          tableButton: {
            top: [
              {content: '新增', fnCode: 'add', type: 'primary', icon: 'el-icon-plus', hasPermi: 'resource:monitorTemp:add'},
              {content: '删除', fnCode: 'delete', type: 'danger', icon: 'el-icon-delete', hasPermi: 'resource:monitorTemp:delete'},
              {content: '导出', fnCode: 'export', type: 'warning', icon: 'el-icon-download', hasPermi: 'resource:monitorTemp:export'},
            ],
            line: [
              {content: '修改', fnCode: 'edit', type: 'primary', icon: 'el-icon-edit', hasPermi: 'resource:monitorTemp:edit'},
              {content: '详情', fnCode: 'details', type: 'primary', icon: 'el-icon-view', hasPermi: 'resource:monitorTemp:details'},
              // {content: '复制', fnCode: 'copy', type: 'primary', icon: 'el-icon-document-copy', hasPermi: 'disRevenue:resource:monitorTemp:copy'},
            ]
          }
        }
      }
    },
    created() {
      this.getList();
    },
    activated() {
      this.$nextTick(() => {
        this.getList();
      });
    },
    methods: {
      /** 查询列表 */
      getList() {
        // this.$modal.loading();
        listMonitorTemp(this.queryParams).then(response => {
          this.tableList = response.rows;
          this.queryParams.total = response.total;
          // this.$modal.closeLoading();
        })
      },
      // 处理子组件传递的新值
      handleValueChange(newValue) {
        // 父组件更新自身数据，实现同步
        this.showSearch = newValue;
        // console.log('父组件拿到新值:', newValue);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

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

      callback(result, rowData, selectChange, selectList) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'add':
              this.$router.push({
                path:'/resource/monitorTemp/details/index'});
              break;
            case 'edit':
              this.$router.push({
                path:'/resource/monitorTemp/details/index',
                query:{
                  id: rowData.id
                }
              });
              break;
            case 'details':
              this.$router.push({
                path:'/resource/monitorTemp/view/index',
                query:{
                  id: rowData.id,
                  readonly: true
                }
              });
              break;
            case 'delete':
              if (selectList && selectList.length <= 0) {
                this.$modal.msgWarning("请选择数据！");
                return;
              }
              this.$modal.confirm('是否确认删除数据项？').then(function() {
                return delMonitorTemp(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("/system/monitorTemp/export", {properties: dataList}, `拓扑管理_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("rocketmq/template/export", paramsList, `监控模版_${new Date().getTime()}.xlsx`, null, 'json');
              break;
            default:
          }
        }
      }
    }
  }
</script>
<style scoped>
  ::v-deep .lastBtnSty .el-form-item__content{
    margin-left: 10px!important;
  }
</style>
