<template>
    <div>
      <m-card title="数据任务">
        <table-list
          ref="table"
          class="pb-3"
          :height="height"
          :loading="false"
          :headers="headers"
          :items="tableData"
          :showPage="false"
          :isTools="false"
          :showSelect="false"
          :elevation="0"
          :disableSort="true"
        >
          <template v-slot:name="{ item }">
            <span style="color:#5aabff;cursor:pointer;text-decoration: underline;" @click="nodeClick(item)">{{item.name}}</span>
          </template>
        </table-list>
      </m-card>
    </div>
</template>

<script>
// 元数据-数据任务
import { checkMetaData } from '@/api/dataBook.js'
import TableList from '@/components/List/table.vue'
import MCard from '@/components/MCard'
export default {
  name: 'metaDataTask',
  components: { TableList, MCard },
  props: {
    query: {
      type: Object,
      default: () => { return {} }
    }
  },
  data () {
    return {
      height: 100,
      metaDataId: '',
      headers: [
        { text: '任务名称', align: 'start', value: 'name' },
        { text: '产品手册id', align: 'start', value: 'productId' },
        { text: '数据源id', align: 'start', value: 'dataSourceId' },
        { text: '加工类型', align: 'start', value: 'type' },
        { text: '是否配置规则', align: 'start', value: 'isConfigRule' },
        { text: '备注', align: 'start', value: 'remark' }
      ],
      tableData: []
    }
  },
  created () {
    this.metaDataId = this.query.metaDataId
    this.getMetaDataTask()
  },
  mounted () {
    this.$nextTick(() => {
      const el = this.$refs.table.$el.getBoundingClientRect()
      this.height = window.innerHeight - el.top - 50
    })
  },
  methods: {
    async getMetaDataTask () {
      try {
        const { data } = await checkMetaData({ id: this.metaDataId })
        if (data.dataProcessingList) {
          this.tableData = data.dataProcessingList.map(item => {
            item.isConfigRule = item.isConfigRule === true ? '是' : '否'
            if (item.type != null) {
              item.type = item.type === 1 ? '不加工' : '数据加工'
            }
            return item
          })
        }
      } catch (error) {
        this.$snackbar.error(error)
      }
    },
    nodeClick ({ id, productId, name }) {
      const src = this.$router.resolve({
        path: `/dataBook/dataTask/details/${id}/${productId}/${name}`
      })
      window.open(src.href)
    }
  }
}
</script>

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