<template>
	<view class="pages">
		<view class="content">
			<view class="card">
				<view class="card1" @click="goToPosition()">
					<text>位置定位</text>
					<text>></text>
				</view>
			</view>
			<view class="card">
				<view class="card1">
					<text style="margin-right: 30rpx;">联系电话</text>
					<u--input placeholder="请输入内容" border="none" v-model="stayInfo.landlinePhone"></u--input>
				</view>
			</view>
			<view class="card">
				<view class="card1">
					<text>酒店简介</text>
				</view>
				<view style="margin-top: 20rpx;">
					<span>
						<u--textarea border='none' :maxlength='300' count v-model="stayInfo.introduction"
							placeholder="请输入酒店简介" height='250'></u--textarea>
					</span>
				</view>
			</view>
			<view class="card" style="padding: 0;">
				<view>
					<u-collapse :border='false' accordion @change="change" @close="close" @open="open">
						<u-collapse-item title="环境\内饰照片(0/10)" name="Docs guide">
							<text class="collapseTitle">至少上传1张，建议上传5-10张，需展示完整内饰</text>
							<view class="upload" v-if="stayInfo.picList.length==0">
								<u-upload :fileList="stayInfo.picList" multiple :maxCount="10"
									:maxSize="10 * 1024 * 1024" @afterRead="afterRead" @delete="deletePic"
									@oversize="overSize">
									<view class="upload-one">
										<image
											src="https://i.ringzle.com/file/20240103/1d3cf8e7ad184d17a253b3b08dfd0c53.png"
											mode="aspectFill"></image>
									</view>
								</u-upload>
							</view>
							<view class="uploads" v-else>
								<u-upload :fileList="stayInfo.picList" multiple :maxCount="10"
									:maxSize="10 * 1024 * 1024" @afterRead="afterRead" @delete="deletePic"
									@oversize="overSize">
									<view class="upload-image">
										<image
											src="https://i.ringzle.com/file/20240103/1d3cf8e7ad184d17a253b3b08dfd0c53.png"
											mode="aspectFill"></image>
									</view>
								</u-upload>
							</view>
						</u-collapse-item>
						<!-- <u-collapse-item title="环境照片" name="Docs guide">
							<text class="collapseTitle">至少上传1张，建议上传5-10张，需展示完整环境</text>
							<view class="upload" v-if="fileList1.length==0">
								<u-upload :fileList="fileList1" multiple :maxCount="10" :maxSize="10 * 1024 * 1024"
									@afterRead="afterRead" @delete="deletePic" @oversize="overSize">
									<view class="upload-one">
										<image
											src="https://i.ringzle.com/file/20240103/1d3cf8e7ad184d17a253b3b08dfd0c53.png"
											mode="aspectFill">
										</image>
									</view>
								</u-upload>
							</view>
							<view class="uploads" v-else>
								<u-upload :fileList="fileList1" multiple :maxCount="10" :maxSize="10 * 1024 * 1024"
									@afterRead="afterRead" @delete="deletePic" @oversize="overSize">
									<view class="upload-image">
										<image
											src="https://i.ringzle.com/file/20240103/1d3cf8e7ad184d17a253b3b08dfd0c53.png"
											mode="aspectFill"></image>
									</view>
								</u-upload>
							</view>
						</u-collapse-item> -->
					</u-collapse>
				</view>
			</view>

		</view>
		<view class="bottom">
			<view class="btn">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				value1: '',
				fileList: [],
				fileList1: [],
				imgUrlList: [],
				fileList2: [],
				stayInfo: {
					picList: []
				}
			}
		},
		onLoad() {
			this.getStayInfo()
		},
		methods: {
			goToPosition() {
				const qwe=JSON.stringify(this.stayInfo)
				console.log(qwe,'qweqweqweqwe');
				uni.navigateTo({
					url: '/pagesMy/stayInfo/roomPosition?item=' + JSON.stringify(this.stayInfo)
				})
			},
			getStayInfo() {
				this.$api.get('/merchant/hotel/mine/getMerchantHomestayInfo/' + '1711268640588517378').then(res => {
					if (res.data.code == 0) {
						this.stayInfo = res.data.data
					} else {
						uni.showToast({
							title: res.data.msg,

						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					}
					console.log(res, 'res------');
				})
			},
			change() {

			},
			close() {

			},
			open() {

			},
			// 删除图片
			deletePic(event) {
				console.log('jinlaile1');
				this[`stayInfo.picList{event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				console.log('jinlaile2', event);
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this.stayInfo.picList.length
				lists.map((item) => {
					this.stayInfo.picList.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this.stayInfo.picList[fileListLen]
					this.stayInfo.picList.splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				console.log('jinlaile3');
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			// 	deletePic(event) {
			// 		this.fileList.splice(event.index, 1);
			// 	},
			// 	overSize(e) {
			// 		uni.$u.toast('上传图片大小不能超过10MB!');
			// 	},
			// 	// 新增图片
			// 	async afterRead(event) {
			// 		console.log('jinlaile');
			// 		// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			// 		let Lists = [].concat(event.file);
			// 		let fileListLen = this.fileList.length;
			// 		Lists.map((item) => {
			// 			this.picList.push(
			// 				item.url,
			// 			)
			// 		})

			// 		for (let i = 0; i < Lists.length; i++) {
			// 			const result = await this.uploadFilePromise(Lists[i].url);
			// 			wx.getImageInfo({
			// 				src: Lists[i].url,
			// 				success: res => {
			// 					this.imgUrlList.push(result)
			// 				}
			// 			})
			// 		}
			// 	},
			// 	//上传图片
			// 	uploadFilePromise(url) {
			// 		return new Promise((resolve, reject) => {
			// 			let a = uni.uploadFile({
			// 				url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
			// 				filePath: url,
			// 				name: 'file',
			// 				header: {
			// 					token: wx.getStorageSync('access_token')
			// 				},
			// 				success: (res) => {
			// 					let data = JSON.parse(res.data);
			// 					this.fileList.push({
			// 						url: data.data.url
			// 					})
			// 					resolve(data.data.url);
			// 				}
			// 			});
			// 		})
			// 	},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-cell__body {
		padding: 0;
	}

	::v-deep .u-cell__body {
		padding: 0;
	}

	.pages {
		height: 100vh;
		background: #F9FAFC;

		.content {
			padding: 20rpx;
			height: 100vh;

			.card {
				background: #fff;
				border-radius: 16rpx;
				padding: 30rpx 33rpx;
				margin-bottom: 20rpx;

				.upload {
					margin-top: 48rpx;
					width: 100%;
					height: 200rpx;
					border-radius: 16rpx;
					background-color: #F5F8FA;
					display: flex;
					align-items: center;
					text-align: center;

					.upload-one {
						margin: 0 245rpx;
						width: 200rpx;
						height: 200rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}

				.collapseTitle {
					font-size: 22rpx;
					color: #a5a5a5;
					margin-bottom: 20rpx;
				}

				.card1 {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

				}
			}
		}

		.bottom {
			position: absolute;
			bottom: 0;
			height: 9%;
			background: #fff;
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 0 30rpx;
			box-sizing: border-box;
			flex-direction: column;

			.btn {
				background: #33AFFC;
				color: white;
				text-align: center;
				height: 73rpx;
				line-height: 73rpx;
				align-self: center;
				border-radius: 35rpx;
				width: 80%;

			}
		}
	}
</style>