<template>
	<el-dialog
		title="过程检验"
		v-model="visible"
		:size="1000"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-container v-loading="loading">
			<el-main style="padding: 0 20px 20px 20px">
				<el-form
					ref="dialogForm"
					:model="form"
					:rules="rules"
					label-position="right"
					label-width="100px"
					style="padding: 0 10px"
				>
					<el-row>
						<el-col :md="12" :sm="24">
							<el-form-item label="批次号" prop="batch">
								<el-input
									v-model="form.batch"
									:disabled="batchDisabled"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="生产数" prop="count_real">
								<el-input-number
									v-model="form.count_real"
									:min="0"
									class="width-100"
									@change="countChanges"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</el-main>
			<el-footer>
				<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
				<el-button @click="visible = false">取消</el-button>
			</el-footer>
		</el-container>
	</el-dialog>
</template>

<script>
export default {
	emits: ["success", "closed"],
	props: {
	    material: {
			type: String,
			default: "",
		},
	},
	data() {
		return {
			loading: false,
			//表单数据
			form: {
				batch: null,
				count_real: 0,
				count_ok: 0,
			},
			//验证规则
			rules: {
				batch: [
					{
						required: true,
						message: "请填写批次号",
						trigger: "blur",
					},
				],
				count_real: [
					{
						required: true,
						message: "请填写生产数量",
						trigger: "blur",
					},
				],
			},
			visible: false,
			isSaveing: false,
			batchDisabled: false,
		};
	},
	mounted() {
	},
	methods: {
		open(data) {
			this.visible = true;
			Object.assign(this.form, data);
		},
		countChanges(){
			this.form.count_ok = this.form.count_real;
		},
		//表单提交方法
		submit() {
			let that = this;
			that.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					that.isSaveing = true;
					that.form.mlog = that.mlog;
					that.form.count_ok = that.form.count_real;
					that.$API.wpm.mlogb.updateOut.req(that.form.id, that.form).then((res) => {
						that.isSaveing = false;
						that.$emit("success");
						that.visible = false;
						that.$message.success("操作成功");
					}).catch((err) => {
						that.isSaveing = false;
					});
				}
			});
		},
	},
};
</script>

<style scoped>
.width-100 {
	width: 100%;
}
</style>
