<template>
  <view class="card-shadow p-base relative" @click="onClick">
    <view class="flex items-center justify-between">
      <view>{{ statusFun(item.type, 'messages', 'name') }}</view>
      <view class="text-hex-999 text-24rpx">{{
        timeFormat(item?.created_at, 'mm月dd日 hh:MM')
      }}</view>
    </view>
    <view class="mt-14rpx text-hex-999 text-26rpx"> {{ item?.content }} </view>
    <view
      class="text-right text-hex-999 text-24rpx flex items-center justify-end"
    >
      <view class="flex items-center">
        <view>点击查看详情</view>
        <uv-icon size="22rpx" class="ml-10rpx" name="arrow-right"></uv-icon>
      </view>
    </view>
    <view class="absolute right-10rpx top-10rpx" v-if="item.is_read == 0">
      <uv-badge :isDot="true" type="error"></uv-badge>
    </view>
  </view>
</template>
<script setup>
import { timeFormat } from '@climblee/uv-ui/libs/function/index'
import statusFun from '@/utils/status'
import { http } from '@/utils/request'

const pageData = {
  task_hygienes: {
    path: '/pages/task/detail',
  },
  reimbursements: {
    path: '/pages/expense-account/detail',
  },
  employee_promotions: {
    path: '/pages/work/detail',
  },
  employee_sign_repairs: {
    path: '/pages/make-card/detail',
  },
  holiday_applies: {
    path: '/pages/ask-leave/detail',
  },
  offical_business: {
    path: '/pages/business/detail',
  },
  overtime_applies: {
    path: '/pages/overtime/detail',
  },
  agreements: {
    path: '/pages/contract/detail',
  },
}
const props = defineProps({
  item: {
    type: Object,
    default: () => {},
  },
})

const onClick = () => {
  // props.item.is_read = 1

  const { type, is_read, id } = props.item
  const { additional } = props.item

  if (is_read == 0) {
    http.get(`/message/messages/${id}`)
    props.item.is_read = 1
  }

  if (type == 'approval') {
    //详情
    if (additional.subject) {
      const subject_type = additional.subject_type
      const { id } = additional.subject
      const path = pageData[subject_type].path
      if (path) {
        uni.navigateTo({
          url: `${path}?id=${id}&type=${subject_type}`,
        })
      }
    }
    //审批
    if (additional.workflow_log) {
      const { check,id } = additional.workflow_log
      const { subject_type, subject_id } = check
      uni.navigateTo({
        url: `/pages/audits/detail?id=${id}&type=${subject_type}`,
      })
    }
  } else if (type == 'exam') {
    //考试
    const { paper } = additional
    const { id } = paper
    uni.navigateTo({
      url: `/pages/examination/detail?id=${id}`,
    })
  }
}
</script>
