<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="450" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="90px">
			<el-form-item label="最终状态" prop="final_status">
				<el-input  v-model="form.final_status" placeholder="请输入最终状态" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSave" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	name: "finalStatusSave",
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "show",
			titleMap: {
				add: '最终状态',
			},
			visible: false,
			isSave: false,
			//表单数据
			form: {
				ids:"",
				final_status: "",
			},
			//验证规则
			rules: {
				final_status: [
					{required: true, message: '最终状态不能为空'}
				],
			},
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode='show'){
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSave = true;
					const res = await this.$API.setup.spare.partsStatus.post(this.form);
					this.isSave = false;
					if(res.code === 200){
						this.visible =  false;
						this.$emit('success', '', this.mode);
					}
				}
			})
		},
		//表单注入数据
		setData(ids) {
			this.form.ids = ids;
		}
	}
}
</script>

<style scoped>

</style>
