<template>
  <div >
    <Modal id="studio_list_modal" v-model="showMd" :title="title" :footer-hide="true" class-name="vertical-center-modal" :width="500">
      <div class="studio_list">
        <Table :columns="column" border :data="list" class="table"></Table>
      </div>
    </Modal>
  </div>
</template>
<script>
export default {
  name: "studio_list",
  props: {
    show: Boolean,
    value:Number
  },
  data() {
    return {
      title: '',
      id: 0,
      isDelete: false,
      delete: false,
      column: [
        {
          title: "平台名称",
          key: "name"
        },
        {
          title:'操作',
          render: (h, params) => {
            if (this.isDelete) {
              return h('span', {
                class: "operate-btn",
                style: {
                  color: "rgba(255, 121, 0, 1)"
                },
                on: {
                  click: () => {
                    this.$api.getStudioChannelDelete({id: this.id, platform_id: params.row.id})
                      .then(response => {
                        if (response.code == 200) {
                          this.delete = true
                          this.getData()
                          this.$Message.success(response.msg)
                        } else {
                          this.$Message.error(response.msg)
                        }
                      })
                  }
                }
              }, '删除')
            } else {
              return h('span', {
                class: "operate-btn",
                style: {
                  color: "rgb(153, 153, 153)",
                  cursor: 'not-allowed'
                },
              }, '删除')
            }
          },
        }
      ],
      list: []
    };
  },
  computed: {
    showMd: {
      get(n) {
        if(this.show){
          this.getAuth()
          this.getData()
        }
        return this.show;
      },
      set(val) {
        if (this.delete) this.$emit("studio-delete")
        this.$emit("update:show", val);
      }
    }
  },
  methods: {
    getAuth() {
      this.$api.getAuthRole({id:this.role_id}).then(data=>{
        if(data.code===200){
          let checkList=data.data.auth_ids.split(',')
          if(checkList.indexOf('276')>=0){
            this.isDelete=true
          }
        }
      })
    },
    getData () {
      this.$api.getStudioChannelList({id:this.value})
        .then(response => {
          if (response.code == 200) {
            this.title = response.name + '公会绑定平台列表'
            this.id = response.id
            this.list = response.data
          }
        })
    }
  },
  created() {},
};
</script>
<style scoped>
.studio_list {
  padding: 20px 15px;
}
.studio_list .content {
  width: 100%;
}
</style>


