<script lang="ts" setup>
import { useRouterDetail } from '@/pages-sub/me/useRouterDetail'
import { deleteBusReport, getMyBusReports } from '@/service'
import { useUserStore } from '@/store'

definePage({
    style: {
        navigationBarTitleText: '测评结果',
    },
})
const userStore = useUserStore()

const list = ref<any[]>([])

function deleteReport(id: string) {
  uni.showModal({
    title: '确认需要删除吗?',
    confirmText: '删除',
    success: ({ confirm }) => {
      if (!confirm)
        return

      deleteBusReport({ data: { id } }).then((res) => {
        if (res.code === 200) {
          list.value = list.value.filter(item => item.reportsId !== id)
        }
      })
    },
  })
}

onShow(() => {
  getMyBusReports({query:{ CustomId: userStore.userInfo?.userExtend.wxId }}).then((res) => {
    if (res.code === 200) {
      list.value = (res.result as { customReports: any[] }).customReports
    }
  })
})
</script>

<template>
    <view class="bg-[#F8F8F8] h-screen px-[30rpx] overflow-y-auto">
        <view v-for="(val, index) in list" :key="index" class="flex first:mt-[30rpx] not-last:mb-[20rpx]" v-if="list.length > 0" @click.stop="useRouterDetail(val)">
            <view
                class="text-[30rpx] grid gap-[8rpx] bg-white px-[30rpx] py-[20rpx] rounded-[16rpx] w-full flex items-center justify-between">
                <view class="">
                    <view class="text-[32rpx] font-600">{{ val.title }}</view>
                    <view class="text-[#666] text-[24rpx]">
                       {{ val.createTime }}
                    </view>
                </view>
                <view class="flex items-center border-[2rpx] border-[#ccc] border-solid rounded-[8rpx] px-[12rpx] py-[4rpx]" @click.stop="deleteReport(val.reportsId)">
                    <view class="w-[32rpx] h-[32rpx] flex items-center">
                        <image src="https://lwzk.ycymedu.com/img/qt/wd_shanchu.png"
                            class="w-[32rpx] h-[32rpx]" />
                    </view>
                    <view class="text-[#999] text-[26rpx]">删除</view>
                </view>
            </view>
        </view>

        <view class="flex flex-col items-center justify-center pt-[322rpx]" v-else>
            <view class="w-[414rpx] h-[298rpx]">
                <image src="https://lwzk.ycymedu.com/img/qt/wd_moren.png" mode="scaleToFill"
                    class="w-[414rpx] h-[298rpx]" />

            </view>
            <view class="text-[#636363] text-[24rpx]">暂无数据</view>

        </view>
    </view>
</template>

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