import breadcrumbComponent from '@/components/breadcrumb.vue'
import tableComponent from '@/components/table.vue'
import list from '@/mixins/list'
import routerUserMenu from '@/mixins/router-user-menu'

export default {
  name: 'MetadataList',
  components: {breadcrumbComponent, tableComponent},
  mixins: [list,routerUserMenu],
  data () {
    return {
      searchForm: {
        tableName: '',
        tableComment: '',
        databaseId: '',
        pageSize: 10,
        page: 1
      },
      databaseOptions: [],
      // 列表数据
      tableData: {
        data: [],
        total: 0
      },
      // 列表设置
      tableOption: {
        // 是否显示序号
        index: true,
        // 是否显示勾选框
        select: false,
        // 默认排序
        defaultSort: {prop: 'updateTime', order: 'descending',},
        // 列
        tableLabel: [
          {prop: 'tableComment', title: '表中文名', width: '100'},
          {prop: 'tableName', title: '表名称', width: '100'},
          {prop: 'resourceName', title: '表所属数据库', width: '100'},
          {prop: 'updateUserName', title: '修改人', width: '100'},
          {prop: 'updateTime', title: '修改时间', width: '100', sort: true}
        ],
        // 操作
        tableOperate: {
          width: '150',
          buttons: [
            {label: '修改', methods: 'edit', color: 'safe'},
            {label: '复制', methods: 'copy', color: 'link'},
            {label: '删除', methods: 'del', color: 'warn'}
          ]
        },
      },
    }
  },
  created () {
  },
  mounted () {
    // this.getList()
    this.listDatabaseOption()
  },
  methods: {

    /* 编辑功能 */
    edit (obj) {
      this.go('EditMetaGuide', {id: obj.id,ifcopy:0})
    },

    // 复制功能
    copy (obj) {
      this.go('EditMetaGuide',{id: obj.id,ifcopy:1})
    },

    /* 删除功能 */

    // 执行删除
    delAction(obj){
      let params={id: obj.id}
      this.$api.storage.removeTableById(params)
        .then(res => {
          if (res.code == 1) {
            this.$message.success(res.msg)
            this.getList()
          }
        })
    },
    // 删除
    del(obj){
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.delAction(obj)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    /* 加载所属数据库下拉列表 */
    listDatabaseOption () {
      this.$api.storage.listDatabaseOption()
        .then(res => {
          this.databaseOptions = res.data
        })
    },

    /* 获取数据库列表信息 */
    getList () {
      let params = this.searchForm
      this.$api.storage.listTable(params)
        .then(res => {
          this.tableData.data = res.data
          this.tableData.total = res.totalNumber
        })
    },
  }
}
