<template>
	<view class="wrap">
		<uni-forms :modelValue="formData" :label-width="50" ref="form">
			<uni-forms-item label="标题" name="taskTitle" required>
				<uni-easyinput type="text" v-model="formData.taskTitle" placeholder="请输入标题" />
			</uni-forms-item>
			<uni-forms-item label="内容" name="taskContent" required>
				<uni-easyinput 
				v-model="formData.taskContent" 
				:maxlength="-1" type="textarea" 
				autoHeight
				placeholder="请输入内容" />
			</uni-forms-item>
		</uni-forms>
		<button @click="submitForm" class="submit-bt">提交</button>
	</view>
</template>
<script>
	import {createMemory} from '@/api/user.js'
	export default {
		data() {
			return {
				rules: {
					taskTitle: {
						rules:[
							{
								required: true,
								errorMessage: '请填写标题',
							}
						],
						label:'标题',
						validateTrigger:'submit'
					},
					taskContent: {
						rules:[
							{
								required: true,
								errorMessage: '请填写内容',
							}
						],
						label:'内容',
						validateTrigger:'submit'
					}
				},
				formData:{
					taskTitle:"",
					taskContent:""
				}
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {		
			submitForm(){
				let accountId=uni.getStorageSync('accountId')
				this.$refs.form.validate().then(res => {
					createMemory({
						...res,
						accountId
					}).then((resq)=>{
						uni.showToast({
							title:"提交成功！",
							icon:"none"
						})	
						setTimeout(()=>{
							uni.switchTab({
								url:'/pages/history/history'
							})	
						},1000)
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			}
		},
		onShareAppMessage() {
			return {
			  title: '记忆',
			  path: '/pages/index/index'
			}			
		},
		onShareTimeline() {
			return {
			  title: '记忆',
			  path: '/pages/index/index'
			}			
		}
	}
</script>

<style lang="scss" scoped>
*{
	padding: 0;
	margin: 0;
}
.wrap{	
	padding:20rpx;
	.submit-bt{
		width: 240rpx;
		height: 72rpx;
		line-height: 72rpx;	
		text-align: center;							
		background:#3D90F4;
		border-radius: 36rpx;	
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		z-index: 999;
		float: right;
	}
}
</style>