<template>
  <navBar :type="'home'"></navBar>
  <view class="page">
    <view class="databox">
      <view class="cell">
        <view class="num">{{ numInfo.article_num }}</view>
        <view class="name">文章</view>
      </view>
      <view class="cell">
        <view class="num">{{ numInfo.video_num }}</view>
        <view class="name">视频</view>
      </view>
      <view class="cell">
        <view class="num" >{{(numInfo.video_read_num && numInfo.article_read_num)?numInfo.video_read_num+numInfo.article_read_num:0}}</view>
        <view class="name">阅读量</view>
      </view>
    </view>
    <view class="kubox">
      <view class="row">
        <up--image
        @click="goVideo"
        :src="videoImg"
        radius="20rpx"
        width="330rpx"
        height="176rpx"

      ></up--image>
       <up--image
        :src="sickImg"
        @click="goSick"
         width="330rpx"
         radius="20rpx"
        height="176rpx"
      ></up--image>
        <!-- <view class="item">
          <u-icon name="order" size="28" color="#00919E"></u-icon>
          <view class="name">视频病例库</view>
        </view>
        <view class="item" style="background: #fef8f0; margin-right: 30rpx">
          <u-icon name="order" size="28" color="#F08500"></u-icon>
          <view class="name" style="color: #f08500">疾病病例库</view>
        </view> -->
      </view>
      <view class="row" style="margin-top: 30rpx">
         <up--image
          @click="goHospital"
        :src="hospitalImg"
        radius="20rpx"
        width="330rpx"
        height="176rpx"

      ></up--image>
       <up--image
        :src="doctorImg"
         @click="searchDoctor"
         width="330rpx"
         radius="20rpx"
        height="176rpx"
      ></up--image>
      </view>
    </view>
    <view class="newsbox">
      <view class="titlebox">
        <view class="title">最新上线</view>
        <view class="more" @click="goList('new')">
          <view class="morename">查看更多</view>
          <u-icon name="arrow-right" size="16" color="#3CC7C0"></u-icon>
        </view>
      </view>
      <view class="listbox">
        <view class="cell" v-for="item in new_articles" :key="item.article_id" @click="goDetail(item.article_id,item.is_link,item.is_link_url)">
          <view class="circle"></view>
          <view class="info">
            <view class="name ellipsis-two-lines">{{item.article_title }}</view>
            <view class="tagsbox">
              <view class="tag" v-for="tag in item.author" :key="tag.author_id">{{ tag.doctor_name }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="newsbox">
      <view class="titlebox">
        <view class="title">最多阅读</view>
        <view class="more" @click="goList('read')">
          <view class="morename">查看更多</view>
          <u-icon name="arrow-right" size="16" color="#3CC7C0"></u-icon>
        </view>
      </view>
      <view class="listbox">
        <view class="cell" v-for="item in most_read_articles" :key="item.article_id" @click="goDetail(item.article_id,item.is_link,item.is_link_url)">
          <view class="circle "></view>
          <view class="info">
            <view class="name ellipsis-two-lines">{{item.article_title }}</view>
            <view class="tagsbox">
              <view class="tag" v-for="tag in item.author" :key="tag.author_id">{{ tag.doctor_name }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="recbox">
      <view class="titlebox">
        <view class="title">医院病例库推荐</view>
        <view class="more" @click="goHospital">
          <view class="morename">查看更多</view>
          <u-icon name="arrow-right" size="16" color="#3CC7C0"></u-icon>
        </view>
      </view>
      <view class="list">
        <view class="cell ellipsis-one-lines" v-for="item in recommend_hospital" :key="item.hospital_id" @click="goListBy(item.hospital_id,item.hospital_name ,'hospital')">{{ item.hospital_name }}</view>
      </view>
    </view>
	<view class="recbox">
      <view class="titlebox">
        <view class="title">医生病例库推荐</view>
        <view class="more" @click="searchDoctor">
          <view class="morename">查看更多</view>
          <u-icon name="arrow-right" size="16" color="#3CC7C0"></u-icon>
        </view>
      </view>
      <view class="list">
      <view class="cell ellipsis-one-lines" v-for="item in recommend_doctor" :key="item.doctor_id" @click="goListBy(item.doctor_id,item.doctor_name ,'doctor')">{{ item.doctor_name }}({{item.hospital_name}})</view>
      </view>
    </view>
  </view>

  <tabBar></tabBar>
 
</template>

<script setup>
import { ref, reactive, onMounted,getCurrentInstance } from "vue";
import {onShow} from "@dcloudio/uni-app";
import tabBar from "@/components/tabBar/tabBar.vue";
import navBar from "@/components/navBar/navBar.vue";
import navTo  from "@/utils/navTo.js";
import list from "@/uni_modules/z-paging/components/z-paging/z-paging";
import api from "@/api/api";
const paging = ref(null);
const dataList = ref([]);
import videoImg from "@/static/video.png";
import sickImg from "@/static/sick.png";
import hospitalImg from "@/static/hospital.png";
import doctorImg from "@/static/doctor.png";
import { object } from "uview-plus/libs/function/test";
const most_read_articles = ref([]);
const new_articles = ref([]);
const recommend_doctor=ref([]);
const recommend_hospital=ref([]);
const numInfo=reactive({})
const goDetail = (id,isLink,src) => {
 if(isLink==1){
	 api.readRecord({
	   type:1,
	   id:id
	   }).then(res=>{
		   
	   })
	 // #ifdef MP-WEIXIN
	 navTo({
	   url: `/pages/web/web?src=${src}`,
	 });  
	 // #endif 
	// #ifdef H5
	 window.location.href=`${src}`
	// #endif 
 }else{
	navTo({
	  url: `/pages/detail/detail?id=${id}&type=article`,
	}); 
 }
 
};
const goListBy=(id,name,type)=>{
  let url=''
  if(type=='doctor'){
    url=`/pages/search/search?doctor_id=${id}&doctor_name=${name}`
  }else{
    url=`/pages/search/search?hospital_id=${id}&hospital_name=${name}`
  }
  navTo({
    url:url,
  });
}

const getData = async() => {
    const {data}=await api.getHomeData();
    if(data.code==200){
       most_read_articles.value=data.data.most_read_articles;
       new_articles.value=data.data.new_articles;
       recommend_doctor.value=data.data.recommend_doctor;
       recommend_hospital.value=data.data.recommend_hospital;

    }
  };
  const getStatic=()=>{
    api.getHomeStatics().then((res) => {
      let result=res.data.data;
       Object.assign(numInfo,result);
      
    })
}
const goList=(type)=>{
	navTo({
		url:'/pages/search/search?order='+type
	})
};
const goVideo=()=>{
  navTo({
    url:'/pages/videoList/videoList'
  })
}
const goSick=()=>{
  navTo({
    url:'/pages/sickList/sickList'
  })
}
const searchDoctor=()=>{
	navTo({
		url:'/pages/searchList/searchList?type=doctor&name=医生&id='
	})
}
const goHospital=()=>{
	navTo({
		url:'/pages/searchList/searchList?type=hospital&name=医院&id='
	})
}

onShow(() => {
  getStatic();
  getData();
  
});
</script>
<style lang="scss" scoped>
 .tagsbox {
    margin-top: 20rpx;
    display: flex;
	flex-wrap: wrap;
    .tag {
      padding: 0 10rpx;
      margin-right: 16rpx;
      height: 46rpx;
      line-height: 46rpx;
      text-align: center;
      background: rgba(60, 199, 192, 0.1);
      border-radius: 8rpx;
      font-weight: 400;
      font-size: 24rpx;
      color: #3cc7c0;
    }
  }
.newsbox {
  margin-bottom: 16rpx;
}
.recbox{
	padding-bottom: 23rpx;
   margin-bottom: 16rpx;
  padding-top: 36rpx;
  background: #fff;
  .cell {
    margin: 23rpx 30rpx 0;;
    padding: 34rpx;
    background: #f3f4f6;
    font-size: 30rpx;
    color: #4b5563;
    line-height: 43rpx;
    border-radius: 15rpx;
  }
}
.listbox {
  .cell {
    margin: 0 30rpx;
    display: flex;
    align-items: flex-start;
    border-bottom: 1rpx solid #f3f4f6;
    padding: 34rpx 0;
    .circle {
      margin-right: 30rpx;
      margin-top: 18rpx;
      width: 16rpx;
      height: 16rpx;
	  flex-shrink: 0;
      background: #3cc7c0;
      border-radius: 50%;
    }
    .name {
      font-size: 32rpx;
      color: #000000;
      line-height: 46rpx;
    }
    .author {
      font-size: 28rpx;
      color: #4b5563;
      line-height: 38rpx;
    }
  }
}
.titlebox {
  margin: 0 30rpx;
  display: flex;
  justify-content: space-between;
  .title{
	  font-weight: bold;
	  font-size: 32rpx;
  }
  .more {
    display: flex;
    align-items: center;
    .morename {
      margin-right: 10rpx;
      font-size: 28rpx;
      color: #3cc7c0;
    }
  }
}
.newsbox {
  padding-top: 36rpx;
  background: #fff;
}
.page {
  background: #f9fafb;
  height: calc(100vh - 425rpx);
  overflow-y: scroll;
}
.kubox {
  padding: 30rpx 0;
  width: 100%;
  background: rgba(0, 0, 0, 0);
  .row {
    padding:0 30rpx;
    display: flex;
    justify-content: space-between;
    .item {
      margin-left: 30rpx;
      padding: 32rpx;
      flex: 1;
      background: #e9fafb;
      border-radius: 15rpx;
      .name {
        font-size: 32rpx;
        color: #00919e;
        line-height: 46rpx;
      }
    }
  }
}
.databox {
  height: 162rpx;
  background: #ffffff;
  display: flex;
  padding: 0 30rpx;
  justify-content: space-between;
  .cell {
    flex: 1;
    padding: 35rpx 0;

    text-align: center;

    .num {
      font-size: 38rpx;
      color: #3cc7c0;
    }
    .name {
      margin-top: 18rpx;
      font-size: 28rpx;
      color: #4b5563;
    }
  }
}

</style>