import { ElMessage } from 'element-plus'
import request from '@/utils/request'

export const useOrg = () => {
  const orgList = ref<any>([])

  request.get('/v1/user/joined/tangent').then((res: any) => {
    if (res.success) {
      orgList.value = res.infos
    }
  })

  // 切换组织
  const changeOrg = (newTangentId: number | string) => {
    request.post('/v1/user/tangent/change', { newTangentId }).then((res: any) => {
      if (res.success) {
        ElMessage({
          type: 'success',
          message: res.msg
        })
        location.reload()
      }
    })
  }
  return {
    orgList,
    changeOrg
  }
}
