<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="productionLineId">
				<el-input v-model="dataForm.productionLineId" placeholder="产线id"></el-input>
			</el-form-item>
			<el-form-item label="上一次记录时间至该条记录时间端内上片数量" prop="inputNum">
				<el-input v-model="dataForm.inputNum" placeholder="上一次记录时间至该条记录时间端内上片数量"></el-input>
			</el-form-item>
			<el-form-item label="上一次记录时间至该条记录时间端内下片数量" prop="outputNum">
				<el-input v-model="dataForm.outputNum" placeholder="上一次记录时间至该条记录时间端内下片数量"></el-input>
			</el-form-item>
			<el-form-item label="记录时间" prop="recordTime">
				<el-input v-model="dataForm.recordTime" 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="sumInputNum">
				<el-input v-model="dataForm.sumInputNum" placeholder="该记录时间点的累计上片数量"></el-input>
			</el-form-item>
			<el-form-item label="该记录时间点的累计下片数量" prop="sumOutputNum">
				<el-input v-model="dataForm.sumOutputNum" 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,
				productionLineId: '',
				inputNum: '',
				outputNum: '',
				recordTime: '',
				valid: '',
				sumInputNum: '',
				sumOutputNum: ''
			},
			dataRule: {
				productionLineId: [{ required: true, message: '产线id不能为空', trigger: 'blur' }],
				inputNum: [{ required: true, message: '上一次记录时间至该条记录时间端内上片数量不能为空', trigger: 'blur' }],
				outputNum: [{ required: true, message: '上一次记录时间至该条记录时间端内下片数量不能为空', trigger: 'blur' }],
				recordTime: [{ required: true, message: '记录时间不能为空', trigger: 'blur' }],
				valid: [{ required: true, message: '删除标志，是否有效:1 可用 0不可用不能为空', trigger: 'blur' }],
				sumInputNum: [{ required: true, message: '该记录时间点的累计上片数量不能为空', trigger: 'blur' }],
				sumOutputNum: [{ 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/productionLineRecSch/${this.dataForm.id}`),
						method: 'get',
						params: this.$http.adornParams()
					}).then(({ data }) => {
						if (data && data.code === 0) {
							this.dataForm.productionLineId = data.productionLineRecSch.productionLineId
							this.dataForm.inputNum = data.productionLineRecSch.inputNum
							this.dataForm.outputNum = data.productionLineRecSch.outputNum
							this.dataForm.recordTime = data.productionLineRecSch.recordTime
							this.dataForm.valid = data.productionLineRecSch.valid
							this.dataForm.sumInputNum = data.productionLineRecSch.sumInputNum
							this.dataForm.sumOutputNum = data.productionLineRecSch.sumOutputNum
						}
					})
				}
			})
		},
		// 表单提交
		dataFormSubmit() {
			this.$refs['dataForm'].validate(valid => {
				if (valid) {
					this.$http({
						url: this.$http.adornUrl(`/monitoring/productionLineRecSch/${!this.dataForm.id ? '' : this.dataForm.id}`),
						method: this.dataForm.id ? 'put' : 'post',
						data: this.$http.adornData({
							id: this.dataForm.id || undefined,
							productionLineId: this.dataForm.productionLineId,
							inputNum: this.dataForm.inputNum,
							outputNum: this.dataForm.outputNum,
							recordTime: this.dataForm.recordTime,
							valid: this.dataForm.valid,
							sumInputNum: this.dataForm.sumInputNum,
							sumOutputNum: this.dataForm.sumOutputNum
						})
					}).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>
