<template>
<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close :close-on-click-modal="false" @closed="$emit('closed')">
	<el-main>
		<el-form ref="dialogForm" :model="form" :rules="rules" label-width="120px">
			<el-form-item label="审核状态" prop="status">
				<el-select v-model="form.status" placeholder="请选择审核状态" clearable>
					<el-option :label="item.label" :value="item.value" v-for="(item, index) in [{label: '待审核', value: 0}, {label: '审核通过', value: 1}, {label: '审核不通过', value: 2}]"></el-option>
				</el-select>
			</el-form-item>
		</el-form>
	</el-main>
	<template #footer>
		<el-button type="primary" @click="onSubmit">确认提交</el-button>
	</template>
</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑',
				audit: '审核'
			},
			form: {},
			rules: {
			},
			visible: false,
			isSaveing: false,
			cache: {}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode='add'){
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		onSubmit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = await this.$API.store.lists.audit.post(this.form)

					this.isSaveing = false;
					if(res.code == 1){
						this.$emit('success', res.data)
						this.visible = false;
						this.$message.success("操作成功")
					}else{
						this.$alert(res.msg, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data){
			this.loading = true
			this.form.id = data.id
			this.form.status = data.status
		}
	}
}
</script>
