<template>
  <a-modal v-model:visible="visible" width="600px" @close="handleClose" @ok="handleOk">
    <template #title>广告数据权限设置</template>
    <div>
      <a-radio-group v-model="adPermission">
        <a-radio :value="1">全部</a-radio>
        <a-radio :value="2">自己以及组员</a-radio>
        <a-radio :value="0">仅自己</a-radio>
      </a-radio-group>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, computed } from 'vue'
import api from '@/api/center/game'
import userApi from '@/api/system/user'
import GamePermission from '@/components/game-permission/index.vue'
import { Message } from '@arco-design/web-vue'

const emit = defineEmits(['success'])

const visible = ref(false)
const adPermission = ref(0)

const id = ref(0)

const handleClose = () => {
  visible.value = false
}

const handleOk = async () => {
  // console.log("handleOk");
  const result = await userApi.setUserPermission({
    id: id.value,
    ad_permission: adPermission.value,
  })
  if (result.code === 200) {
    Message.success('操作成功')
    emit('success')
  }
}

// 打开弹框
const open = async (row) => {
  let rowData = JSON.parse(JSON.stringify(row))

  adPermission.value = rowData.ad_permission
  id.value = rowData.id

  visible.value = true

  await initPage()
}

const initPage = async () => {}

defineExpose({ open })
</script>
