<script setup lang="ts" name="OvertimeWorketailFlow">
/* 集体调休详情 */
import { ref, reactive, computed, onMounted } from 'vue'
// import { useRouter } from 'vue-router'
// import { showImagePreview } from 'vant'
import { getFlowChart } from '@/api/flowEngine/flowInterface'
import { getOverWorkInfo } from '@/api/attendance/overTimeForLeave'
import { useDict } from '../../..//common/utils/dict'
import FlowTimeline from '../../../components/Flow/FlowTimeline.vue'
import ListItemEmployees from './ListItemEmployees.vue'
import DetailEmployees from './DetailEmployees.vue'
import { getDeptName } from '../../../common/utils/transcoding'

// 调休类型
const { att_overtime_type } = useDict('att_overtime_type')

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

const active = ref('1')
const detail = ref<any>({})
const employeesDetail = ref<any>({})
const nodeData = ref<any>()
const activeTab = ref('0')

getOverWorkInfo(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 onDetailEmployees(item) {
  employeesDetail.value = item
  active.value = '2'
}

function onBack() {
  active.value = '1'
}
</script>

<template>
  <div class="container__body">
    <div v-if="active === '1'" class="container__card flex">
      <van-tabs v-model="activeTab">
        <van-tab name="0" title="详情">
          <van-cell-group title="员工基本信息">
            <van-cell title="员工名称" :value="detail.userName" />
            <van-cell title="员工工号" :value="detail.employeesCode" />
            <van-cell title="部门名称" :value="getDeptName(detail.deptId)" />
            <van-cell title="岗位名称" :value="detail.postName" />
          </van-cell-group>
          <van-cell-group title="调休信息">
            <van-cell title="标题" :value="detail.title" />
            <van-cell title="加班类型">
              <DictTag :options="att_overtime_type" :value="detail.type" :tag="false" />
            </van-cell>
          </van-cell-group>
          <FlowTimeline :node-data="nodeData" />
        </van-tab>
        <van-tab name="1" title="加班员工">
          <ListItemEmployees :list="detail.users" @on-detail="onDetailEmployees" />
        </van-tab>
      </van-tabs>
    </div>
    <DetailEmployees v-if="active === '2'" :detail="employeesDetail" @back="onBack" />
  </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>
