<template>
  <div class="page-view">
    <app-filter ref="app-filter" :model="filters" class="bg-white px-15 border-radius-5" @query="onQuery" @reset="onReset">
      <app-filter-item :span="7" label="调用方名称" prop="memberName">
        <el-input v-model="filters.memberName" clearable placeholder="请输入" @keyup.enter.native="$refs['app-filter'].query" />
      </app-filter-item>
      <app-filter-item :span="7" label="调用离线文件下载文件名称" prop="fileName">
        <el-input v-model="filters.fileName" 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="editCompany"
      />
    </div>

    <detail-dialog v-model="dialogVisible" :data="currentRow" :title="dialogTitle" @confirm="onCompanyConfirm" />
  </div>
</template>

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

export default {
  components: { DetailDialog },
  mixins: [tableMixin],
  props: {
    providerRow: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    const TABLE_CONFIG = {
      columns: [
        { label: '调用方名称', prop: 'memberName', align: 'center', width: '150px' },
        { label: '调用方系统名称', prop: 'appName', align: 'center' },
        { label: '调用方编码', prop: 'memberCode', align: 'center', width: '150px' },
        { label: '调用访问的资源名称', prop: 'resourceName', align: 'center' },
        { label: '调用访问的资源编码', prop: 'resourceCode', align: 'center' },
        { label: '客户端访问的IP地址', prop: 'requestIp', align: 'center' },
        { label: '调用离线文件下载文件名称', prop: 'fileName', align: 'center' },
        { label: '调用离线文件下载文件地址', prop: 'filePath', align: 'center' },
        {
          dataType: 'option',
          label: '操作',
          align: 'center',
          width: '240px',
          operation: [
            {
              name: '详情',
              type: 'text',
              size: 'mini',
              icon: 'el-icon-view',
              plain: true,
              // showHide: (row) => {},
              clickFun: row => {
                // this.$emit('onTableClick', row, 'dataSource');
                this.showDetail(row);
              },
            },
          ],
        },
      ],
    };

    const DIALOG_CONFIG = {
      dialogVisible: false,
      dialogTitle: '新增',
    };
    return {
      ...TABLE_CONFIG, // table相关
      ...DIALOG_CONFIG, // 主列表dialog相关
      tableData: [],
      tableLoading: false, // 表格加载状态
      pagination: {
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页显示的条数
      },
    };
  },
  computed: {
    // 配置列表接口方法；只有配置了该计算属性才会执行table mixins中的getData方法
    dataMethod() {
      return API.fileDownloads;
    },
  },
  mounted() {},
  methods: {
    showDetail(row) {
      this.dialogTitle = '数据详情';
      this.currentRow = row;
      this.dialogVisible = true;
    },
    // 双击
    editCompany(row) {
      this.dialogTitle = `编辑 - ${row.memberName}`;
      this.currentRow = row;
      this.dialogVisible = true;
    },

    onCompanyConfirm(data) {
      const id = this.tableData.length++;
      if (data?.id) {
        const ind = this.tableData.findIndex(o => o.id == data.id);
        ind >= 0 && this.tableData.splice(ind, 1, data);
      } else {
        this.tableData.push({ ...data, id });
      }
      this.dialogVisible = false;
    },
  },
};
</script>

<style></style>
