<template>
  <div class="collect">
    <el-table
      ref="multipleTable"
      :data="list"
      :highlight-current-row="true"
      stripe
      fit
      height="calc(100% - 1px)"
      border>
      <el-table-column
        prop="apiName"
        label="接口名称"/>
      <el-table-column
        prop="createTime"
        label="收藏时间"/>
      <el-table-column
        prop="description"
        label="查看详情">
        <template slot-scope="scope">
          <el-button type="success" plain @click="handleDetail(scope.row)">
            查看详情
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        width="270"
        label="操作">
        <template slot-scope="scope">
          <el-button plain type="danger" @click="handleDelete(scope.row)">
            取消收藏
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { collectCancel, collectList } from '@/api/apimngr'

export default {
  name: 'Collect',
  data() {
    return {
      list: []
    }
  },
  mounted() {
    this.appId = window.localStorage.getItem('appId')
    this.getList()
  },
  methods: {
    getList() {
      collectList().then(res => {
        this.list = res.data
      })
    },
    handleDetail(row) {
      this.$router.push({
        path: `/apilist/detail/${row.apiId}`
      })
    },
    handleDelete(row) {
      // 是否取消
      this.$confirm('是否取消收藏', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = new URLSearchParams()
        param.append('acId', row.acId)
        collectCancel(param).then(res => {
          this.$message({
            message: '取消收藏成功',
            type: 'success'
          })
          this.getList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    }
  }
}
</script>

<style scoped>
.collect{
  width: 100%;
  height: 100%;
  background: #fff;
}
</style>
