<template>
	<view>
		<u-navbar :is-back="true" :title="title" :border-bottom="false"></u-navbar>
		<view class="u-content">
			<u-parse :html="content"
			:autosetTitle="true"
			:show-with-animation="true"
			:selectable="true"></u-parse>
		</view>
		<u-swiper :list="imgList" @change="change"></u-swiper>
		<view v-for="(item,index) in attachments" :key="index">
		  <text @click="download(item)">{{ item.fileName }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:null,
				title:'资讯',
				content: ``,
				imgList:[],
				attachments:[]
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getDetail()
		},
		methods:{
			getDetail(){
				this.$u.get(`/notice/detail?id=${this.id}`,{},{
					WT: this.$getToken()
				}).then(res=>{
					if(res.flag) {
						this.title = res.data.noticeTitle;
						this.content = res.data.noticeContent;
						if(res.data.imgs) {
							const _this = this;
							res.data.imgs.forEach(img=>{
								_this.imgList.push(_this.$config.staticUrl + img)
							})
						}
						this.attachments = res.data.attachments;
					}
				})
			},
			download(item){
				uni.downloadFile({
				  url: this.$config.staticUrl + item.url,
				  success(res) {
				    uni.openDocument({
				      filePath: res.tempFilePath
				    })
				  }
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.u-content{
		margin:0 10rpx;
		padding: 24rpx;
		font-size: 34rpx;
		color: $u-main-color;
		line-height: 1.8;
		white-space: pre-wrap !important;
	}
</style>

