<template>
  <a-card :bordered="false">
    <div class="ant-alert ant-alert-info ant-alert-light">
      <span class="ant-alert-title">定义网关请求白名单</span>
    </div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a @click="handleDelete(record.id)">删除</a>
        </span>

      </a-table>
    </div>

    <hlwWhiteList-modal ref="modalForm" @ok="modalFormOk"></hlwWhiteList-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlwWhiteListModal from './modules/HlwWhiteListModal'
  import { httpAction,getAction,deleteAction } from '@/api/manage'

  export default {
    name: "HlwWhiteListList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HlwWhiteListModal
    },
    data () {
      return {
        description: 'ip白名单管理页面',
        // 表头
        columns: [
          {
            title:'客户端ID',
            align:"center",
            dataIndex: 'clientId'
          },
          {
            title:'ip地址',
            align:"center",
            dataIndex: 'ipAddr'
          },
          {
            title:'版本号',
            align:"center",
            dataIndex: 'version'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/wisdom/whiteList/list",
          delete: "/wisdom/whiteList/delete",
          deleteBatch: "/wisdom/whiteList/deleteBatch",
          exportXlsUrl: "/wisdom/whiteList/exportXls",
          importExcelUrl: "/wisdom/whiteList/importExcel",
        },
        /* 排序参数 */
        isorter:{
          column: 'createTime',
          order: 'desc',
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleDelete: function (id) {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        var that = this;
        const modal = that.$confirm({
          title: '删除白名单',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '确定要删除该白名单吗？',
          okText: '确定删除',
          cancelText: '取消',
          onOk: function() {
            deleteAction(that.url.delete, {id: id}).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.loadData();
              } else {
                that.$message.warning(res.message);
              }
            });
          },
          onCancel(e) {
            modal.destroy()
          }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .ant-alert-title{
    font-size: 14px;
    line-height: 18px;
  }
  .ant-alert-light{
    margin-bottom: 16px;
    background-color: #f4f4f5;
    color: #909399;
    padding: 0.8rem;
    border: none;
  }
</style>