<template>
	<c-modal
		@confirm="handleConfirm"
		@cancel="handleClose"
		:show="isShow"
		title="审批信息"
	>
		<view class="w-100">
			<u--form
				labelPosition="top"
				:model="fmData"
				:rules="rules"
				ref="uForm"
			>
				<u-form-item prop="agree">
					<uni-data-select
						v-model="fmData.agree"
						:localdata="sionList"
						placeholder="请选择审批结论"
					></uni-data-select>
				</u-form-item>

				<u-form-item>
					<c-textarea
						v-model="fmData.message"
						placeholder="请输入内容"
						maxlength="1000"
					></c-textarea>
				</u-form-item>
			</u--form>
		</view>
	</c-modal>
</template>

<script>
import { audited } from '@/api/approval/index.js';
export default {
	name: 'approvalFm',
	props: {
		isShow: Boolean,
		rId: Number,
	},
	data() {
		return {
			fmData: {
				agree: '',
				message: '',
			},
			rules: {
				agree: {
					type: 'string',
					required: true,
					message: '请选择审批结论',
					trigger: ['change'],
				},
			},
			sionList: [
				{ value: '1', text: '通过' },
				{ value: '0', text: '驳回' },
			],
		};
	},
	methods: {
		async handleConfirm() {
			try {
				uni.$c.loading();
				await this.$refs.uForm.validate();
				await audited({ id: this.rId, ...this.fmData });
				uni.hideLoading();
				uni.$c.toast({
					title: '审批成功',
					icon: 'success',
				});
				this.handleClose();
				this.$emit('reload');
			} catch (e) {
				uni.hideLoading();
				throw new Error(e);
			}
		},
		handleClose() {
			this.$refs.uForm.resetFields();
			this.fmData.agree = '';
			this.fmData.message = '';
			this.$emit('update:isShow', false);
		},
	},
};
</script>

<style scoped></style>
