import { getToken } from '@/libs/util'
import { ListMemberLevel, ListOperation } from '@/api/permissions.js'
import memberPermission from './components/member-permission'
import operationPermission from './components/operation-permission'

export default {
  components: {
    memberPermission,
    operationPermission
  },
  data () {
    return {
      token: getToken(),
      member_table_data: [],
      operation_table_title: [
        {
          title: this.$t('index'),
          slot: 'index',
          width: '80',
          align: 'center'
        },
        {
          title: this.$t('uri_link'),
          slot: 'path'
        },
        {
          title: this.$t('menu_title'),
          key: 'title'
        },
        {
          title: this.$t('operation'),
          slot: 'operation'
        }
      ],
      operation_table_data: []
    }
  },
  created () {
    this.getListData()
  },
  methods: {
    getListData () {
      let formData = new FormData()
      formData.append('access_token', this.token)
      formData.append('project', this.projectName)

      ListMemberLevel(formData).then(res => {
        this.member_table_data = res.data
      })

      ListOperation(formData).then(res => {
        if (res.data.length > 0) {
          this.operation_table_data = res.data
        } else this.operation_table_data = []
      })
    },
    refresh () {
      this.getListData()
    }
  }
}
