<script setup lang="ts" name="LeaveListItem">
import { ref, reactive, computed, onMounted } from 'vue'
import { parseTime } from '@/common/utils/ruoyi'

const emit = defineEmits<{
  'onRevoke': [item: any]
}>()
const props = defineProps<{
  item: any
  userInfo: any
    audit_status: any
}>()

const now = new Date().getTime()

const hasLeaved = computed(() => {
  let real = props.item?.realEndTime?.replace?.(/-/g, '/')
  real = real ? new Date(real).getTime() : Infinity
  const endTime = new Date(props.item.endTime.replace(/-/g, '/')).getTime()
  return now > real || now >= endTime
})

// function onDetail() {
//   emit('onDetail', props.item)
// }
// function onUpdate() {
//   emit('onUpdate', props.item)
// }
function onRevoke() {
  emit('onRevoke', props.item)
}

</script>

<template>
  <div class="list-item">
    <div class="list-item__top">
      <div class="list-item__top-title">
        <div class="list-item__top-title-firstword">{{ props.item.applyMan.substr(0, 1) }}</div>
        <div class="list-item__top-title-label">{{ props.item.applyMan }}提交的用车申请</div>
      </div>
      <div class="list-item__top-time">{{ parseTime(props.item.createTime, '{y}-{m}-{d}') }}</div>
    </div>
    <div class="list-item__address">
      车牌号：{{ props.item.carNum }}
    </div>
    <div class="list-item__date">申请日期：{{ props.item.applyDate }}</div>
    <div class="list-item__date">归还日期：{{ props.item.applyBacktime }}</div>
    <div class="list-item__date">申请时长：{{ props.item.applyLong }}</div>


    <div class="list-item__detail">
      <div>申请原因：</div>
      <div class="list-item__detail-content">{{ props.item.applyReason }}</div>
    </div>
    <van-divider style="margin: 0.8rem 0;" />
    <div class="list-item__status">
      <DictTag :options="props.audit_status" :value="props.item.auditStatus" />
      <van-button
        v-if="props.item.auditStatus === '2'"
        type="primary"
        size="small"
        beautify
        @click.stop="onRevoke">撤办</van-button>
    </div>
  </div>
</template>

<style lang="less" scoped>
@marginTop: 0.8rem;
.list-item {
  margin-top: 1.2rem;
  background-color: #fff;
  border-radius: 24rpx;
  padding: 1.6rem 1.8rem @marginTop;
  font-size: 1.4rem;
  box-shadow: 0 4rpx 40rpx  rgba(64, 103, 251, 0.14);
  &__top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    &-title {
      flex: 1;
      display: flex;
      align-items: center;
      overflow: hidden;
      &-firstword {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 0.6rem;
        width: 2.6rem;
        height: 2.6rem;
        font-size: 1rem;
        color: #fff;
        background-color: var(--van-primary-color);
        border-radius: 0.6rem;
      }
      &-label {
        flex: 1;
        overflow: hidden;
        font-size: 1.4rem;
        color: #333;
        font-weight: bold;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
    &-time {
      margin-left: 0.6rem;
      color: #999;
      font-size: 1.2rem;
    }
  }
  &__address {
    display: flex;
    margin-top: @marginTop;
    color: #999;
    :deep(.tag-label) {
      font-size: 1.4rem;
    }
  }
  &__date {
    margin-top: @marginTop;
    display: flex;
    justify-content: space-between;
    color: #999;
  }
  &__days {
    margin-top: @marginTop;
    color: #999;
  }
  &__detail {
    margin-top: @marginTop;
    display: flex;
    color: #999;
    &-content {
      flex: 1;
      overflow: hidden;
      word-break: break-all;
    }
  }
  &__status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: @marginTop;
  }
}
.option-btn {
  margin-right: 1rem;
}
</style>
