<template>
    <div style="padding: 0 20px">
      <div ref="lxHeader">
        <lx-header icon="md-apps" text="BD详情管理" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <slot>
            <div style="display: flex;align-items: center;">

              <el-button size="medium" type="primary" @click="$refs['addBd'].isShow = true,$refs['addBd'].type = 'add'" style="margin-left: 10px">新增</el-button>
            </div>
          </slot>
        </lx-header>
      </div>

    <xy-table
      :table-item="table"
      :list="data"
      :total="total"
      :auths="['edit','delete']"
      @pageSizeChange="e => {select.page_size = e;select.page = 1;getList()}"
      @pageIndexChange="e => {select.page = e;getList()}"
      @delete="deleteStudy"
      @editor="editorStudy">
    </xy-table>
    <addBd ref="addBd" @refresh="getList"></addBd>
  </div>
</template>

<script>

import {getList,destroy} from '@/api/resource/bd.js'
import addBd from '@/views/resource/component/addBd'
export default {
  components: {
    addBd
  },
  data() {
    return {
      select:{
        page:1,
        rows:10
      },
      total:0,
      data:[],
      table:[
        {
          label:'详情名称',
          sortable:false,
          prop:'name'
        },
        {
          label:'详情编码',
          sortable:false,
          prop:'key',
        },
        {
          label:'详情内容',
          sortable:false,
          prop:'value',
        }
      ]
    }
  },
  computed: {},
  mounted() {
    this.getList()
  },
  methods: {
    async getList(){
      let res = await getList(this.select)
      console.log(res)
      this.data = res.data
      this.total = res.total
    },
    deleteStudy(row){
      destroy({id:row.id}).then(res => {
        this.$successMessage('destroy','BD')
        this.getList()
      })
    },
    editorStudy(row){
      this.$refs['addBd'].id = row.id
      this.$refs['addBd'].type = 'editor'
      this.$refs['addBd'].isShow = true
    }
  },
}
</script>

<style scoped lang="scss">
//::v-deep .el-button + .el-button{
//  margin-left: 0 !important;
//}
::v-deep .el-button{
  padding: 5px 8px !important;
}
</style>
