<template>
  <div class="app-container pageTopForm">
    <el-form :model="queryParams" ref="queryRef" size="small" v-show="showSearch" label-width="auto">
      <el-col :span="8">
        <el-form-item label="ClientID" prop="clientId">
          <el-input
            v-model="queryParams.clientId"
            placeholder="请输入ClientID"
            clearable
            @keyup.enter.native="handleQuery"/>
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="FRPC服务状态" title="FRPC服务状态" prop="frpcStatus">
          <el-select
            v-model="queryParams.frpcStatus"
            placeholder="请选择FRPC服务状态"
            clearable>
            <el-option
              v-for="dict in dict.type.frpc_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"/>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <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" :modelIdent="this.$options.name" :queryParams="queryParams" :tableList="tableList" @fnClick="callback" @fnRenderList="getList" @value-change="handleValueChange">
      <template #tempFrpcStatus="{ row, column }">
        <dict-tag :options="dict.type.frpc_status" :value="row.frpcStatus"/>
      </template>
      <template #tempFrpcConnect="{ row, column }">
        <dict-tag :options="dict.type.frpc_connection_status" :value="row.frpcConnectionStatus"/>
      </template>
    </TableList>
  </div>
</template>

<script setup>
  import TableList from "@/components/table/index.vue"
  import {listFrpcConfig} from "@/api/disRevenue/resource"
  export default {
    name: 'frpServerManage',
    components: {TableList},
    dicts: ['frpc_status', 'frpc_connection_status'],
    data() {
      return {
        loading: true,
        showSearch: true,
        tableList: [],
        queryParams: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        },
        // 列显隐信息
        columns: {
          id: { label: `ID`,width: '50'},
          clientId: { label: `clientID`, minWidth: '250', visible: true },
          mgmtPublicIp:{ label: `管理网-公网IP`,minWidth: '120'},
          mgmtInterfaceName: { label: `管理网-接口名称`, minWidth: '120'},
          mgmtMacAddress: { label: `管理网-mac地址`, minWidth: '150'},
          mgmtInterfaceType: { label: `管理网-接口类型`, minWidth: '120'},
          mgmtIpv4Address: { label: `管理网-IPv4地址`, minWidth: '120'},
          mgmtGateway: { label: `管理网-网关`, minWidth: '120'},
          frpcRemotePort: { label: `FRPC_remotePort`,minWidth: '140', visible: true},
          frpcCreateTime: { label: `链接生成时间`,minWidth: '130'},
          frpcServerAddr: { label: `FRPC_serverAddr`, minWidth: '140', visible: true},
          frpcServerPort: { label: `FRPC_serverPort`,minWidth: '140', visible: true},
          frpcStatus: { label: `FRPC服务状态`,minWidth: '120', visible: true, slotName: 'tempFrpcStatus'},
          frpcName: { label: `FRPC_name`,minWidth: '100'},
          frpcType: { label: `FRPC_tcp`,minWidth: '90'},
          frpcLocalIp: { label: `FRPC_localIP`,minWidth: '110'},
          frpcLocalPort: { label: `FRPC_localPort`,minWidth: '120'},
          frpcConnectionStatus: { label: `FRP连接地址生成状态`,minWidth: '150',visible: true, slotName: 'tempFrpcConnect'},
        },
        config: {
          colHiddenCheck: true,
          tableButton: {
            top: [
              {content: '修改FRP服务端配置', fnCode: 'edit', type: 'primary', icon: 'el-icon-edit', hasPermi: 'resource:frpServerManage:edit'},
            ],
            line: [
              {content: '详情', fnCode: 'details', type: 'primary', icon: 'el-icon-view', hasPermi: 'resource:frpServerManage:details'}
            ]
          }
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        listFrpcConfig(this.queryParams).then(response => {
          this.tableList = response.rows;
          this.queryParams.total = response.total;
          this.loading = false;
        })
      },
      // 处理子组件传递的新值
      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) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'edit':
              this.$router.push({
                path:'/resource/frpServerManage/edit'
              });
              break;
            case 'details':
              this.$router.push({
                path:'/resource/frpServerManage/view',
                query:{
                  id: rowData.id,
                  readonly: true
                }
              });
              break;
            case 'export':
              // let dataList = [];
              // Object.keys(this.columns).forEach(item => {
              //   if (item.visible) {
              //     dataList.push(item.prop);
              //   }
              // });
              // this.download("/system/alarmManage/export", {properties: dataList,}, `拓扑管理_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("system/alarmManage/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>
