<template>
  <!-- 数据安全 -->
  <div class="pa-3" style="background-color: #FFF;">
    <m-filter :option="filter" @search="handleSearch" />
    <table-list
      class="mt-3"
      :loading="loading"
      :headers="headers"
      :items="items"
      :total="total"
      :page-info="pageInfo"
      :is-tools="false"
      :show-select="false"
      @pageHandleChange="pageHandleChange"
      @sort="handleSort"
    >
      <template #status="{ item }">
        <v-chip
          :color="item.status ? 'success' : 'error'"
          small
        >
          {{ item.status ? '已启用' : '已禁用'}}
        </v-chip>
      </template>
      <template #tag="{ item }">
        {{ item.tag.map(e => e.name_zh).join(',') }}
      </template>
      <template v-slot:name_zh = "{item}">
        <span class="defaultLink" @click="toDetail(item)">{{ item.name_zh }}</span>
      </template>
    </table-list>
  </div>
</template>

<script>
import MFilter from '@/components/Filter'
import TableList from '@/components/List/table'
import { api } from '@/api/dataGovernance'
export default {
  name: 'dataSecurity',
  components: {
    MFilter,
    TableList
  },
  data () {
    return {
      api,
      loading: false,
      filter: {
        list: [
          { type: 'textField', value: '', label: '关键词', key: 'title' }
        ]
      },
      headers: [
        { text: '中文名', value: 'name_zh' },
        { text: '英文名', value: 'name_en' },
        { text: '分类', value: 'category', sortable: false },
        { text: '描述', value: 'describe', sortable: false },
        { text: '标签', value: 'tag', sortable: false },
        { text: '状态', value: 'status', sortable: false },
        { text: '血缘关系数量', value: 'blood_count', align: 'center' },
        { text: '创建时间', value: 'create_time' }
      ],
      items: [],
      total: 0,
      pageInfo: {
        size: 10,
        current: 1
      },
      query: {},
      orders: []
    }
  },
  created () {
    // this.init()
  },
  methods: {
    async init () {
      this.loading = true
      try {
        const { data } = await api.getMetaDataList({ ...this.pageInfo, ...this.query })
        this.total = data.total
        this.items = data.records
      } catch (error) {
        this.$snackbar.error(error)
      } finally {
        this.loading = false
      }
    },
    handleSort (val) {
      this.orders = val
      this.init()
    },
    handleSearch (obj) {
      Object.assign(this.query, obj)
      this.pageInfo.current = 1
      this.init()
    },
    pageHandleChange (index) {
      this.pageInfo.current = index
      this.init()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
