<template>
	<el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
		<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
			<el-form-item label="检测内容id" prop="inspectionDetId">
				<el-input v-model="dataForm.inspectionDetId" placeholder="检测内容id"></el-input>
			</el-form-item>
			<el-form-item label="检测内容（设备推送消息时，可能无对应id，只填这个字段）" prop="inspectionDetContent">
				<el-input v-model="dataForm.inspectionDetContent" placeholder="检测内容（设备推送消息时，可能无对应id，只填这个字段）"></el-input>
			</el-form-item>
			<el-form-item label="产线id" prop="productionId">
				<el-input v-model="dataForm.productionId" placeholder="产线id"></el-input>
			</el-form-item>
			<el-form-item label="工段id" prop="sectionId">
				<el-input v-model="dataForm.sectionId" placeholder="工段id"></el-input>
			</el-form-item>
			<el-form-item label="检测人员，可以多个" prop="checkPerson">
				<el-input v-model="dataForm.checkPerson" placeholder="检测人员，可以多个"></el-input>
			</el-form-item>
			<el-form-item label="检测时间" prop="checkTime">
				<el-input v-model="dataForm.checkTime" placeholder="检测时间"></el-input>
			</el-form-item>
			<el-form-item label="来源 1，手动（默认） 2，自动" prop="source">
				<el-input v-model="dataForm.source" placeholder="来源 1，手动（默认） 2，自动"></el-input>
			</el-form-item>
			<el-form-item label="描述" prop="explainText">
				<el-input v-model="dataForm.explainText" placeholder="描述"></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="remark">
				<el-input v-model="dataForm.remark" placeholder="备注"></el-input>
			</el-form-item>
			<el-form-item label="删除标志，是否有效:1 可用 0不可用" prop="valid">
				<el-input v-model="dataForm.valid" placeholder="删除标志，是否有效:1 可用 0不可用"></el-input>
			</el-form-item>
			<el-form-item label="创建人" prop="creatorId">
				<el-input v-model="dataForm.creatorId" placeholder="创建人"></el-input>
			</el-form-item>
			<el-form-item label="创建人姓名" prop="creatorName">
				<el-input v-model="dataForm.creatorName" placeholder="创建人姓名"></el-input>
			</el-form-item>
			<el-form-item label="创建时间" prop="createTime">
				<el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
			</el-form-item>
			<el-form-item label="更新人" prop="updaterId">
				<el-input v-model="dataForm.updaterId" placeholder="更新人"></el-input>
			</el-form-item>
			<el-form-item label="更新人姓名" prop="updaterName">
				<el-input v-model="dataForm.updaterName" placeholder="更新人姓名"></el-input>
			</el-form-item>
			<el-form-item label="更新时间" prop="updateTime">
				<el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
			</el-form-item>
			<el-form-item label="版本号" prop="version">
				<el-input v-model="dataForm.version" placeholder="版本号"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取消</el-button>
			<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
		</span>
	</el-dialog>
</template>

