<template>
    <album-carousel-item v-if="images" :temp="temp" :sampleId="sampleId" :farmId="farmId" :images="images" :lock="lock"></album-carousel-item>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted, watch } from "vue";
import "./cacheImg.js"
import AlbumCarouselItem from "./albumCarouselItem";
import {dateFormat} from "@/utils/date_util.js"
import eventBus from "@/api/eventBus.js";

const props =defineProps({
  sampleId:{
    type: [Number, String],
    required: false
  },
  farmId:{
    type: [Number, String],
    required: true
  },
  blueGeoHash:{
    type: String,
    required: false
  },
  temp:{
    type: String,
    required: false
  },
  farmWork:{
    type: Object,
    required: false
  },
  lock:{
    type: Boolean,
    default: true
  }
})
const images = ref(null);
onMounted(() => {
  getList()
});

watch(()=>props.farmId,(newValue,oldValue) =>{
  if(newValue){
    getList()
  }
})

const getList = () =>{
  if(!props.farmId) return
  let params = {farmId: props.farmId}
  if(props.blueGeoHash){
    params.blueZone = props.blueGeoHash
  }
  if(props.sampleId){
    params.sampleId = props.sampleId
  }
  if(props.farmWork?.executeDate){
    let execcuteDate = new Date(props.farmWork.executeDate)
    let beforeExecuteDate = new Date(props.farmWork.beforeExecuteDate)
    const pastDate = new Date(beforeExecuteDate);
    const futureDate = new Date(execcuteDate);
    params.startDate = dateFormat(pastDate, "YY-mm-dd");
    params.endDate = dateFormat(futureDate, "YY-mm-dd");
  }
  VE_API.image.list(params, {Global: false}).then(res => {
  if(res.code === 0){
      images.value = res.data
    }
  })
}

</script>

<style lang="scss" scoped>
@import "src/styles/index";
</style>
