<template>
	<view class="content">
		<view class="area">
			<u-textarea v-model="detail" placeholder="请输入您要反馈的内容" count height="300" maxlength="200"
				border="none"></u-textarea>
		</view>
		<view class="upload hflex acenter fwrap">
			<view class="imgs" v-for="(item,index) in imglist" :key="index">
				<image :src="item" mode="aspectFill"></image>
			</view>
			<view class="upload-bg hflex acenter jcenter" @click="uploadImg">
				<image src="static/upload-img.png" mode="aspectFill"></image>
			</view>
			<text>添加图片（选填）</text>
		</view>
		<view class="btn" :class="detail ? 'btn-sure' : ''" @click="sumbit">提交反馈</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				detail: '',
				imglist: []
			}
		},
		onLoad() {
			that = this
		},
		onShow() {

		},
		onPullDownRefresh() {

		},
		onReachBottom() {

		},
		methods: {
			uploadImg() {
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						uni.showLoading({
							title: '上传中...'
						})
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: $api.config.baseUrl + 'upload/image', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'image',
							success: (uploadFileRes) => {

								let res = JSON.parse(uploadFileRes.data)
								this.imglist.push(res.data.url)
								uni.hideLoading()
							}
						});
					}
				});
			},
			sumbit() {
				$api.req({
					url: 'feedback',
					method: 'POST',
					data: {
						content: that.detail,
						images: that.imglist
					}
				}, function(res) {
					$api.info(res.msg)
					uni.switchTab({
						url: '/pages/mine/index'
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.content::v-deep {
		background: #FFFFFF;
		border-top: 1px solid #f5f5f5;
		padding: 0 28rpx;

		.btn-sure {
			opacity: 1 !important;
		}

		.btn {
			width: 702rpx;
			height: 88rpx;
			background: #00B0B0;
			border-radius: 44rpx;
			opacity: 0.3;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 88rpx;
		}

		.upload {
			padding: 46rpx 0 86rpx;

			.imgs {
				image {
					width: 112rpx;
					height: 112rpx;
					margin: 0 16rpx 16rpx 0;
				}
			}

			.upload-bg {
				width: 112rpx;
				height: 112rpx;
				background: rgba(231, 231, 231, .6);
				border-radius: 12rpx;

				image {
					width: 64rpx;
					height: 64rpx;
				}
			}

			text {
				font-size: 24rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: rgba(51, 51, 51, .6);
				padding: 0 0 0 32rpx;
			}
		}

		.area {
			padding: 44rpx 0 28rpx;
			width: 100%;
			box-sizing: border-box;
			border-bottom: 1px solid rgba(151, 151, 151, .1);

			.u-textarea {
				padding: 0;
			}
		}
	}
</style>