<template>
  <div class="w-full min-h-400 pb-10">
    <!-- 审核中 -->
    <ProfileNotesEmpty v-if="!loading && !draftList.length" />

    <div v-else-if="draftList.length">
      <ProfileNotesAuditingItem
        v-for="item in draftList"
        :key="item.id"
        :data="item"
        @on-revoke="handleRevoke(item)"
      />
    </div>
  </div>
</template>

<script setup>
const { loading, setLoading } = useLoading()
loading.value = true

const draftList = ref([])

async function getNotesList() {
  setLoading(true)
  try {
    const { data } = await request('/website/tourism/publishTravelNotes/getDraftList', {
      query: {
        pageNum: 1,
        pageSize: 10000,
        type: 1
      }
    })
    draftList.value = data.dataList
  } finally {
    setLoading(false)
  }
}

async function handleRevoke(item) {
  showConfirmDialog({
    title: '提示',
    message: '确定撤销审核吗?'
  })
    .then(async () => {
      try {
        await request(`/website/tourism/publishTravelNotes/withdraw`, {
          method: 'post',
          body: {
            writeId: item.id
          }
        })
        showSuccessToast('撤销成功')
        getNotesList()
      } catch (error) {}
    })
    .catch(() => {
      // on cancel
    })
}

onMounted(() => {
  getNotesList()
})
</script>

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