<template>
	<view style="padding: 30rpx;">
		<uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="80px" label-align="right" label-position="left">
			<uni-forms-item name="evaluate" label="反馈内容" required>
				<uni-easyinput v-model="formData.evaluate" type="textarea" placeholder="请输入反馈内容"></uni-easyinput>
			</uni-forms-item>
		</uni-forms>
		<button class="send-button" @tap="handleSubmit">提 交</button>
	</view>
</template>

<script setup>
import { ref, unref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { feedbackInterviewInvite } from '@/api/interview'

const formRef = ref(null)
const formData = ref({
	id: null,
	evaluate: null
})
const formRules = {
	evaluate: {
		rules: [{ required: true, errorMessage: '请输入反馈内容' }]
	}
}

onLoad(async (options) => {
	const { id } = options
	if (!id) {
		uni.showToast({
			title: 'ID缺失',
			icon: 'none'
		})
		setTimeout(() => {
			uni.navigateBack({ delta: 1 })
		}, 1000)
		return
	}

	formData.value.id = id
})

// 提交
const handleSubmit = async () => {
	const valid = await unref(formRef).validate()
	if (!valid) return

	uni.showLoading({ title: '提交中' })
	try {
		await feedbackInterviewInvite(formData.value)
		uni.hideLoading()
		uni.showToast({
			title: '提交成功',
			icon: 'success'
		})
		setTimeout(() => {
			uni.navigateBack({ delta: 1 })
		}, 1000)
	} catch {
		uni.hideLoading()
	}
}
</script>

<style scoped lang="scss">

</style>
