<template>
	<!-- 帮助与反馈 -->
	<view class="help">
		<navbar title="帮助与反馈" leftClick @leftClick="$utils.navigateBack" />
		<view class="help-box">
			<view>
				<view class="help-issue">
					<text>帮助与反馈</text>
					<text style="color: #BD3624;">*</text>
				</view>
				<uv-textarea v-model="form.question" :count="true" border="none" height="400"
					placeholder="请把您需要的帮助或者您发现的问题提交给我们，感谢您的参与(必填)" :text-style="{color:'#BCB7B7',fontSize:'28rpx'}" />
			</view>

			<view>
				<view class="help-issue">
					<text>问题截图</text>
					<text style="color: #BD3624;">*</text>
				</view>

				<view class="help-screenshot">
					<uv-upload :fileList="fileList" multiple :maxCount="3" width="180rpx" height="180rpx" multiple
						@afterRead="afterRead" @delete="deleteImage">
						<!-- <image src="../static/help/uploading.png" mode="aspectFill"
							style="width: 180rpx;height: 180rpx;" /> -->
					</uv-upload>
				</view>
			</view>

			<view>
				<view class="help-issue">
					<text>联系方式</text>
					<text style="color: #BD3624;">*</text>
				</view>
				<view class="form-sheet-cell">
					<view>
						联系姓名
					</view>
					<input placeholder="请输入联系姓名" v-model="form.name" />
				</view>
				<view class="form-sheet-cell">
					<view>
						联系电话
					</view>
					<input placeholder="请输入联系电话" v-model="form.phone" />
				</view>
			</view>

			<view class="b-fiexd">
				<view @click="submit" class="button-submit">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					question: '',
					phone: '',
					name: '',
					image: '',
				},
				fileList: []
			}
		},
		onLoad(args) {

		},
		methods: {
			deleteImage(e) {
				this.fileList.splice(e.index, 1)
			},
			afterRead(e) {
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList.push({
							url
						})
					})
				})
			},
			submit() {

				let data = JSON.parse(JSON.stringify(this.form))

				data.image = this.fileList.map((item) => item.url).join(",")

				if (this.$utils.verificationAll(data, {
						question: '请输入你的问题和意见', //问题和意见
						image: '请上传截图', //
						name: '请输入姓名', //
						phone: '请输入手机号码', //手机号码
					})) {
					return
				}

				this.$api('addFeedback', data, res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})

						setTimeout(uni.navigateBack, 800, -1)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.help {
		.help-box {
			width: 92%;
			margin-left: 4%;

			.help-issue {
				margin: 20rpx;
				font-size: 28rpx;
				font-weight: 600;
				color: #333333;
			}

			.help-screenshot {
				display: flex;
				align-items: center;
				background-color: #fff;
				padding: 20rpx;
			}

			.form-sheet-cell {
				display: flex;
				background-color: #fff;
				padding: 20rpx 30rpx;
				font-size: 24rpx;
				align-items: center;

				view {
					width: 150rpx;
				}
			}

			.b-fiexd {
				position: fixed;
				left: 0;
				bottom: 0;
				width: 100%;

				.button-submit {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 596rpx;
					height: 90rpx;
					background: #E3441A;
					border-radius: 46rpx;

					margin: 20rpx auto;

					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #ffffff;
				}
			}
		}
	}
</style>