<template>
    <div>
        <div class="top">
            <div class="btn">
                <Row>
                    <Col span="12">
                        <Button type="error">删除全部</Button>
                    </Col>
                </Row>
            </div>
            <template>
                <Form :model="formItem" :label-width="100">
                    <FormItem label="接口标识：">
                        <Input v-model="formItem.input" @on-blur="selectDataList"></Input>
                    </FormItem>
                </Form>
            </template>
        </div>
        <div>
            <Table border :columns="columns" :data="dataList" :loading="loading">
                <template  slot="action">
                    <Button type="primary" size="small" style="margin-right: 5px">查看日志</Button>
                    <Button type="error" size="small">删除</Button>
                </template>
            </Table>
        </div>
    </div>
</template>

<script>
import { getCollNameList } from '../../../api/system/sys-api-category'

export default {
  name: 'WlApiCategory',
  data () {
    return {
      formItem: {
        input: ''
      },
      columns: [
        {
          title: '接口标识',
          key: 'name'
        },
        {
          title: '操作',
          slot: 'action',
          width: 300,
          align: 'center'
        }
      ],
      dataList: [],
      resultsList: [],
      loading: true
    }
  },
  methods: {
    selectDataList () {
      if (this.formItem.input !== '') {
        this.dataList = []
        this.resultsList.forEach(item => {
          if (item.name === this.formItem.input) {
            this.dataList.push(item)
          }
        })
      } else {
        this.dataList = this.$common.xeUtils.clone(this.resultsList)
      }
    },
    getCollNameList () {
      let data = {
        dbname: 'undb'
      }
      getCollNameList(data).then(ret => {
        if (ret.data.errcode === 0) {
          let results = ret.data.data
          results.forEach(item => {
            let List = {
              name: item
            }
            this.resultsList.push(List)
          })
          this.dataList = this.$common.xeUtils.clone(this.resultsList)
          this.loading = false
        } else {
          this.$Message.error(ret.data.errmsg)
        }
      })
    },
    init () {
      this.getCollNameList()
    }
    // success () {
    //   this.$Message.success('操作成功')
    // },
    // error (data) {
    //   this.$Message.error({
    //     content: '操作失败,\n' + data.errmsg
    //   })
    // }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>
    .top{
        width: 40%;
    }
    .btn{
        margin-top: 20px;
        margin-bottom: 20px;
    }
</style>
