<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="实际生产数">
								<el-input-number
									v-model="form.count_real"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="合格数量">
								<el-input-number
									v-model="form.count_ok"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="不合格数量">
								<el-input-number
									v-model="form.count_notok"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="划伤">
								<el-input-number
									v-model="form.count_n_hs"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="气泡">
								<el-input-number
									v-model="form.count_n_qp"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="水纹">
								<el-input-number
									v-model="form.count_n_swen"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="崩边">
								<el-input-number
									v-model="form.count_n_bb"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="雾面">
								<el-input-number
									v-model="form.count_n_wm"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="麻点">
								<el-input-number
									v-model="form.count_n_md"
									:min="0"
									class="width-100"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="线痕">
								<el-input-number
									v-model="form.count_n_xh"
									:min="0"
									class="width-100"
									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"],
	data() {
		return {
			loading: false,
			//表单数据
			form: {},
			//验证规则
			rules: {
				batch: [
					{
						required: true,
						message: "请填写批次号",
						trigger: "blur",
					},
				],
				count_use: [
					{
						required: true,
						message: "请填写领用数量",
						trigger: "blur",
					},
				],
			},
			options: [],
			materialOptions: [],
			visible: false,
			isSaveing: false,
			batchDisabled: false,
		};
	},
	mounted() {
		if (this.form.batch != null) {
			this.batchDisabled = true;
		}
	},
	methods: {
		open(data) {
			this.visible = true;
			Object.assign(this.form, data);
			console.log(this.form);
		},

		//表单提交方法
		submit() {
			let that = this;
			that.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					that.isSaveing = true;
					that.form.mlog = that.mlog;
					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>
