<template>
	<view class="">
		<navbar :config="config" backColor="#333333"></navbar>

		<view class="zw-pages-content">
			<view class="select-box">
				<text>反馈主题</text>
				<view class="box-r">
					<u-input v-model="form.opinionTitle" placeholder="请填写反馈主题" />
				</view>
			</view>
			<view class="select-box">
				<text>反馈类型</text>
				<view class="box-r">
					<u-input v-model="form.opinionType" type="select" placeholder="请输入反馈类型" @click="show = true" />
					<u-action-sheet :list="actionSheetList" v-model="show"
						@click="actionSheetCallback"></u-action-sheet>
				</view>
			</view>
			<view class="upload-box">
				<u-input v-model="form.opinionContent" auto-height :height="200" maxlength="200" type="textarea"
					:clearable="false" placeholder="请填写要反馈的内容" />
					<view class="num"><text>{{form.opinionContent.length || 0}}</text> / 200</view>
				<view >
					<uploadImg closeTip imgCount="3" uploadImgCount="1" :imgArr="imgArr" :type="upimgtype" url=""
						@result="resultUrlone" @delImg="delImg"></uploadImg>
				</view>
			</view>
			<view class="select-box">
				<text>联系方式</text>
				<view class="box-r">
					<u-input v-model="form.opinionUserPhone" type="number" maxlength="11" placeholder="请输入手机号" />
				</view>
			</view>

			<view class="btn-box">
				<view class="btn" @click="confirm">确认反馈</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		forEach
	} from 'mathjs';
	import uploadImg from '../../components/uploadImg/imgUpload.vue';
	import permision from "@/utils/permission.js"
	export default {
		components: {
			uploadImg,
		},
		data() {
			return {
				config: {
					back: true,
					title: '使用反馈',
					color: 'black',
					backgroundColor: [1, '#fff'],
					statusBarFontColor: 'black',
				},
				form: {
					opinionTitle: '',
					opinionType: '',
					opinionContent: '',
					opinionUserPhone: '',
					opinionImg: ''
				},
				imgArr: [],
				show: false,
				border: true,
				upimgtype: 'other',
				actionSheetList: [],
			};
		},
		onLoad() {
			this.getTypeOptions();
		},
		methods: {
			actionSheetCallback(index) {
				this.form.opinionType = this.actionSheetList[index].text;
			},

			//获取反馈类型
			getTypeOptions() {
				this.$yghttp.get('/dict/data/type/user_opinion_type').then((res) => {
					if (res && res.code == 200) {
						let data = res.data;
						this.actionSheetList = [];
						data.forEach((e) => {
							this.actionSheetList.push({
								text: e.dictValue,
							});
						});
					}
				});
			},

			confirm() {
				if (!this.form.opinionTitle) {
					uni.showToast({
						icon: 'none',
						title: '请填写意见标题',
					});
					return;
				}
				if (!this.form.opinionType) {
					uni.showToast({
						icon: 'none',
						title: '请选择类型',
					});
					return;
				}
				if (!this.form.opinionContent) {
					uni.showToast({
						icon: 'none',
						title: '请填写反馈内容',
					});
					return;
				}
				if (this.imgArr.length > 0) {
					this.form.opinionImg = this.imgArr.join(',')
				}
				this.$yghttp.post('/user/opinion/add', this.form).then((res) => {
					if (res && res.code == 200) {
						uni.showToast({
							icon: 'none',
							title: '提交成功',
						});
						this.form = {
							opinionTitle: '',
							opinionType: '',
							opinionContent: '',
							opinionUserPhone: '',
							opinionImg: '',
						};
						this.imgArr = []
						setTimeout(() => {
							uni.navigateBack()
						}, 300)
					}
				});
			},

			//上传身份证
			resultUrlone(e) {
				console.log('e', e);
				this.imgArr = e;
			},
			delImg(e) {
				this.imgArr = e;
			},
		},
	};
</script>

<style>
	page {
		background-color: #F8F8F8;
	}
</style>
<style lang="scss" scoped>
	.zw-pages-content {
		position: relative;
		padding: 0 28rpx;

		.select-box {
			display: flex;
			align-items: center;
			padding: 20rpx 40rpx 20rpx 50rpx;
			background-color: #fff;
			margin: 22rpx 0;
			border-radius: 20rpx;

			.box-r {
				display: flex;
				align-items: center;
				flex: 1;
				margin-left: 20rpx;
			}

			&>text {
				font-size: 30rpx;
			}
		}

		.upload-box {
			display: flex;
			flex-direction: column;
			margin: 22rpx 0;
			padding: 20rpx 40rpx 20rpx 50rpx;
			background-color: #fff;
			border-radius: 20rpx;

			// .upload-img {
			// 	// display: flex;
			// 	// justify-content: space-between;
			// 	// align-items: flex-end;

			// 	.upload-img-box {
			// 		flex: 1;

			// 		::v-deep .upload-img-view {
			// 			min-width: 200rpx;
			// 		}
			// 	}
			// }

			.num {
				margin: 10rpx 0;
				margin-left: auto;
				color: #999999;
				font-size: 30rpx;

				&>text {
					color: #4FD1E5;
				}
			}
		}

		.btn-box {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			padding: 20rpx;
			padding-bottom: 50rpx;

			.btn {
				width: 534rpx;
				height: 80rpx;
				margin: 0 auto;
				line-height: 80rpx;
				text-align: center;
				font-size: 30rpx;
				background: linear-gradient(17deg, #52d5e9 0%, #45c5da 100%) #3c66d9;
				color: #fff;
				border-radius: 10rpx;
			}
		}
	}
</style>