<script setup lang="ts">
import { useRouter } from 'vue-router'
import { get1, get2, get3, get4, getDick, getNews, type NewsData, type NewsResponseData } from '@/api/home'
import { ref } from 'vue'
import { getFileExtension } from '@/utils/getFileExtension'
import { queryFieldMethod } from '@/utils/queryFieldMethod'
import { formatTime } from '../../utils/formatTime'

let router = useRouter()

const toDetail = (id:number|undefined)=>{
  if(!id){
    return
  }
  router.push({
    path:'/newsDetail',
    query:{
      id
    }
  })
}
const toLink = (index:number)=>{
  if(index == 1){
    window.open("http://hntzxm.fgw.hunan.gov.cn/home")
  }else if(index == 2){
    window.open("http://220.168.30.70:28889/portal_v2.jsp")
  }else if(index == 3){
    window.open("https://222.244.103.250:8181/pmp/a/login;jsessionid=fa168d5f90a3ed7b76a9bd5f2442#")
  }
}
const toOrtherLink = (index:number)=>{
  if(index == 1){
    window.open("https://credit.fgw.hunan.gov.cn/xyd/feature")
  }else if(index == 2){
    window.open("https://smecmd.hunanfae.com/main/cms/static/html/loan.html")
  }else if(index == 3){
    window.open("https://credit.fgw.hunan.gov.cn/xyd/financeMarketDetail?id=414&isShow=ck")
  }else if(index == 4){
    window.open('https://credit.fgw.hunan.gov.cn/xyd/financeMarketDetail?id=26&isShow=ck')
  }
}
const toLink1 = ()=>{
  window.open("https://www.hhjrfw.com/")
}
const toLink2 = ()=>{
  window.open("https://credit.fgw.hunan.gov.cn/xyd/provincialIndex")
}
const financialData = ref<NewsData[]>([])
const financingLoans = ref<NewsData[]>([])
const creditDynamics = ref<NewsData[]>([])
const dickMapAll = ref<Map<string,string>>(new Map());
const data1 = ref();
const data2 = ref();
const data3 = ref();
const data4 = ref();
const init =async ()=>{
  const {data} = await getDick()
  const dickMap = data.reduce((acc:Map<string,string>, cur:{dictLabel:string,dictValue:string}) => {
    const key = cur.dictLabel;
    acc.set(key, cur.dictValue);
    return acc;
  },new Map())
  dickMapAll.value = dickMap
  console.log(dickMap)
  //获取政府项目资金需求 数据
  const res1 = await getNews(queryFieldMethod('special_column',dickMap.get('政府项目资金需求')))
  if(res1.code == 200){
    financialData.value = res1.data.slice(0,5);
  }
  //获取园区企业融资贷款 数据
  const res2 = await getNews(queryFieldMethod('special_column',dickMap.get('园区企业融资贷款')))
  if(res2.code == 200){
    financingLoans.value = res2.data.slice(0,5);
  }
  //获取信用动态 数据
  const res3 = await getNews(queryFieldMethod('special_column',dickMap.get('信用动态')))
  if(res3.code == 200){
    creditDynamics.value = res3.data.slice(0,5);
  }
  //获取行政许可 数据
  const res4 = await get1({pageNum:1,pageSize:4})
  data1.value = res4.records.slice(0,4);
  //获取行政处罚 数据
  const res5 = await get2({pageNum:1,pageSize:4})
  data2.value = res5.records.slice(0,4);
  //获取守信红名单 数据
  const res6 = await get3({pageNum:1,pageSize:4})
  data3.value = res6.records.slice(0,4);
  //获取失信黑名单 数据
  const res7 = await get4({pageNum:1,pageSize:4})
  data4.value = res7.data.result.slice(0,4);
}
const toCompanyList = (n:number)=>{
  router.push({
    path:'/companyList',
    query:{
      n
    }
  })

}
const knowMore = (dickMapKey:string|undefined,dickMapValue:string|undefined)=>{
  console.log(dickMapKey)
  router.push({
    path:'/creditDynamicsDetail',
    query:{
      dickMapKey,
      dickMapValue
    }
  });
}
init()
</script>

