<template>
  <div class="content">
    <div class="topSearch">
      <div class="left">
        <Input style="width:280px" search enter-button placeholder="" @on-search='onSearch'/>
         <span class="lable">
              购买页
            </span>
            <Select clearable  v-model="seleted" style="width:80px" @on-change='selectChange' >
              <Option
                v-for="item in pagesList"
                :value="item.id"
                :key="item.id"
                >{{ item.title }}</Option
              >
            </Select>
      </div>
      <div class="right">
        <Button class='success-btn' type="success" @click="seq">排序</Button>
        <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' :list="pagesList"/>
      <!-- <draggableList :visible.sync="draggableVisible" :list='data' @ok='ok'/> -->
  </div>
</template>

<script>
import Stable from './table.vue'
import Forms from './form.vue'
import draggableList from '@/view/common/draggable.vue'
import {
  getVips,
  delVips,
  vipPagesList,
  editVips
} from '@/api/vip'
export default {
  name: 'categories',
  components: {
    Stable,
    Forms,
    draggableList
  },
  data () {
    return {
      seleted: null,
      selectList: [],
      pagesList: [],
      visible: false,
      draggableVisible: false,
      row: {},
      data: []
    }
  },
  methods: {
    edit (row) {
      this.visible = true
      this.row = row
    },
    add () {
      this.visible = true
      this.row = {
        id: 'add'
      }
    },
    selectChange (p) {
      console.log(p)
      this.search({
        page_id: p
      })
    },
    select (val) {
      this.selectList = val
    },
    seq () {
      this.draggableVisible = true
    },
    ok (list) {
      editVips(list).then((res) => {
        if (res.code === 200 && res.data.length > 0) {
          this.$Message.success('操作成功')
          this.draggableVisible = false
          this.search()
        }
      })
    },
    del () {
      delVips(this.selectList).then((res) => {
        if (res.code === 200) {
          this.$Message.success('删除成功')
          this.search()
        } else {
          this.$Message.error('删除失败')
        }
      })
    },
    getVipPagesList () {
      vipPagesList({}).then((res) => {
        this.pagesList = res.data
      })
    },
    onSearch (p) {
      this.search({
        keyword: p
      })
    },
    search (p) {
      getVips(p).then((res) => {
        this.data = res.data
      })
    }
  },
  mounted () {
    this.seleted = this.$route.query.row && this.$route.query.row.id
    let parmas = {
      page_id: this.seleted
    }
    this.search(parmas)
    this.getVipPagesList()
  }
}
</script>

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