<template>
	<div>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">问题反馈</h1>
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		</header>

		<div class="mui-content vongi-meform">
			<div class="mui-h5">问题和意见</div>
			<div class="mui-input-row">
				<textarea v-model="subForm.content" rows="5" placeholder="请详细描述您的问题和意见"></textarea>
			</div>
			<div class="vongi-wordcard vongi-meform-pho">
				<h5>上传图片<span class="mui-h6">（选填,提供问题截图）</span></h5>
				<div class="fyy-upphoto">
					<div v-for="(item,index) in listPic" class="mui-col-xs-3">
						<img :src="item" />
					</div>
					<div class="mui-col-xs-3" @click="chooseImage">
						<a><span class="mui-icon mui-icon-camera"></span></a>
					</div>
				</div>
			</div>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>联系方式</label>
					<input type="text" v-model="subForm.telephone" class="mui-input-clear" placeholder="选填，方便我们联系您" />
				</div>
			</form>
			<div class="vongi-btn vongi-login-btn">
				<button class="mui-btn mui-btn-primary" @click="submit">提 交</button>
			</div>
		</div>
	</div>
</template>

<script>
	import * as API_Mine from '@/apis/Master/mine'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import NavMenu from '@/components/NavMenu.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	import * as WxJsApi from '$project/utils/wxJsApi'
	export default {
		name: 'MasterMineFeedback',
		components: {
			Common,
			Loading,
			TopHeader,
			NavMenu
		},
		data() {
			return {
				pageTitle: '消息',

				isLoading: false,

				lastNotice: {},

				imgBase64: '',
				listPic: [],
				subForm: {
					content: '',
					picUrl: '',
					telephone: ''
				}
			}
		},
		created() {

		},
		methods: {
			//微信选择图片
			chooseImage() {
				WxJsApi.chooseImage().then(res => {
					var localData = res.localData;

					if (localData.indexOf('data:image') != 0) {
						//判断是否有这样的头部
						localData = 'data:image/jpeg;base64,' + localData
					}
					localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
					this.imgBase64 = localData;
					this.uploadpic();
				}).catch(error => {
					mui.toast(error);
				})
			},
			//上传图片
			uploadpic() {
				this.isLoading = true;
				WxJsApi.uploadPic(this.imgBase64).then(response => {
					this.isLoading = false;

					this.listPic.push(response);
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//表单检测
			checkFrom() {
				if (!this.subForm.content) {
					mui.toast('请输入内容');
					return false;
				} else {
					return true;
				}
			},
			//提交
			submit() {
				if (this.checkFrom()) {
					this.subForm.picUrl = this.listPic.join(',');
					this.isLoading = true;
					API_Mine.problemFeedback(this.subForm).then(response => {
						this.isLoading = false;

						mui.toast('提交成功');
						this.$router.go(-1);

					}).catch(error => {
						this.isLoading = false;
						mui.toast(error);
					})
				}
			},
			asynCallBack() {},
		},
		mounted() {
			//获取微信配置
			WxJsApi.getWxConfig();
		},
		destroyed() {

		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style>
</style>
