<template>
	<div class="hui-flex hui-dialog">
		<div class="hui-flex-box hui-dialog-content">
			<el-form ref="form" :model="form" label-position="top">
				<el-form-item label="审核意见" class="hui-textarea">
					<el-input type="textarea" v-model="form.content" placeholder="请输入审核意见" maxlength="120" :rows="4"
						show-word-limit resize="none"></el-input>
				</el-form-item>
				<el-form-item label="审核附件" class="hui-textarea">
					<upload ref="upload" :list="responsibility" type="insert"></upload>
				</el-form-item>
			</el-form>
		</div>
		<div class="hui-dialog-submit">
			<el-button size="medium" @click="$emit('callback')">取 消</el-button>
			<el-button size="medium" type="primary" @click="submit" :loading="loading">确 定</el-button>
		</div>
	</div>
</template>

<script>
	import upload from '@/components/common/upload'
	import {
		userFlowAction
	} from '@/httpApi/property'
	export default {
		props: ['action', 'projectFlowId'],
		data() {
			return {
				form: {
					content: ''
				},
				responsibility: [],
				loading: false
			}
		},
		created() {},
		methods: {
			submit() {
				this.loading = true;
				userFlowAction(this.projectFlowId, this.action.id, {
					comment: JSON.stringify({
						text: this.form.content,
						enclosure: this.$refs.upload.fileList
					})
				}).then(res => {
					if (res.state) {
						this.$emit('updateFlowState', this.returnState(res.data.context.projectFlow.statusStr),
							this.action.viewName);
						this.$message.success('操作成功');
						this.$emit('callback', 'init');
					}
					this.loading = false;
				});
			},
			returnState(name) {
				let state = '';
				switch (name) {
					case '待提交':
						state = 1;
						break;
					case '审核中':
						state = 2;
						break;
					case '通过':
						state = 3;
						break;
					case '未通过':
						state = 4;
						break;
					default:
						state = 1;
						break;
				}
				return state;
			}
		},
		components: {
			upload
		}
	}
</script>

<style lang="scss"></style>