<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['addActivityCompany'].isShow = true,$refs['addActivityCompany'].type = 'add'">添加</Button>

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

    <xy-table
      :list="list"
      :total="total"
      @pageSizeChange="e => select.pageSize = e"
      @pageIndexChange="pageChange"
      :table-item="table"
      @delete="deleteActivity"
      @editor="editorActivity"></xy-table>

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

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

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

      total:0,
      list:[],
      table:[
        {
          label:"关联方名称",
          // width: 220,
          prop:'name',
          align:'left',
          // fixed:'left',
        },
        // {
        //   label:"类型",
        //   width: 140,
        //   prop:'type'
        // },
        {
          label:"备注",
          // width: 140,
          prop:'remark',
          align:'left',
        }
      ]
    }
  },
  methods: {
    async getActivities(){
      const res = await index({
        rows:this.select.pageSize,
        page:this.select.pageIndex
      })
      this.list = res.rows
      this.total = res.total
    },

    pageChange(e){
      this.select.pageIndex = e
    },

    deleteActivity(row){
      destroy({id:row.id}).then(res => {
        Message({
          type:'success',
          message:'删除成功'
        })
        this.getActivities()
      })
    },
    editorActivity(row){
      this.$refs['addActivityCompany'].id = row.id
      this.$refs['addActivityCompany'].type = 'editor'
      this.$refs['addActivityCompany'].isShow = true
    }
  },
  mounted() {
    this.getActivities()
  }

}
</script>

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