<script setup lang="ts">
import { ref } from 'vue'
import { getNews, type NewsData } from '@/api/home'
import { queryFieldMethod } from '@/utils/queryFieldMethod'
import { useRoute, useRouter } from 'vue-router'

const props = defineProps({
  limit:{
    type:Number,
    default:5
  }
});
const creditDynamics = ref<NewsData[]>([])
const router = useRouter()
const route = useRoute()
const init = async ()=>{
  //获取信用动态 数据
  const conditionJsonWhole:any[] = [];
  conditionJsonWhole.push({
    column:'special_column',
    type:'in',
    value:"provincialDynamics,outsideProvincialDynamics,parkDynamics,currentCityDynamics"
  });
  conditionJsonWhole.push({
    column:'date',
    type:'orderByDesc'
  });
  const s = encodeURIComponent(JSON.stringify(conditionJsonWhole));
  const res3 = await getNews({
    conditionJson:s
  })
  if(res3.code == 200){
    creditDynamics.value = res3.data.slice(0,props.limit);
  }
}
const knowMore = (dickMapKey:string|undefined,dickMapValue:string|undefined)=>{
  router.push({
    path:'/creditDynamicsDetail',
    query:{
      dickMapKey,
      dickMapValue
    }
  });
}
const toDetail = (id:number|undefined)=>{
  if(!id){
    return
  }
  router.push({
    path:'/newsDetail',
    query:{
      id
    }
  })
}
init()
</script>

<template>
  <div class="mt-15px bg-white mt-15px min-h-480px relative">
    <div class="ml-10px w-117px border-solid border-#003aac border-b-3px h-32px">
      <img src="/src/assets/img/小图标1.png" />
      <span class="text-#003aac text-16px font-bold ">最新动态</span>
    </div>
    <div v-if="route.query.dickMapValue != '最新动态'" class="absolute right-10px top-15px cursor-pointer text-16px text-#006eff" @click="knowMore('credit_dynamics','最新动态')">查看更多></div>
    <div v-for="(item,index) in creditDynamics" :key="index">
      <div class="mt-20px mb-20px">
        <div class="w-313px mr-auto ml-auto line-clamp-2 bold text-13px">{{item.title}}</div>
        <div class="text-#ff9900 text-13px cursor-pointer text-right mr-10px mt-5px" @click="toDetail(item.id)">查看更多></div>
      </div>
      <div class="h-1px bg-gray"></div>
    </div>
  </div>
</template>

<style scoped>

</style>