<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">姓名</view>
				<input placeholder="请输入姓名" data-field="name" @input="bindInput"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">联系方式</view>
				<input placeholder="请输入联系方式" data-field="mobile" @input="bindInput"></input>
			</view>
			<view class="cu-form-group">
				<textarea maxlength="-1" @input="bindInput" data-field="content" placeholder="请输入您的意见和建议"></textarea>
			</view>
			<view class="cu-bar bg-white justify-end margin-top">
				<view class="action">
					<button class="cu-btn bg-green margin-left" @tap="subModal">确定</button>
				</view>
			</view>
		</form>
	</view>
</template>

<script>
	var _this;
	
	export default {
		data() {
			return {
				userinfo: {},
				info: {
					name: '',
					mobile: '',
					content: '',
					userid: 0,
				},
			}
		},
		onLoad: function(option) {
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/myinfo");
			_this.info.userid = _this.userinfo.id;
		},
		methods: {
			textareaAInput(e) {
				_this.info.content = e.detail.value;
			},
			bindInput: function(e) {
				_this.info[e.currentTarget.dataset.field] = e.detail.value;
			},
			subModal() {
				if (_this.info.name == '') {
					uni.showModal({
						title: '信息提示',
						content: '姓名不能为空',
						showCancel: false
					});
					return false;
				}
				if (_this.info.mobile == '') {
					uni.showModal({
						title: '信息提示',
						content: '联系方式不能为空',
						showCancel: false
					});
					return false;
				}
				if (_this.info.content == '') {
					uni.showModal({
						title: '信息提示',
						content: '反馈内容不能为空',
						showCancel: false
					});
					return false;
				}
				_this.$req.ajax({
					path: "my/feedback",
					data: _this.info,
				}).then((data) => {
					uni.navigateBack();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 30rpx);
	}
</style>
