<template>
	<view>
		<u-navbar title="意见反馈"></u-navbar>
		<view class="main">
			<textarea name="" id="" 
			v-model="subForm.opinion" maxlength="200"
			cols="30" rows="10" placeholder="填写反馈内容（必填）"></textarea>
		
			<u-upload   ref="uUpload" 
			name="photoFile"
			  :max-size="50 * 1024 * 1024"
			:form-data="formData" :header="header" :action="action"
			:file-list="fileList" upload-text=""></u-upload>

			<input type="text" 
			 v-model="subForm.phone"
			placeholder="请留下联系方式，方便我们与您取得联系" />
		</view>

		<button  @click="submit">提交</button>
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/user.js'
	import * as WxJsApi from '@/apis/utils/wxJsApi'
	
	export default {
		data() {
			return {
				action:"",
				formData:{},
				fileList:[],
				header:{
					
				},
				subForm: {
					opinion: '',
					photoUrl: '',
					phone: ''
				}
			}
		},onLoad() {
			this.action=process.car.BASE_URL+"uploadPicture"
			
			this.formData.subFolder="feedback"
			//接口应该免登陆
			var token=this.carhelp.getToken()
			
			this.header={
		
				'Authorization':token
			}
			// //获取微信配置
			// WxJsApi.getWxConfig(['getLocation','addEventListener']).then((res)=>{
			
			// 	this.isReady=true;
			// 	//(res)
			 
			// }).catch(error => {
			// 		//(res)
			// })
		},
		methods: {
			//表单检测
			checkFrom() {
				if (!this.subForm.opinion) {
				
					uni.showToast({
						title: "请输入内容"
					})
					return false;
				} else {
					return true;
				}
			},
			
			//提交
			submit() {
				let files = [];
								// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
								files = this.$refs.uUpload.lists
								// 如果您不需要进行太多的处理，直接如下即可
								// files = this.$refs.uUpload.lists;
				
				console.log(files);
					
				var photoUrl=files.map(item=>{
					return item.response.data.fileUrl;
				})
				console.log(photoUrl);
				this.subForm.photoUrl = photoUrl.join(',');
				
			
				if (this.checkFrom()) {
					//this.subForm.picUrl = this.listPic.join(',');
					uni.showLoading({
						title: "加载中",
						mask: true,
					})
					
					API.addFeedback(this.subForm).then(response => {
						
						uni.hideLoading()
						uni.showModal({
							title: '提示',
							content: '提交成功',
							showCancel:false,
							success: res=>{
								if (res.confirm) {
									uni.navigateBack({
										
									})
								} else if (res.cancel) {
									//('用户点击取消');
								}
							}
						});
						
			
					}).catch(error => {
					
						uni.showToast({
							title: error
						})
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff;
	}

	.main {
		padding: 32rpx;

		/deep/.u-add-tips {
			margin-top: 0;
		}

		// /deep/.u-icon__icon {
		// 	font-size: 90rpx !important;
		// 	color: #b0b0b0 !important;
		// }
		.u-upload{
			margin-top: 32rpx;
		}

		uni-input {
			margin-top: 32rpx;
			height: 80rpx;
			border-bottom: 1px solid #b5b5b5;
			color: #b5b5b5;
			font-size: 14px
		}

	}
	uni-button {
		margin:80rpx 32rpx;
		border-radius: 8px;
		background-color: rgba(31, 74, 153, 1);
		color: rgba(255, 255, 255, 1);
		font-size: 16px;
		height: 88rpx;
	}
</style>
