<template>
	<view class="container qualifications" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0' }">
		<view class="remarks-content">
			<view class="list-view-title">
				<view class="list-view-h1">咨询人</view>
			</view>
			<view class="remarks-input">啊啊啊</view>
			<view class="list-view-title"> <view class="list-view-h1">文字备注</view> </view>
			<view class="tui-remarks-content">
				<text class="tui-remarks-span" v-for="(label, labelIndex) in remarksParams.remarks" :key="labelIndex">
					{{ label }}
				</text>
			</view>
			<view class="list-view-title" v-if="remarksParams.imageList.length>0"> <view class="list-view-h1">图片</view> </view>
			<view class="list-view-upload clearfix" v-if="remarksParams.imageList.length>0">
				<view class="photo-item" v-for="(image, imageIndex) in remarksParams.imageList" :key="imageIndex">
					<image
						:src="image"
						mode="aspectFill"
						@click.stop="previewImg(remarksParams.imageList, imageIndex)"
					></image>
				</view>
			</view>
			<view class="list-view-title" v-if="remarksParams.fileList.length>0"> <view class="list-view-h1">文件</view> </view>
			<view class="list-view" v-for="(file, fileIndex) in remarksParams.fileList" :key="fileIndex" v-if="remarksParams.fileList.length>0">
				<view class="list-view-text">
					<view class="input">{{ file.fileName }}</view>
					<view class="delbtn" @click.stop="previewFile(file)">预览</view>
					<!-- <view class="delbtn down" @click.stop="previewFile(file)">下载</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import authorize from '@/common/config/authorize.js'
import { uploadFileImage, uploadFilePdfDocDocx } from '@/services/public.js'

var isPreviewImg
export default {
	data() {
		return {
			isIphoneX: this.$store.state.isIphoneX,
			productActions: [],
			remarksParams: {},
			remarksId:0
		}
	},
	onLoad(option) {
		console.log(option)
		this.remarksId = option.remarksId
		this.getUserRemarksVisitDetail()
	},
	methods: {
		...mapMutations(['login']),
		getUserRemarksVisitDetail() {
			//资料详情
			this.UserService.getUserRemarksVisitDetail({
				remarksId: this.remarksId
			})
				.then(response => {
					this.remarksParams = response.data
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		previewImg(image, index) {
			//顶部商品图片预览
			isPreviewImg = true
			let previewUrls = image
			uni.previewImage({
				current: index, //图片索引
				urls: previewUrls, //必须是http图片，本地图片无效
				longPressActions: ''
			})
		},
		previewFile(file){//预览文件
			this.openDocument(file)
		},
		openDocument(file) {// 打开文档
		    uni.showLoading({
		        title:'加载中'
		    })
		    // 获取文件后缀
		    const index = file.fileName.lastIndexOf('.')
		    const suffix = file.fileName.substring(index + 1)
		    // 下载文件
		    uni.downloadFile({
		        url: file.fileUrl,
		        success(res) {
		            const filePath = res.tempFilePath
		            console.log(filePath) 
		            // 打开文件
		            uni.openDocument({
		                filePath: filePath,
		                fileType: suffix,
		                success(res) {
		                    uni.showToast({
		                        icon:'success',
		                        title:'打开成功',
		                        duration: 1200
		                    })
		                    uni.hideLoading()
		                },
		                fail(err) {
		                    if(err.errMsg.indexOf('fail filetype not supported')){
		                        uni.showModal({
		                            content: '不支持的文件预览',
		                            cancelColor: '#666',
		                            confirmColor: '#E15616'
		                        })
		                    }
		                    uni.hideLoading()
		                }
		            })
		        },
		        fail(err){
		            uni.showToast({
		                title: JSON.stringify(err),
		                icon:'none',
		                duration: 5000
		            })
		            uni.hideLoading()
		        },
		    })
		},
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto;
	background: #ffffff;
}
.remarks-content {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 0 24rpx;
	padding-bottom: 80rpx;
	.list-view-title {
		width: 100%;
		height: auto;
		margin-bottom: 16rpx;
		margin-top: 40rpx;
		.list-view-h1 {
			line-height: 40rpx;
			font-size: $font-size-28;
			color: #333333;
			text-align: left;
		}
	}
	.tui-remarks-content {
		width: 100%;
		height: auto;
		margin-bottom: 24rpx;
		.tui-remarks-span{
			height: 48rpx;
			line-height: 48rpx;
			text-align: center;
			padding: 0 20rpx;
			background-color: #FEF6F3;
			font-size: $font-size-26;
			color: #E15616;
			border-radius: 25rpx;
			display: inline-block;
			margin-right:24rpx;
			margin-bottom: 24rpx;
			&:nth-child(4n){
				margin-right: none;
			}
		}
	}
	.list-view {
		width: 100%;
		height: auto;
		margin-top: 20rpx;
		.list-view-text {
			width: 100%;
			float: left;
			.input {
				width: 500rpx;
				height: 50rpx;
				box-sizing: border-box;
				line-height: 50rpx;
				color: #333333;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				line-clamp: 1;
				-webkit-box-orient: vertical;
				float: left;
				font-size: 26rpx;
			}
			.delbtn{
				width: 96rpx;
				height: 44rpx;
				border-radius: 8rpx;
				font-size: $font-size-24;
				color: #e15616;
				line-height: 44rpx;
				text-align: center;
				float: left;
				&.down{
					color: #1890F9;
				}
			}
		}
	}
	.list-view-upload {
		width: 100%;
		height: auto;
		.photo-item {
			display: inline-block;
			width: 112rpx;
			height: 112rpx;
			margin: 10rpx 0;
			margin-right: 25rpx;
			border-radius: 10rpx;
			border: 1px solid #f5f5f5;
			position: relative;
			float: left;
			image {
				width: 112rpx;
				height: 112rpx;
				border-radius: 10rpx;
			}
		}
		.photo-list {
			width: 100%;
			height: 116rpx;
			overflow: hidden;
			white-space: nowrap;
			display: flex;
			align-items: flex-start;
		}
	}
}
</style>
