<script setup lang="ts" name="TripDetailFlowClose">
/* 出差关闭详情 */
import { ref } from 'vue'
// import { showImagePreview } from 'vant'
import { getBusinessTripBack } from '@/api/attendance/trip'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import FlowTimeline from '../../../components/Flow/FlowTimeline.vue'

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

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

getBusinessTripBack(props.id).then(res => {
  detail.value = res.data.businessTrip
  detailClose.value = res.data.businessTripBack
})
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="detailClose?.applyTime" />
      <van-cell title="出差关闭备注" :value="detailClose?.remark" />
      <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" />
  </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>
