<template>
	<view class="content">
		<view class="main">
			<!-- 建议 -->
			<view class="firstView">
				<view class="title">您的问题或建议</view>
				<view>
					<textarea placeholder-style="color:#999999" placeholder="输入个人意见反馈" v-model="exeContent"
						class="textareaCont" maxlength="-1" auto-height="true" @confirm="feedDone" />
				</view>
			</view>

			<!-- 图片 -->
			<view class="secondView">
				<view class="title">上传图片</view>
				<view class="imgBox">
					<view class="imgLine" v-for="(img,imgindex) in imgArr">
						<image :class="{img4:(imgindex+1)%4==0}" :src="img" mode="" class="itemImg"></image>
						<image src="../../static/img/icon_del_red.png" mode="" class="delImg"
							@click="delimg(imgindex)"></image>
					</view>
					<view class="imgLine" @click="uploadImg">
						<image src="../../static/img/btn_pic.png" mode="" class="itemImg"></image>
					</view>
				</view>
			</view>


		</view>

		<view class="bottom">
			<view class="shoreDz" @click="submit">提交</view>
		</view>
	</view>
</template>

<script>
	import nodata from '@/components/nodata/nodata.vue'
	export default {
		components: {
			nodata
		},
		data() {
			return {
				imgArr: [],
				exeContent: '',
				
			}
		},
		
		methods: {
			feedDone(e) {
				this.exeContent = e.target.value
				
			},
			uploadImg() {

				var that = this;
				var length=this.imgArr.length;
				var num=9;
				if(length>8){
					uni.showToast({
						title: '最多上传9张',
						icon: 'none',
						duration: 2000,
					});
					return false;
				}
				uni.chooseImage({
					sourceType: ['album','camera'],
					count:num-length, 
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						/* uni.uploadFile({
				            url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例,非真实的接口地址
				            filePath: tempFilePaths[0],
				            name: 'file',
				            formData: {
				                'user': 'test'
				            },
				            success: (uploadFileRes) => {
				                console.log(JSON.parse(uploadFileRes.data).data );
								that.imgArr=that.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
								
				            }
				        }); */
						tempFilePaths.forEach(v => {
							console.log(that.$request.baseUrl + 'tuhuUploadFile');
							uni.uploadFile({
								url: that.$request.baseUrl + 'tuhuUploadFile',
								filePath: v,
								name: 'file',
								formData: {
									'user': 'test'
								},
								
								success: (uploadFileRes) => {

									console.log(JSON.parse(uploadFileRes.data).data);
									that.imgArr = that.imgArr.concat(JSON.parse(
										uploadFileRes.data).data);
								}
							});
						})
						/* that.$http('accompany/SuperCheckSheet/uploadFile', tempFilePaths[0], 'POST').then(res => {
							
						}) */
					}
				});
			},
			delimg(index) {
				this.imgArr.splice(index, 1)
			},
			submit() {
				if (!this.exeContent) {
					uni.showToast({
						title: '请输入个人意见反馈',
						icon: 'none',
						duration: 2000,
					});
					return ;
				}
				// if (this.imgArr.length == 0) {
				// 	uni.showToast({
				// 		title: '请上传图片',
				// 		icon: 'none',
				// 		duration: 2000,
				// 	});
				// 	return ;
				// }
				uni.showLoading({});
				var exeImg = this.imgArr.join(',')
				this.$http('worldKeepCar/keepCarMy/addTMemberSuggest', {
					
					contents: this.exeContent,
					img: exeImg
				}, 'POST').then(res => {
					//this.submitSuperCheckSheet()
					if(res.code==0){
						uni.showToast({
							title: '提交成功',
							icon: 'none',
							duration: 2000,
						});
						setTimeout(function() {
							uni.navigateBack({
								
							})
						}, 2000); 	
					}else{
						uni.showToast({
							title: '提交失败',
							icon: 'none',
							duration: 2000,
						});
					}
					
					

				})
			}

		}
	}
</script>

<style scoped>
	.content {
		background: #F4F5F7;
		min-height: 100vh;

	}

	/* #ifdef H5 */
	.content {
		background: #F4F5F7;
		min-height: calc(100vh - 44px);

	}

	/* #endif */
	.main {
		background: #F4F5F7;
		padding: 20rpx 24rpx;
	}

	.firstView,
	.secondView {
		background-color: #FFFFFF;
		border-radius: 10rpx;
	}

	.firstView {
		margin-bottom: 20rpx;
	}

	.title {
		font-size: 30rpx;
		color: #3C3C3C;
		padding: 20rpx;
	}

	.textareaCont {
		padding: 20rpx;
		min-height: 150rpx;
		width: 95%;
	}


	.imgBox {
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx;

	}
	.imgLine{
		position: relative;
		margin-right: 10rpx;
	}
	.itemImg {
		width: 150rpx;
		height: 150rpx;
		margin-right: 5rpx;
	}

	/* .img4 {
		margin-right: 20rpx;
		
	} */

	.delImg {
		width: 32rpx;
		height: 32rpx;
		position: absolute;
		right: 0rpx;
		top: 0rpx;
	}


	.bottom {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0px -4px 8px 0px rgba(153, 153, 153, 0.08);
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-around;
	}

	.shoreDz {
		width: 702rpx;
		height: 74rpx;
		background: linear-gradient(124deg, #FF8700 0%, #FF4F00 100%);
		border-radius: 37rpx;
		text-align: center;
		line-height: 74rpx;
		color: #FFFFFF;
		font-size: 30rpx;
		margin-top: 24rpx;
	}
</style>