<template>
	<view class="evaluate">
		<u--form labelPosition="left" :model="form" :rules="rules" ref="form">
			<u-form-item label="评价" prop="evaluateDes">
				<u--textarea v-model="form.evaluateDes" placeholder="请输入评价内容" height="100" count :maxlength="200">
				</u--textarea>
			</u-form-item>
			<u-form-item>
				<u-button type="primary" text="评价" @click="submitForm" :loading="loading" />
			</u-form-item>
		</u--form>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				form: {
					evaluateDes: '',
					deviceExcptionId: ''
				},
				rules: {
					evaluateDes: {
						type: 'string',
						required: true,
						message: '请填写评价内容',
						trigger: ['blur', 'change']
					},
				}
			}
		},
		onLoad(page) {
			this.form.deviceExcptionId = page.id
		},
		methods: {
			submitForm() {
				this.$refs.form.validate().then(res => {
					this.loading = true
					uni.$u.api.deviceAbnormalApi.addDeviceAbnormalRecordsEvaluateApi(this.form).then(res => {
						if (res.code === 200) {
							this.$refs.uToast.show({
								loading: true,
								message: '添加评论成功!',
								type: 'success',
								complete() {
									this.loading = false
									uni.$u.route({
										type: 'back'
									})
								}
							});
						} else {
							this.$refs.uToast.show({
								message: '添加评论失败!',
								type: 'error'
							});
						}
					})
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.evaluate {
		padding: 15px;
	}
</style>
