<template>
	<view style="padding:0 40rpx 20rpx;box-sizing: border-box;" v-if="content != null">
		<view style="font-size: 34rpx;font-weight: bold;color: #303133;margin-top: 20rpx;">
			{{content.mainTitle}}
		</view>
		<view style="font-size: 30rpx;color:#606266;padding: 20rpx 0;" v-if="type==1">
			发件人：{{content.sendUserName}}
		</view>
		<view style="font-size: 30rpx;color:#606266;padding: 20rpx 0;" v-else>
			收件人：{{recipient}}
		</view>
		<view style="font-size: 28rpx;color:#909399;margin-bottom: 20rpx;">
			{{$u.timeFormat(content.sendTime, 'yyyy-mm-dd hh:MM:ss')}}
		</view>
		<u-divider></u-divider>
		<view>
			<u-parse :content="content.mailContent"></u-parse>
		</view>
		<view style="border-radius: 8rpx;background-color: #f3f3f3;margin-top: 40rpx;padding: 20rpx 40rpx;" v-if="content.files != null && content.files.length != 0">
			<view style="display: flex;align-items: center;margin-bottom: 20rpx;f">
				<u-icon name="file-text-fill" color="#000"></u-icon>
				附件
			</view>
			<view style="margin-bottom: 30rpx;" v-for="v in content.files" :key="v.fileId">
				<u--text :lines="1" size="15" color="#2979FF" decoration="underline" :text="v.name" @click="downLoad(v.path)"></u--text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content:null,
				type:null,
				recipient:null,
				list1:[],
				list2:[]
			}
		},
		onLoad(options){
			this.type = options.type
			this.getEmailInfo(options.id)
			if(options.type==2){
				this.getRecipient(options.id)
			}
		},
		methods: {
			//查询邮件信息
			getEmailInfo(id){
				uni.$u.http.get('/oa/mail/detail/'+id).then(res=>{
					// console.log(res)
					this.content = res.data
				})
			},
			//获取收件人
			getRecipient(id){
				uni.$u.http.get('/oa/mail/select/users/'+id).then(res=>{
					// console.log(res)
					this.recipient = res.join('、')
				})
			},
			//下载附件
			downLoad(v){
				let that = this
				uni.showLoading({
					title:"打开中...",
				})
				if(that.list1.indexOf(v) == -1){
					uni.downloadFile({
					  url:getApp().globalData.saveUrl+ v,
					  success: function(res) {
					    if (res.statusCode === 200) {
							that.list1.push(v)
							that.list2.push(res.tempFilePath)
					      uni.openDocument({
					        filePath: res.tempFilePath,
							success: function (res) {
								uni.hideLoading();
							}
					      });
					    }else{
							uni.hideLoading()
							uni.showToast({
								title:"下载失败",
								icon:'none'
							})
						}
					  },fail:function(){
						  uni.hideLoading()
						  uni.showToast({
						  	title:"下载失败",
							icon:'none'
						  })
					  }
					});
				}else{
					uni.openDocument({
					  filePath: that.list2[that.list1.indexOf(v)],
					  success: function (res) {
					  	uni.hideLoading();
					  }
					});
				}
				
			}
		}
	}
</script>

<style>

</style>
