<script setup lang="ts" name="LeaveListItem">
import { ref, reactive, computed, onMounted } from 'vue'
import { parseTime } from '@/common/utils/ruoyi'
import { getDeptName, getPostName } from '@/common/utils/transcoding'
import { useDict } from '@/common/utils/dict'
const emit = defineEmits<{
  'onDetail': [item: any]
  'onUpdate': [item: any]
  'onDelete': [item: any]
  'onApply': [item: any]
}>()
const props = defineProps<{
  item: any
  userInfo: any
}>()
const { life_material_status, sys_user_sex, housing_flag } = useDict('life_material_status', 'sys_user_sex', 'housing_flag')
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 onDelete() {
  emit('onDelete', props.item)
}
function onApply() {
  emit('onApply', 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.userInfo.nickname.substr(0, 1) }}</div>
        <div class="list-item__top-title-label">{{ props.userInfo.nickname }}提交的入住申请</div>
      </div>
      <div class="list-item__top-time"><DictTag :options="life_material_status" class="dict-tag" :value="props.item.auditStatus" /></div>
    </div>
    <!-- <el-table-column label="工号" prop="staffNumber" />
        <el-table-column label="部门" prop="serviceDepartmentId" show-overflow-tooltip >
          <template #default="scope">
            {{ getDeptName(scope.row.serviceDepartmentId) }}
          </template>
        </el-table-column>
        <el-table-column label="岗位" prop="positionHeldId" show-overflow-tooltip>
          <template #default="scope">
            {{ getPostName(scope.row.positionHeldId) }}
          </template>
        </el-table-column> -->
    <div class="list-item__date">申请日期：{{ parseTime(props.item.createTime, '{y}-{m}-{d}') }}</div>
    <div class="list-item__date">工号：{{ props.item.staffNumber }}</div>
    <div class="list-item__date">部门：{{ getDeptName( props.item.serviceDepartmentId ) }}</div>
    <div class="list-item__date">岗位：{{ getPostName( props.item.positionHeldId ) }}</div>
    <div class="list-item__date">联系方式：{{ props.item.contactInformation }}</div>
    <div class="list-item__date">处理人：{{ props.item.processor }}</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
        class="option-btn"
        type="primary"
        size="small"
        beautify
        @click.stop="onDetail">详情</van-button>
      <van-button
        :disabled="!['1','5','6'].includes(props.item.auditStatus)"
        class="option-btn"
        type="primary"
        size="small"
        beautify
        @click.stop="onApply">提交</van-button>
      <van-button
        :disabled="!['1','5','6'].includes( props.item.auditStatus)"
        class="option-btn"
        type="primary"
        size="small"
        beautify
        @click.stop="onUpdate">修改</van-button>
      <van-button
        :disabled="!['1','5','6'].includes(props.item.auditStatus)"
        type="primary"
        size="small"
        beautify
        @click.stop="onDelete">删除</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: flex-end;
    align-items: center;
    margin-top: @marginTop;
  }
}
.option-btn {
  margin-right: 1rem;
}
</style>
