<script setup lang="ts" name="LeaveDetailFlow">
/* 出差详情 */
import { ref, reactive, computed, onMounted } from 'vue'
// import { useRouter } from 'vue-router'
// import { showImagePreview } from 'vant'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import { getBusinessTrip } from '@/api/attendance/trip'
import { useDict } from '@/common/utils/dict'
import FlowTimeline from '@/components/Flow/FlowTimeline.vue'
import TripCloseListItem from './TripCloseListItem.vue'

// const router = useRouter()
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>()
const activeTab = ref('')

getBusinessTrip(props.id).then(res => {
  detail.value = res.data
})
getFlowChart({ instanceId: props.instanceId }).then(res => {
  nodeData.value = res.data
})

// 预览
function onPreview(index) {

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

// 点击销假列表
function onDetailClose(item) {
  // router.push({
  //   path: '/attendance/trip/close-detail',
  //   query: {
  //     id: item.id,
  //     instanceId: item.instanceId
  //   }
  // })
  uni.navigateTo({
    url:'/attendance/trip/close-detail?id=' + item.id + '&instanceId=' + item.instanceId
  })
}
</script>

<template>
  <van-tabs v-model="activeTab">
    <van-tab name="0" title="详情">
      <van-cell-group>
        <van-cell title="出差地点" :value="detail.location" />
        <van-cell title="开始时间" :value="detail.beginTime" />
        <van-cell title="结束时间" :value="detail.businessTripStatus === '2' ? detail.realBackTime : detail.endTime" />
        <van-cell title="出差天数" :value="detail.day" />
        <van-cell title="出差事由" :value="detail.reason" />
        <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="出差关闭">
      <TripCloseListItem :list="detail.businessTripBackList" @on-detail="onDetailClose" />
    </van-tab>
  </van-tabs>
</template>

<style lang="less" scoped>
.grid {
  :deep(.van-image) {
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    .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;
    }
  }
}
</style>
