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: 'DatabaseList',
  components: {breadcrumbComponent, tableComponent},
  mixins: [list, routerUserMenu],
  data () {
    return {
      searchForm: {
        projectName: '',
        pageSize: 10,
        page: 1
      },
      statusOption:[{id:"1",name:"启用"},{id:"0",name:"禁用"}],
      reqOptions: [],
      typeOptions: [],
      // 列表数据
      tableData: {
        data: [],
        total: 0
      },
      testDataVisible: false,
      interfaceVisible: false,
      testReturnData: "",
      showInterfaceData: [],
      labelInfo:[],
      // 列表设置
      tableOption: {
        // 是否显示序号
        index: true,
        // 是否显示勾选框
        select: false,
        // 默认排序
        defaultSort: {prop: 'updateTime', order: 'desc'},
        // 列
        tableLabel: [
          {prop: 'projectName', title: '接口分类名称', width: '100'},
          {prop: 'checkCode', title: '权限校验码', width: '100'},
          {prop: 'operatorId', title: '操作员', width: '100'},
          {prop: 'updateTime', title: '修改时间', width: '120', sort: true}
        ],
        // 操作
        tableOperate: {
          width: '300',
          buttons: [
            {label: '修改', methods: 'edit', color: 'safe'},
            {label: '删除', methods: 'del', color: 'warn'}
          ]
        },
      },
    }
  },
  created () {
  },
  mounted () {
    this.getList()
  },
  methods: {

    /* 编辑功能 */
    edit (obj) {
      this.go('interfaceClassifyEdit', {id: obj.projectId})
    },
    // 执行删除
    delAction (obj) {
      let params = {id: obj.projectId}
      this.$api.interfaceDb.deleteInterfaceProject(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: '已取消删除'
        });
      });
    },
    /* 获取接口列表信息 */
    getList () {
      let params = this.searchForm
      this.$api.interfaceDb.listInterfaceProject(params)
        .then(res => {
          this.tableData.data = res.data
          this.tableData.total = res.totalNumber
        })
    },
  }
}
