<template>
  <div class="page-view flex-row-sb">
    <div class="page-view flex-1 h-100">
      <app-filter :model="filters" ref="app-filter" class="bg-white px-15 border-radius-5" label-width="90px" @query="onQuery" @reset="onReset">
        <app-filter-item :filter-config="{ operation: 'LIKE' }" :span="5" el-type="input" label="表资源名称">
          <el-input v-model="filters.name" clearable placeholder="请输入" @keyup.enter.native="onQuery(filters)" />
        </app-filter-item>
        <app-filter-item :filter-config="{ operation: 'EQUAL' }" :span="5" label="治理状态">
          <el-select v-model="filters.cleanStatus" clearable @keyup.enter.native="onQuery(filters)">
            <el-option label="成功" value="1" />
            <el-option label="失败" value="0" />
          </el-select>
        </app-filter-item>
        <app-filter-item :filter-config="{ operation: 'EQUAL' }" :span="5" label="治理方式">
          <el-select v-model="filters.cleanType" clearable @keyup.enter.native="onQuery(filters)">
            <el-option label="DS任务" value="1" />
            <el-option label="离线文件导入" value="2" />
          </el-select>
        </app-filter-item>
        <app-filter-item :filter-config="{ operation: 'EQUAL' }" :span="5" label="计算方式">
          <el-select v-model="filters.type" clearable @keyup.enter.native="onQuery(filters)">
            <el-option label="全量计算" value="1" />
            <el-option label="增量计算" value="2" />
          </el-select>
        </app-filter-item>
      </app-filter>

      <div class="pa-15 bg-white flex-1 flex-col mt-15 border-radius-5">
        <app-table
          ref="table"
          :column="columns"
          :pagination="pagination"
          :table-data="tableData"
          :table-loading="tableLoading"
          :total="total"
          row-key="id"
          @pagination-change="onPaginationChange"
          @row-dblclick="handleDetail"
        >
          <template #startTime="scope">
            <span>{{ scope.row['startTime'] || '' }} 至 {{ scope.row['endTime'] || '' }}</span>
          </template>
          <template #cleanType="scope">
            <el-tag type="primary">
              {{ scope.row['cleanType'] === '1' ? 'DS任务' : scope.row['cleanType'] === '2' ? '离线文件导入' : '-' }}
            </el-tag>
          </template>
          <template #type="scope">
            <el-tag type="primary">
              {{ scope.row['type'] === '1' ? '全量计算' : scope.row['type'] === '2' ? '增量计算' : '-' }}
            </el-tag>
          </template>
          <template #cleanStatus="scope">
            <el-tag :type="scope.row['cleanStatus'] === '0' ? 'danger' : scope.row['cleanStatus'] === '1' ? 'success' : 'primary'">
              {{ scope.row['cleanStatus'] === '0' ? '失败' : scope.row['cleanStatus'] === '1' ? '成功' : '-' }}
            </el-tag>
          </template>
        </app-table>
      </div>
      <detail-dialog v-model="dialogVisible" :data="dialogdData" :title="dialogTitle" />
    </div>
  </div>
</template>

<script>
import tableMixin from '@/mixins/table.js'; // 列表mixins
import detailDialog from './detailDialog.vue';
import API from '@/api/business/dataAPPCatalog';

export default {
  name: 'appLayerLog',
  components: { detailDialog },
  mixins: [tableMixin],
  data() {
    const TABLE_CONFIG = {
      // 列表表头
      columns: [
        { label: '表资源名称', prop: 'name' },
        { label: '数据库表名', prop: 'tableNameEn' },
        { label: 'DS项目名称', prop: 'dsProjectName' },
        { label: '治理方式', prop: 'cleanType', dataType: 'slot', slot: 'cleanType', width: '140', align: 'center' },
        { label: '计算方式', prop: 'type', dataType: 'slot', slot: 'type', width: '140', align: 'center' },
        { label: '治理时间', prop: 'startTime', dataType: 'slot', slot: 'startTime', minWidth: '140', align: 'center' },
        { label: '治理状态', prop: 'cleanStatus', dataType: 'slot', slot: 'cleanStatus', width: '140', align: 'center' },
      ],
    };

    const DIALOG_CONFIG = {
      dialogVisible: false,
      dialogTitle: '详情',
      dialogdData: {},
    };

    return {
      ...TABLE_CONFIG,
      ...DIALOG_CONFIG,
    };
  },
  computed: {
    // 配置列表接口方法：只有配置了该计算属性 才会执行 table mixins中的getData方法
    dataMethod() {
      return API.dataGovernanceLog;
    },
  },

  methods: {
    // 列表 ------------
    handleDetail(row) {
      this.dialogVisible = true;
      this.dialogTitle = `日志详情 - ${row.name}`;
      this.dialogdData = row;
    },
  },
};
</script>

<style lang="scss" scoped></style>
