<template>
  <div class="content">
    <div class="topSearch">
      <div class="left">
        <Input style="width:280px" search enter-button placeholder="" @on-search='search'/>
      </div>
      <div class="right">
        <Button @click="add" type="primary">新增</Button>
        <Button type="error" @click="del">删除</Button>
      </div>
    </div>
     <Stable :data='data' @edit='edit' @select='select' :search='search'/>
     <Forms :visible.sync="visible" :search='search' :row='row'/>
  </div>
</template>

<script>
import Stable from './table.vue'
import Forms from './form.vue'
import {
  getVipPage,
  editVipPage,
  delVipPage
} from '@/api/vipPage'
export default {
  name: 'categories',
  components: {
    Stable,
    Forms
  },
  data () {
    return {
      selectList: [],
      visible: false,
      draggableVisible: false,
      row: {},
      data: []
    }
  },
  methods: {
    edit (row) {
      this.visible = true
      this.row = row
    },
    add () {
      this.visible = true
      this.row = {
        id: 'add'
      }
    },
    select (val) {
      this.selectList = val
    },
    ok (list) {
      editVipPage(list).then((res) => {
        if (res.code === 200 && res.data.length > 0) {
          this.$Message.success('操作成功')
          this.draggableVisible = false
          this.search()
        }
      })
    },
    del () {
      delVipPage(this.selectList).then((res) => {
        if (res.code === 200) {
          this.$Message.success('删除成功')
          this.search()
        } else {
          this.$Message.error('删除失败')
        }
      })
    },
    search () {
      getVipPage({}).then((res) => {
        this.data = res.data
      })
    }
  },
  mounted () {
    this.search()
  }
}
</script>

<style lang="less"></style>
