<script setup lang="ts" name="OutsideDetailFlow">
/* 请假详情 */
import { ref, reactive, computed, onMounted } from 'vue'
// import { useRouter } from 'vue-router'
// import { showImagePreview } from 'vant'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import { getOutsideApplyInfo } from '@/api/attendance/outside'
import FlowTimeline from '@/components/Flow/FlowTimeline.vue'

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

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

getOutsideApplyInfo(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
  })
}
</script>

<template>
  <div>
    <van-cell-group>
      <van-cell title="当日外出地点" :value="detail.location" />
      <van-cell title="当日外出日期" :value="detail.outsideDate" />
      <van-cell title="预计当日外出开始时间" :value="detail.expectBeginTime" />
      <van-cell title="预计当日外出结束时间" :value="detail.expectEndTime" />
      <van-cell title="实际当日外出开始时间" :value="detail.actualBeginTime ?? '-'" />
      <van-cell title="实际当日外出结束时间" :value="detail.actualEndTime ?? '-'" />
      <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" />
  </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>
