<template>
	<el-dialog v-model="visible" :title="title" width="1500px" draggable :close-on-click-modal="false" @close="close">
		<LossForm ref="lossForm" @refreshDataList="handleRefresh" />
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
				<el-button v-if="method !== 'view'" type="primary" icon="el-icon-circle-check" v-noMoreClick
					@click="submit">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script>
import LossForm from "./LossForm";

export default {
	components: {
		LossForm,
	},
	data() {
		return {
			visible: false,
			method: "view",
			title: "",
		};
	},
	methods: {
		init(method, id) {
			this.method = method;
			this.title =
				method === "edit" ? "修改报损申请" : method === "view" ? "查看报损申请" : "新建报损申请";
			this.visible = true;
			this.$nextTick(() => {
				this.$refs.lossForm.init(method, id);
			});
		},
		submit() {
			this.$refs.lossForm.doSubmit();
		},
		handleRefresh() {
			this.visible = false;
			this.$emit("refreshList");
		},
		close() {
			this.visible = false;
			if (this.$refs.lossForm) {
				this.$refs.lossForm.close();
			}
		},
	},
};
</script>
