<script setup lang="ts" name="LeaveDetailFlowClose">
/* 销假详情 */
import { parseTime } from '/common/utils/ruoyi'
import { getLeaveRequrstBack } from '@/api/attendance/leave'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import { useDict } from '@/common/utils/dict'
import FlowTimeline from '@/components/Flow/FlowTimeline.vue'

const props = defineProps<{
  id: string
  instanceId: string
}>()

const { request_leave_type } = useDict('request_leave_type')

const detail = ref<any>({})
const detailClose = ref<any>({})
const nodeData = ref<any>()

getLeaveRequrstBack(props.id).then(res => {
  detail.value = res.data.tAttLeaveRequest
  detailClose.value = res.data.leaveRequestBack
})
getFlowChart({ instanceId: props.instanceId }).then(res => {
  nodeData.value = res.data
})

// 预览
function onPreview(index) {
  // showImagePreview({
  //   images: detail.value.fileList.map(item => item.url),
  //   startPosition: index
  // })

  uni.previewImage({
    urls:detail.value.fileList.map(item => item.url),
    current:index
  })
}
</script>

<template>
  <div class="container__card flex">
    <van-cell-group>
      <van-cell title="销假申请时间" :value="detailClose?.applyTime" />
      <van-cell v-if="['8', '9'].includes(detail?.leaveType)" title="提前返回时长(小时)" :value="detailClose?.differHour" />
      <van-cell title="销假备注" :value="detailClose?.remark" />
      <van-cell title="请假类型">
        <DictTag
          v-if="detail?.leaveType"
          :tag="false"
          :options="request_leave_type"
          :value="detail?.leaveType" />
      </van-cell>
      <van-cell title="开始日期" :value="parseTime(detail.beginTime, '{y}-{m}-{d}')" />
          <van-cell title="开始上午/下午" :value="detail.startHalf === 'AM' ? '上午' : '下午'" />
          <van-cell title="结束日期" :value="parseTime(detail.endTime, '{y}-{m}-{d}')" />
          <van-cell title="结束上午/下午" :value="detail.startHalf === 'PM' ? '上午' : '下午'" />
          <van-cell title="请假时长">
            {{ detail.duringTime }}天
          </van-cell>
      <!-- <van-cell title="代理人" :value="detail?.agentName" /> -->
      <van-cell title="请假事由" :value="detail?.reason" />
      <!-- <van-cell title="岗位紧急处理事务" :value="detail.urgentHandingOfAffairs || '无'" /> -->
      <van-grid
        v-if="detail?.fileList?.length"
        :border="false"
        :column-num="3"
        class="grid">
        <template v-for="(item, index) in detail.fileList" :key="index">
          <van-grid-item>
            <van-image :src="item.url" @click="onPreview(index)" />
          </van-grid-item>
        </template>
      </van-grid>
    </van-cell-group>
    <FlowTimeline :node-data="nodeData" />
  </div>
</template>

<style lang="less" scoped>
.grid {
  :deep(.van-image) {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    border-radius: 0.6rem;
    box-shadow: 0.2rem 0.2rem 0.5rem rgba(0,0,0,0.5);
    overflow: hidden;
    .van-image__img {
      position: absolute;
      object-fit: cover;
    }
  }
}

:deep(.van-cell) {
  .van-cell__title {
    margin-right: 1rem;
    flex: none;
  }
  .van-cell__value {
    display: flex;
    justify-content: flex-end;
    color: var(--van-cell-text-color);
    overflow: hidden;
    span {
      text-align: justify;
    }
  }
}

:deep(.tag-label) {
  font-size: 1.4rem;
}

.list {

}
</style>