<template>
    <div class="homeContainer">
      <div class="w-100px h-25px"></div>
      <div class="w-912px ml-auto mr-auto mt-20px mb-20px bg-white">
        <div class="w-912px text-16px mt-12px mb-10px line-height-44px border-dashed border-#e5e5e5 border-b-5px">
          <div class="w-120px border-solid border-#00306e border-b-5px relative">
            <img class="w-21px h-21px m-3px " src="/src/assets/img/信用小图标.png" />
            <span class="color-#003aac text-16px">信用动态</span>
            <span class="absolute right--775px top-3px cursor-pointer text-#959595" @click="knowMore(dickMapAll.get('信用动态'),'信用动态')">查看更多 ></span>
          </div>
        </div>
        <div class="w-100%">
          <div v-for="(item,index) in creditDynamics" :key="index" @click="toDetail(item.id)" class="cursor-pointer">
            <div class="flex justify-between">
              <div class="mt-24px ml-24px color-black flex">
                <div class="text-16px mr-10px">{{item.title}}</div>
                <!--                <div class="text-13px rounded-5 p-3px border-solid border-1px border-#ff9900 color-#ff9900 ">文本服务</div>-->
              </div>
              <div class="color-#858585 text-13px pt-23px mr-24px">{{item.dataSource}}|{{formatTime(item.date)}}</div>
            </div>
            <div class="mt-13px w-864px ml-auto mr-auto line-clamp-3 text-13px line-height-23px" v-html="item.content"></div>
            <div class="h-1px bg-#e9e9e9 mt-20px"></div>
          </div>
        </div>
      </div>
      <div class="w-912px ml-a mr-a flex flex-wrap">
        <div class="w-451px bg-white mb-20px mr-10px">
          <div class="h-4px bg-blue"></div>
          <div class=" flex justify-between">
            <div class="text-26px h-34px line-height-34px">行政许可</div>
            <div class="text-13px h-20px line-height-30px cursor-pointer" @click="toCompanyList(1)">查看更多 >></div>
          </div>
          <div class="h-2px bg-blue"></div>
          <div class="p-10px flex justify-between" v-for="(item,index) in data1" :key="index">
            <div>{{item.administrativePartyName}}</div>
            <div>{{item.licenseDecisionDate}}</div>
          </div>
        </div>
        <div class="w-451px bg-white mb-20px">
          <div class="h-4px bg-blue"></div>
          <div class=" flex justify-between">
            <div class="text-26px h-34px line-height-34px">行政处罚</div>
            <div class="text-13px h-20px line-height-30px cursor-pointer" @click="toCompanyList(2)">查看更多 >></div>
          </div>
          <div class="h-2px bg-blue"></div>
          <div class="p-10px flex justify-between" v-for="(item,index) in data2" :key="index">
            <div>{{item.administrativePartyName}}</div>
            {{item.penaltyDecisionDate.split('T')[0]}}
          </div>
        </div>
        <div class="w-451px bg-white mb-20px mr-10px">
          <div class="h-4px bg-blue"></div>
          <div class=" flex justify-between">
            <div class="text-26px h-34px line-height-34px">守信红名单</div>
            <div class="text-13px h-20px line-height-30px cursor-pointer" @click="toCompanyList(3)">查看更多 >></div>
          </div>
          <div class="h-2px bg-blue"></div>
          <div class="p-10px flex justify-between" v-for="(item,index) in data3" :key="index">
            <div>{{ item.subjectName }}</div>
            <div>{{item.statisticsTime.split('T')[0]}}</div>
          </div>
        </div>
        <div class="w-451px bg-white mb-20px">
          <div class="h-4px bg-blue"></div>
          <div class=" flex justify-between">
            <div class="text-26px h-34px line-height-34px">失信黑名单</div>
            <div class="text-13px h-20px line-height-30px cursor-pointer" @click="toCompanyList(4)" v-if="data4 != 0">查看更多 >></div>
          </div>
          <div class="h-2px bg-blue"></div>
          <div>
            <div class="p-10px flex justify-between" v-for="(item,index) in data4" :key="index">
              <div>{{item.enterpriseName}}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="w-912px h-100px mr-a ml-a bg-white mt-10px bg-cover text-50px blod text-center line-height-90px cursor-pointer mb-25px hover:scale-120 duration-200" @click="toLink2">
        湖南省企业融资综合信用服务平台
      </div>
      <div class="w-912px h-100px mr-a ml-a bg-white mt-10px bg-cover text-50px blod text-center line-height-90px cursor-pointer mb-25px hover:scale-120 duration-200" @click="toLink1">
        怀化市综合金融服务平台
      </div>
      <div>
        <div class="w-912px bg-white ml-a mr-a text-16px pt-12px mb-10px line-height-44px border-dashed border-#e5e5e5 border-b-5px">
          <div class="w-240px border-solid border-#00306e border-b-5px relative">
            <img class="w-21px h-21px m-3px " src="/src/assets/img/信用小图标.png" />
            <span class="color-#003aac text-16px">政府项目资金需求发布及链接</span>
            <span class="absolute right--650px top-10px cursor-pointer text-#959595" @click="knowMore(dickMapAll.get('政府项目资金需求'),'政府项目资金需求')">查看更多 ></span>
          </div>
          <div v-for="(item,index) in financialData" :key="index">
            <div class="flex justify-between">
              <div class="ml-20px cursor-pointer" @click="toDetail(item.id)">{{item.title}}</div>
              <div class="color-gray mr-20px text-14px">
                <span>数据来源:{{item.dataSource}}</span>
                <span>|</span>
                <span>{{formatTime(item.date)}}</span>
              </div>
            </div>
            <div class="h-1px bg-gray"></div>
          </div>
        </div>
        <div>
          <div class="w-912px ml-auto mr-auto flex flex-wrap justify-between bg-white">
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toLink(1)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">湖南省发改委项目审批</div>
            </div>
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toLink(2)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">湖南省财政厅项目资金管理</div>
            </div>
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toLink(3)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">湖南省工信厅项目管理</div>
            </div>
            <div class="w-174px h-116px mr-10px relative">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">待开发</div>
            </div>
            <div class="w-174px h-116px relative">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">待开发</div>
            </div>
          </div>
        </div>
      </div>
      <div>
        <div class="w-912px bg-white ml-a mr-a text-16px mt-12px mb-10px line-height-44px border-dashed border-#e5e5e5 border-b-5px">
          <div class="w-240px border-solid border-#00306e border-b-5px relative">
            <img class="w-21px h-21px m-3px " src="/src/assets/img/信用小图标.png" />
            <span class="color-#003aac text-16px">园区企业融资贷款</span>
            <span class="absolute right--650px top-10px cursor-pointer text-#959595" @click="knowMore(dickMapAll.get('园区企业融资贷款'),'园区企业融资贷款')">查看更多 ></span>
          </div>
          <div v-for="(item,index) in financingLoans" :key="index">
            <div class="flex justify-between">
              <div class="ml-20px cursor-pointer" @click="toDetail(item.id)">{{item.title}}</div>
              <div class="color-gray mr-20px text-14px">
                <span>数据来源:{{item.dataSource}}</span>
                <span>|</span>
                <span>{{formatTime(item.date)}}</span>
              </div>
            </div>
            <div class="h-1px bg-gray"></div>
          </div>
        </div>
        <div>
          <div class="w-912px ml-auto mr-auto flex flex-wrap justify-between bg-white">
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toOrtherLink(1)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">制造业中长期贷款</div>
            </div>
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toOrtherLink(2)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">潇湘财银贷</div>
            </div>
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toOrtherLink(3)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">农业银行流水贷</div>
            </div>
            <div class="w-174px h-116px mr-10px relative cursor-pointer" @click="toOrtherLink(4)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">湖南银行流水贷</div>
            </div>
            <div class="w-174px h-116px relative cursor-pointer" @click="toOrtherLink(5)">
              <img class="w-100% h-100%" src="/src/assets/img/首页背景.png" />
              <div class="absolute bottom-0 text-center w-100% h-22px text-white text-14px pt-4px pb-4px bg-#00306e bg-opacity-72">待开发</div>
            </div>
          </div>
        </div>
      </div>
      <div class="h-20px "></div>
    </div>
</template>

<style scoped lang="scss">
.homeContainer{
  background-color: #ecf0f9;
}
</style>
