<template>
  <div class="page-view">
    <app-filter ref="app-filter" :model="filters" class="bg-white px-15 border-radius-5" label-width="125px" @query="onQuery" @reset="onReset">
      <app-filter-item :span="6" label="访问接口名称" prop="apiName">
        <el-input v-model="filters.apiName" clearable placeholder="请输入" @keyup.enter.native="$refs['app-filter'].query" />
      </app-filter-item>
      <app-filter-item :span="6" label="客户端访问IP地址" prop="requestIp">
        <el-input v-model="filters.requestIp" clearable placeholder="请输入" @keyup.enter.native="$refs['app-filter'].query" />
      </app-filter-item>
    </app-filter>
    <!-- 列表组件 -->
    <div class="flex-1 pa-11 bg-white h-100 flex-col mt-11 border-radius-5">
      <app-table
        :column="columns"
        :pagination="pagination"
        :table-data="tableData"
        :table-loading="tableLoading"
        :total="total"
        @pagination-change="onPaginationChange"
        @row-dblclick="showDetail"
      >
        <!-- 插槽-->
        <template #requestStatus="scope">
          <el-tag :type="!!scope.row.requestStatus ? 'success' : 'danger'">{{ scope.row.requestStatus ? '成功' : '失败' }} </el-tag>
        </template>
      </app-table>
    </div>

    <!-- dialog组件 -->
    <detail-dialog v-model="dialogVisible" :data="currentRow" :title="dialogTitle" />
  </div>
</template>

<script>
import API from '@/api/business/dataServiceLog';
import tableMixin from '@/mixins/table.js'; // 列表mixins
import DetailDialog from './DetailDialog';

export default {
  components: { DetailDialog },
  mixins: [tableMixin],
  data() {
    const TABLE_CONFIG = {
      filters: {},
      // 列表表头
      columns: [
        { label: '访问接口名称', prop: 'apiName', align: 'center' },
        { label: '访问接口URL地址', prop: 'apiUrl', align: 'center' },
        { label: '客户端访问IP地址', prop: 'requestIp', align: 'center' },
        { label: '请求访问时间', prop: 'requestTime', align: 'center' },
        { label: '请求参数信息', prop: ' requestParams', align: 'center' },
        { label: '返回参数信息', prop: 'responseResult', align: 'center' },
        { label: '接口响应时长', prop: 'responseTimeLength', align: 'center', width: '110px' },
        {
          label: '请求访问状态',
          prop: 'requestStatus',
          dataType: 'slot',
          slot: 'requestStatus',
          align: 'center',
        },
        {
          dataType: 'option',
          label: '操作',
          width: '230px',
          fixed: 'right',
          align: 'center',
          operation: [
            {
              name: '详情',
              icon: 'el-icon-s-operation',
              // showHide: (row) => {},
              clickFun: row => {
                this.showDetail(row);
              },
            },
          ],
        },
      ],
    };

    const DIALOG_CONFIG = {
      dialogVisible: false,
      dialogTitle: '',
    };
    return {
      ...TABLE_CONFIG, // table相关
      ...DIALOG_CONFIG, // 主列表dialog相关
      // 新增代码---------
      total: 0,
      tableLoading: false, // 表格加载状态
      tableData: [],
      pagination: {
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页显示的条数
      },
    };
  },
  computed: {
    // 配置列表接口方法；只有配置了该计算属性才会执行table mixins中的getData方法
    dataMethod() {
      return API.apiCall;
    },
  },
  mounted() {},
  created() {},
  methods: {
    showDetail(row) {
      this.dialogTitle = '数据详情';
      this.currentRow = row;
      this.dialogVisible = true;
    },
    delCompany(row) {
      this.$confirm(`此操作将永久删除该汇聚方（${row.name}）, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        const ind = this.tableData.findIndex(o => o.id == row.id);
        ind >= 0 && this.tableData.splice(ind, 1);
      });
    },
  },
};
</script>

<style></style>
