<script setup lang="ts" name="LeaveDetailFlow">
/* 请假详情 */
import { ref, reactive, computed, onMounted } from 'vue'
import { parseTime } from '/common/utils/ruoyi'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import { getLeaveRequestDetail } from '@/api/attendance/leave'
import { selectDictLabel } from '@/common/utils/ruoyi'
import { useDict } from '../../../common/utils/dict'
import FlowTimeline from '../../../components/Flow/FlowTimeline.vue'
import LeaveCloseListItem from './LeaveCloseListItem.vue'

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

const { request_leave_type, breast_feed_type } = useDict('request_leave_type', 'breast_feed_type')

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

getLeaveRequestDetail(props.id).then(res => {
  detail.value = res.data
})
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
  })
}

// 点击销假列表
function onDetailClose(item) {
  // router.push({
  //   path: '/attendance/leave/close-detail',
  //   query: {
  //     id: item.id,
  //     instanceId: item.instanceId
  //   }
  // })


    uni.navigateTo({
    url:'/attendance/leave/closeDetail?id=' + item.id + '&instanceId=' + item.instanceId
  })
}
</script>

<template>
  <div class="container__card flex">
    <van-tabs v-model="activeTab">
      <van-tab name="0" title="详情">
        <van-cell-group>
          <van-cell title="请假类型">
            <DictTag
              v-if="detail.leaveType"
              :tag="false"
              :options="request_leave_type"
              :value="detail.leaveType" />
          </van-cell>
          <van-cell v-if="detail.leaveType === '17'" title="哺乳假类型">
            <DictTag
              v-if="detail.breastFeedType"
              :tag="false"
              :options="breast_feed_type"
              :value="detail.breastFeedType" />
          </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" />
      </van-tab>
      <van-tab name="1" title="销假">
        <LeaveCloseListItem :list="detail.requestBackList" :leave-type="detail.leaveType" @on-detail="onDetailClose" />
      </van-tab>
    </van-tabs>
  </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>
