<template>
  <div style="padding: 0 20px">
    <div ref="lxHeader">
      <lx-header icon="md-apps" text="活动关联方" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
        <slot>
          <div style="display: flex;justify-content: flex-start;flex-wrap: wrap;">
            <Button icon="ios-add" type="primary" style="margin-right: 10px;" @click="$refs['addActivityType'].isShow = true,$refs['addActivityType'].type = 'add'">添加</Button>

          </div>
        </slot>
      </lx-header>
    </div>

    <xy-table
      :list="list"
      :total="total"
      :table-item="table"
      :isPage='false'
      @delete="deleteActivity"
      @editor="editorActivity"></xy-table>

    <addActivityType ref="addActivityType" @refresh="getActivities"></addActivityType>
  </div>
</template>

<script>
import {index,destroy} from "@/api/activityType"

import addActivityType from '@/views/activity/component/addActivityType'
import { Message } from 'element-ui'
export default {
  components:{
    addActivityType
  },
  data() {
    return {
      select:{
        pageSize:99,
        pageIndex:1
      },

      total:0,
      list:[],
      table:[
        {
          label:"分类名称",
          prop:'name',
          align:'left',
        },
        {
          label:"id",
          // width: 220,
          prop:'id',
          align:'left',
          // fixed:'left',
        }
      ]
    }
  },
  methods: {
    async getActivities(){
      const res = await index({
        rows:this.select.pageSize,
        page:this.select.pageIndex
      })
      this.list = res
      // this.total = res.total
    },
    deleteActivity(row){
      destroy({id:row.id}).then(res => {
        Message({
          type:'success',
          message:'删除成功'
        })
        this.getActivities()
      })
    },
    editorActivity(row){
      this.$refs['addActivityType'].id = row.id
      this.$refs['addActivityType'].editName = row.name
      this.$refs['addActivityType'].type = 'editor'
      this.$refs['addActivityType'].isShow = true
    }
  },
  mounted() {
    this.getActivities()
  }

}
</script>

<style scoped lang="scss">
</style>
