<template>
  <div style="height: calc(100vh - 105px);" class="w-full  pb-10">
    <!-- 审核中 -->
    <ProfileNotesEmpty v-if="!loading && !draftList.length" />

    <div v-else-if="draftList.length">

      <van-list
       v-model:loading="loading"
       v-model:error="error"
      :finished="finished"
      :immediate-check="false"
       offset="80"
       error-text="请求失败，点击重新加载"
       finished-text=""
       @load="getNotesList"
    >
    <ProfileNotesAuditingItem
        v-for="item in draftList"
        :key="item.id"
        :data="item"
        @on-revoke="handleRevoke(item)"
      />
    
    </van-list>
      
    </div>
  </div>
</template>

<script setup>
const { loading, setLoading } = useLoading()
loading.value = true
const finished = ref(false);
const error = ref(false);
const pageNum=ref(1)
const draftList = ref([])

async function getNotesList() {
  setLoading(true)
  pageNum.value++
  try {
    const { data } = await request('/website/tourism/publishTravelNotes/getDraftList', {
      query: {
        pageNum: pageNum.value,
        pageSize: 5,
        type: 1
      }
    })
    draftList.value = draftList.value.concat(data.dataList);
    loading.value = false;
    if (draftList.value.length >= data.totalCount) {
      finished.value = true;
    }
  } 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>
