<template>
	<view class="content padding">
		<view class="tit">{{ info.title }}</view>
		
		<view class="fileList">
			<view class="file" v-for="(item,index) in info.attachmentList" :key="index">
				<!-- <view class="link oneRowText">附件 {{ index+1 }} ----------------------------------------------------------------</view> -->
				<view class="link oneRowText">{{ item.name || index }}</view>
				<view class="lookLink" @click="goWebview(item)">查看附件</view>
			</view>
		</view>
		
		<u-parse :content="info.content" :tagStyle="style"></u-parse>
		
		<view class="timeDesc" v-if="info.timeDesc">创建时间： {{ info.timeDesc }}</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	// let attachmentList = ["https://lyjp-bucket-main.oss-cn-beijing.aliyuncs.com/6f4db7615fff8c35085cdb53976af6afec0b96d857c27cda487487564b7efefb.xls","https://lyjp-bucket-main.oss-cn-beijing.aliyuncs.com/2ec7359a66a38526cbb214adef8c75e39bfd2f17bbf75b5c0547041d333580eb.xls"]
	import {
			onLoad,
			onPullDownRefresh,
		} from '@dcloudio/uni-app'
		
	import { getNoticeDetail } from '@/config/api.js'
	let articleId = ''
	const info = ref('')
	async function getNoticeDetailFn() {
		const {data: res} = await getNoticeDetail({articleId})
		info.value = res
	}
	function goWebview(item) {
		let url = item.url || item
		uni.downloadFile({
			url,
		  success: function (res) {
			  var filePath = res.tempFilePath;
		    uni.openDocument({
		      filePath: filePath,
		      showMenu: true,
		      success: function (res) {
		        console.log('打开文档成功');
		      },
			  success: function (res) {
			    console.log('打开失败成功');
			  }
		    });
		  },
		  fail: (err)=> {
		  	console.log(err);
		  	uni.$u.toast('下载失败')
		  },
		});
		
		return
		uni.showLoading({
			title: '正在下载'
		})
		uni.downloadFile({
		    url: item,
		    success: (res) => {
		    		if (res.statusCode === 200) {
						uni.$u.toast('下载成功')
		    		}
		    	},
			fail: (err)=> {
				console.log(err);
				uni.$u.toast('下载失败')
			},
			complete: (err)=> { uni.hideLoading(); console.log(err) }
		  })
		} 
	onLoad((option)=>{
		articleId = option.id
		getNoticeDetailFn()
	})
	
	onPullDownRefresh(async()=>{
	   await getNoticeDetailFn()
	   uni.stopPullDownRefresh()
	})
</script>

<style lang="scss" scoped>
	.tit {
		font-size: 32rpx;
		font-weight: 700;
		padding: 20rpx 0;
		text-align: center;
	}
	.timeDesc {
		text-align: right;
		font-size: 28rpx;
		color: #999;
		padding: 30px 0;
	}
	
	.fileList {
		padding: 0 32rpx;
		.file {
			display: flex;
			align-items: center;
			padding: 10rpx 0;
			.link {
				font-size: 24rpx;
				color: #9C9C9C;
				flex: 1;
				
			}
			.lookLink {
				width: 132rpx;
				height: 44rpx;
				background: #DE3A26;
				border-radius: 22rpx;
				font-size: 24rpx;
				color: #fff;
				text-align: center;
				line-height: 44rpx;
				margin-left: 20rpx;
				&.boder {
					border: 1px solid #DE3A26;
					color: $themC;
					background-color: #fff;
				}
			}
		}
	}
</style>