<template>
  <view style="height: 98vh; background-color: #f2f4f7; padding-top: 10px;">
    <view v-if="list.length > 0">
      <uni-card v-for="(item, index) in list" class="list-item" @tap.stop="viewReport(item)" :key="index" :is-shadow="true" :border='false' shadow="0px 0px 3px 1px rgba(0,0,0,0.1)">
        <view class="font-weight-bold">From： {{ formatName(item.enterprise.enterpriseName) }}</view>
				<view>创建时间：{{ timesTampChange(item.entity.createDate) }}</view>
        <view style="text-align: end;">
          <text class="color-primary" @tap.stop="viewReport(item)">点击查看</text>
        </view>
      </uni-card>
      <uni-load-more status="noMore" style="line-height: 20vh;" />
		</view>
		<view v-else class="nodata-img-parent">
			<image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
		</view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { getRecommendationPage } from '@/api/student'
import { onShow } from '@dcloudio/uni-app'
import { formatName } from '@/utils/getText'
import { timesTampChange } from '@/utils/date'
import { preview } from '@/utils/preview'

const list = ref([
  {
    enterprise: {
      enterpriseName: '门墩儿科技有限公司',
    },
    entity: {
      createDate: 1740570206120,
      fileUrl: 'https://minio.menduner.com/dev/person/725759784858554368/attachment/7cde29dc69c1403649be55d4c2bfd3d8304c088dc79ab25afe9c4bf55d3b382f.docx'
    }
  }
])
// list.value = Array.from({ length: 10 }, () => list.value[0]);

// 推荐信预览
const viewReport = (item) => {
  if (!item.entity.fileUrl) {
    uni.showToast({
      title: '加载失败，请稍后重试',
      icon: 'none',
      duration: 2000
    })
    return
  }
  preview(item.entity.fileUrl)
}

// 获取推荐信列表
const getList = async () => {
  try {
    const { data } = await getRecommendationPage({ size: 9999, current: 1 })
    console.log(data, '推荐信列表')
    // list.value = data.records.reverse()
  } catch {}
}

onShow(async () => {
  await getList()
})
</script>

<style lang="scss" scoped>
.list-item {
  background-color: #fff;
  border-radius: 3px;
  box-shadow: 0px 0px 3px 1px rgba(0,0,0,0.1);
}
</style>
