<template>
  <div class="page-view">
    <app-filter ref="app-filter" :model="filters" class="bg-white px-15 border-radius-5" label-width="130px" @query="onQuery" @reset="onReset">
      <app-filter-item :span="6" label="数据资源项名称">
        <el-input v-model="filters.name" clearable placeholder="请输入" @keyup.enter.native="$refs['app-filter'].query" />
      </app-filter-item>
      <app-filter-item :span="6" label="数据资源项编码">
        <el-input v-model="filters.code" 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 #status="scope">
          <el-tag :type="!!scope.row.status ? 'success' : 'danger'">{{ scope.row.status ? '成功' : '失败' }}</el-tag>
        </template>
      </app-table>
    </div>

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

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

export default {
  components: { DetailDialog },
  mixins: [tableMixin],
  data() {
    const TABLE_CONFIG = {
      // 列表表头
      columns: [
        { label: '数据资源项名称', prop: 'name', align: 'center' },
        { label: '数据资源项编码', prop: 'code', align: 'center' },
        { label: '数据库实体表表名', prop: 'entityTableName', align: 'center' },
        { label: '数据表名', prop: 'tableName', align: 'center' },
        {
          label: '数据推送状态',
          prop: 'status',
          dataType: 'slot',
          slot: 'status',
          // width: '300px',
          align: 'center',
        },
        { label: '表当前数据总量', prop: 'totalNum', align: 'center' },
        {
          dataType: 'option',
          label: '操作',
          width: '200px',
          fixed: 'right',
          align: 'center',
          operation: [
            {
              name: '详情',
              icon: 'el-icon-view',
              // 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相关
      tableData: [],
      tableLoading: false, // 表格加载状态
      pagination: {
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页显示的条数
      },
    };
  },
  computed: {
    // 配置列表接口方法；只有配置了该计算属性才会执行table mixins中的getData方法
    dataMethod() {
      return API.pushLogs;
    },
  },
  mounted() {},
  methods: {
    // 联通接口后 该方法可用table.js  Mixins里的getData方法替代 ，此处只为静态页面开发使用
    showDetail(row) {
      this.dialogTitle = '数据详情';
      this.currentRow = row;
      this.dialogVisible = true;
    },
  },
};
</script>

<style></style>
