<template>
	<view class="wrap">
		<view class="content">
			<view class="row row-bottom">
				<view class="left">姓名</view>
				<input v-model="personInfo.name" class="right-bottom" placeholder="请输入姓名"></input>
			</view>
			<view class="row row-bottom">
				<view class="left">电话</view>
				<input class="right-bottom" v-model="personInfo.mobilePhone" placeholder="请输入电话"></input>
			</view>
			<view class="row no-boder">
				<view class="left">留言</view>
			</view>
			<view class="row no-boder">
				<u-input v-model="personInfo.message" :type="type" :border="border" :height="height"
					:auto-height="autoHeight" />
			</view>
			<view class="bottom">
				<u-button type="primary" class="submit" hover-class="none" @click="submit">提交</u-button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';

	export default {
		components: {

		},
		data() {
			return {
				personInfo: {
					name: '',
					mobilePhone: '',
					message: '',
					type: 1

				},
				type: 'textarea',
				border: true,
				height: 150,
				autoHeight: true,
			}
		},

		onLoad() {

		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onShow() {
			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
				console.log("checkSession", res)
				if (res.data.data == "INVALID") {
					uni.showModal({
						title: '登录提示',
						content: '当前登入信息验证失败，是否重新登录？',
						showCancel: true,
						confirmText: '登录',
						success: (e) => {
							if (e.confirm) {
								uni.navigateTo({
									url: '/pages/public/login'
								})
							}
						},
						fail: () => {},
						complete: () => {}
					})
				}
			})
			console.log("hasLogin", this.hasLogin)
		},
		methods: {
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			calculate() {},
			submit() {
				if (!this.personInfo.name) {
					this.$refs.uToast.show({
						title: '姓名不能为空！',
						type: 'error',
					})
				}
				if (!this.personInfo.mobilePhone) {
					this.$refs.uToast.show({
						title: '电话号码不能为空！',
						type: 'error',
					})
				}
				this.$api.doRequest('post', '/openServiceInfo/api/addInfo', this.personInfo).then(res => {
					
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '提交成功，客服人员会及时与您取得联系。！',
							type: 'success',
							back: true
						})
					}
				})

			}
		}
	}
</script>
<style lang='scss' scoped>
	page {
		background: #F5F6FA;
		overflow: hidden;
	}

	.wrap {
		background: #fff;
		margin: 10px;
		border-radius: 10px;
		padding: 20rpx;
	}

	.content {
		border-radius: 20rpx;
		background: white;
		padding: 20rpx;

		.row {
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #EEEEEE;
			padding: 21rpx 0;

			.right,
			input {
				font-size: 28rpx;
				color: #333333;
			}
		}

		.row-bottom {
			.right-bottom {
				width: 300rpx;
				text-align: right;
			}
		}

		.no-boder {
			border: 0;
		}
	}

	.submit {
		margin-top: 200rpx;
		background: #22C572;
		border-radius: 10rpx;
	}
</style>
