<template>
	<view class="dljt-page-box" v-if="data.info">
		<MtaNavbar></MtaNavbar>
		<view class="dljt-container-box">
			<!-- 详情页面 -->
			<view class="dljt-page-title">职业培训</view>
			<view class="dljt-page-content-box">
				<!-- 导航 -->
				<view class="dljt-breadcrumb-box">
					<view class="breadcrumb-text" @click="handleGo('shouye')">首页</view>
					<icon class="breadcrumb-jt"></icon>
					<view class="breadcrumb-text">职业培训</view>
					<icon class="breadcrumb-jt"></icon>
					<view class="breadcrumb-text" @click="handleGo('tzgg')">通知公告</view>
					<icon class="breadcrumb-jt"></icon>
					<view class="breadcrumb-active">详情</view>
				</view>
				<view class="dljt-detail-box">
					<!-- 标题 -->
					<view class="detail-title">{{data.info.title}}</view>
					<!-- 时间 -->
					<view class="detail-data">{{formatDate.join('-') }}</view>
					<!-- 富文本 -->
					<MtaMpHtml class="dljt-editor-box" :content="data.info.content"></MtaMpHtml>

				</view>
				
				<!-- table -->
				<view class="dljt-table-box" v-if="isHasLink(data.info.ziliao)">
					<view class="table-th-row">
						<view style="width: 15%">序号</view>
						<view style="width: 60%">资料名称</view>
						<view style="width: 25%">下载</view>
					</view>
					<view class="table-td-row" v-for="(ccIte,index) in data.info.ziliao">
						<view style="width: 15%" class="item-center"><view>{{index+1}}</view></view>
						<view style="width: 60%"><view>{{ccIte.name}}</view></view>
						<view style="width: 25%">
							<a class="table-btn" @click="handleDownFile(ccIte)" >文件下载</a>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部导航 -->
		<MtaFooter></MtaFooter>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		computed,
		onMounted,
		onUnmounted
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import * as httpApi from "@/api/common.js"
	import {
		formatDateToYearMonthDay
	} from "@/utils/common.js"
	import MtaMpHtml from "@/components/MTAMpHtml/MtaMpHtml.vue"
	import MtaFooter from "@/components/MtaFooter.vue"
	import {
		getCommonZypxTongzhiInfo
	} from "../../api/common";
	const data = reactive({
		info: null,
		id: null
	})
	const formatDate = computed(() => {
		if (data.info && data.info.createTime) {
			return formatDateToYearMonthDay(data.info.createTime)
		}
		return []
	})


	onLoad(({
		id
	}) => {
		data.id = id;
		pageInit();
	})
	
	function handleDownFile(ccite) {
		window.location.href = ccite.url;
	}
  function isHasLink(list) {
    if (!list) {
      return false;
    }
    if (list.length>1) {
      return true
    }
    if (list.length == 0 ) {
      return false
    }
    if (list.length == 1 && list[0].name && list[0].url) {
      return true
    }
  
    return false
  }

	function handleGo(code) {
		if (code == 'shouye') {
			uni.navigateTo({
				url: '/pages/index/index'
			})
		}
		if (code == 'tzgg') {
			uni.navigateTo({
				url: '/pages/zypxTongzhigonggao/zypxTongzhigonggao'
			})
		}
	}


	function pageInit() {
		httpApi.getCommonZypxTongzhiInfo({
			id: data.id
		}).then(res => {
			data.info = res.data;
		})
	}
</script>

<style>

</style>