<script>
export default {
	data() {
		return {
			visible: false,
			dataForm: {
				id: 0,
				inspectionDetId: '',
				inspectionDetContent: '',
				productionId: '',
				sectionId: '',
				checkPerson: '',
				checkTime: '',
				source: '',
				explainText: '',
				remark: '',
				valid: '',
				creatorId: '',
				creatorName: '',
				createTime: '',
				updaterId: '',
				updaterName: '',
				updateTime: '',
				version: ''
			},
			dataRule: {
				inspectionDetId: [{ required: true, message: '检测内容id不能为空', trigger: 'blur' }],
				inspectionDetContent: [{ required: true, message: '检测内容（设备推送消息时，可能无对应id，只填这个字段）不能为空', trigger: 'blur' }],
				productionId: [{ required: true, message: '产线id不能为空', trigger: 'blur' }],
				sectionId: [{ required: true, message: '工段id不能为空', trigger: 'blur' }],
				checkPerson: [{ required: true, message: '检测人员，可以多个不能为空', trigger: 'blur' }],
				checkTime: [{ required: true, message: '检测时间不能为空', trigger: 'blur' }],
				source: [{ required: true, message: '来源 1，手动（默认） 2，自动不能为空', trigger: 'blur' }],
				explainText: [{ required: true, message: '描述不能为空', trigger: 'blur' }],
				remark: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
				valid: [{ required: true, message: '删除标志，是否有效:1 可用 0不可用不能为空', trigger: 'blur' }],
				creatorId: [{ required: true, message: '创建人不能为空', trigger: 'blur' }],
				creatorName: [{ required: true, message: '创建人姓名不能为空', trigger: 'blur' }],
				createTime: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
				updaterId: [{ required: true, message: '更新人不能为空', trigger: 'blur' }],
				updaterName: [{ required: true, message: '更新人姓名不能为空', trigger: 'blur' }],
				updateTime: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],
				version: [{ required: true, message: '版本号不能为空', trigger: 'blur' }]
			}
		}
	},
	methods: {
		init(id) {
			this.dataForm.id = id || 0
			this.visible = true
			this.$nextTick(() => {
				this.$refs['dataForm'].resetFields()
				if (this.dataForm.id) {
					this.$http({
						url: this.$http.adornUrl(`/monitoring/qualityInspectionRecord/${this.dataForm.id}`),
						method: 'get',
						params: this.$http.adornParams()
					}).then(({ data }) => {
						if (data && data.code === 0) {
							this.dataForm.inspectionDetId = data.qualityInspectionRecord.inspectionDetId
							this.dataForm.inspectionDetContent = data.qualityInspectionRecord.inspectionDetContent
							this.dataForm.productionId = data.qualityInspectionRecord.productionId
							this.dataForm.sectionId = data.qualityInspectionRecord.sectionId
							this.dataForm.checkPerson = data.qualityInspectionRecord.checkPerson
							this.dataForm.checkTime = data.qualityInspectionRecord.checkTime
							this.dataForm.source = data.qualityInspectionRecord.source
							this.dataForm.explainText = data.qualityInspectionRecord.explainText
							this.dataForm.remark = data.qualityInspectionRecord.remark
							this.dataForm.valid = data.qualityInspectionRecord.valid
							this.dataForm.creatorId = data.qualityInspectionRecord.creatorId
							this.dataForm.creatorName = data.qualityInspectionRecord.creatorName
							this.dataForm.createTime = data.qualityInspectionRecord.createTime
							this.dataForm.updaterId = data.qualityInspectionRecord.updaterId
							this.dataForm.updaterName = data.qualityInspectionRecord.updaterName
							this.dataForm.updateTime = data.qualityInspectionRecord.updateTime
							this.dataForm.version = data.qualityInspectionRecord.version
						}
					})
				}
			})
		},
		// 表单提交
		dataFormSubmit() {
			this.$refs['dataForm'].validate(valid => {
				if (valid) {
					this.$http({
						url: this.$http.adornUrl(`/monitoring/qualityInspectionRecord/${!this.dataForm.id ? '' : this.dataForm.id}`),
						method: this.dataForm.id ? 'put' : 'post',
						data: this.$http.adornData({
							id: this.dataForm.id || undefined,
							inspectionDetId: this.dataForm.inspectionDetId,
							inspectionDetContent: this.dataForm.inspectionDetContent,
							productionId: this.dataForm.productionId,
							sectionId: this.dataForm.sectionId,
							checkPerson: this.dataForm.checkPerson,
							checkTime: this.dataForm.checkTime,
							source: this.dataForm.source,
							explainText: this.dataForm.explainText,
							remark: this.dataForm.remark,
							valid: this.dataForm.valid,
							creatorId: this.dataForm.creatorId,
							creatorName: this.dataForm.creatorName,
							createTime: this.dataForm.createTime,
							updaterId: this.dataForm.updaterId,
							updaterName: this.dataForm.updaterName,
							updateTime: this.dataForm.updateTime,
							version: this.dataForm.version
						})
					}).then(({ data }) => {
						if (data && data.code === 0) {
							this.$message({
								message: '操作成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.visible = false
									this.$emit('refreshDataList')
								}
							})
						} else {
							this.$message.error(data.msg)
						}
					})
				}
			})
		}
	}
}
</script>
