<template>
	<view class="container qualifications" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0' }">
		<view class="remarks-content-club" @click="handleClickClunInfo">
			<view class="content-club-le">
				<view class="club-le-text">
					<text class="label">机构名称：</text> <text class="text">{{ clubInfo.name }}</text>
				</view>
				<view class="club-le-text">
					<text class="label">联系人：</text> <text class="text">{{ clubInfo.linkMan }}</text>
					<text class="label phone">手机号：</text> <text class="text">{{ clubInfo.contractMobile }}</text>
				</view>
				<view class="club-le-text">
					<text class="label">地址：</text>
					<text class="text" v-if="clubInfo.provincialAddress">{{ clubInfo.provincialAddress }}{{ clubInfo.address }}</text>
				</view>
			</view>
			<view class="content-club-ri"> <text class="iconfont icon-xiayibu"></text> </view>
		</view>
		<view class="remarks-content clearfix">
			<view class="list-view-title"> <view class="list-view-h1">咨询人：{{ remarksParams.questionMan }}</view> </view>
			<view class="list-view-title"> <view class="list-view-h1">咨询类别：</view> </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="downloadFile(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,
			clubUserId: 0,
			clubInfo: {},
			userInfo: {}
		}
	},
	onLoad(option) {
		console.log(option)
		this.remarksId = option.remarksId
		this.getUserClubRemarksDetail()
	},
	methods: {
		...mapMutations(['login']),
		getUserClubRemarksDetail() {
			//资料详情
			this.UserService.getUserClubRemarksDetail({
				remarksId: this.remarksId
			})
				.then(response => {
					this.remarksParams = response.data
					this.clubUserId = response.data.userId
					this.getCulbInfo()
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		getCulbInfo() {
			// 查询机构信息
			this.UserService.OrganizationUpdateModifyInfo({ userId: this.clubUserId })
				.then(response => {
					this.clubInfo = response.data.club
					this.userInfo = response.data.user
				})
				.catch(error => {
					console.log('=============>', error.msg)
				})
		},
		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
					// 打开文件
					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()
				}
			})
		},
		downloadFile(file) {
			let self = this
			// 下载文件
			wx.downloadFile({
			    url: file.fileUrl,
			    success (res) {
					console.log('保存文件路勁============>',res.tempFilePath)
			        wx.saveFile({
			            tempFilePath: res.tempFilePath,
			            success (res) {
							self.$util.msg('下载成功', 2000)
							setTimeout(()=>{
								self.openDocument(file)
							},2000)
			            },
			            fail(error){
			                self.$util.msg('下载失败', 2000)
			            }
			        })
			    }
			})
		},
		handleClickClunInfo() {
			//修改机构资料
			if (this.userInfo.userIdentity === 2) {
				this.$api.navigateTo(`/pages/seller/login/apply?userID=${this.userInfo.userId}`)
			} else if (this.userInfo.userIdentity === 4) {
				this.$api.navigateTo(`/pages/seller/login/information?userID=${this.userInfo.userId}`)
			}
		}
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto;
	background: #ffffff;
}
.remarks-content-club {
	width: 100%;
	height: 252rpx;
	padding: 24rpx;
	box-sizing: border-box;
	border-bottom: 20rpx solid #f7f7f7;
	.content-club-le {
		width: 660rpx;
		float: left;
		.club-le-text {
			width: 100%;
			height: 60rpx;
			line-height: 60rpx;
			font-size: $font-size-28;
			color: #333333;
			.label {
				color: #999999;
				&.phone {
					margin-left: 48rpx;
				}
			}
		}
	}
	.content-club-ri {
		width: 40rpx;
		height: 160rpx;
		float: right;
		line-height: 160rpx;
		text-align: center;
		color: #b2b2b2;
	}
}
.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;
				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>
