<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2024-09-05 15:35:29
 * @Description:
-->
<template>
	<el-form
		:model="dataForm"
		:rules="dataRule"
		ref="dataForm"
		@keyup.enter.native="dataFormSubmit()"
		label-position="top"
		label-width="80px">
		<el-row :gutter="20">
			<el-col :span="12">
				<el-form-item label="产线" prop="productionLineName">
					<el-input
						style="width: 100%"
						v-model="dataForm.productionLineName"
						disabled />
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="activeName==='now'">
				<el-form-item label="工段" prop="workshopSectionName">
					<el-input
						style="width: 100%"
						v-model="dataForm.workshopSectionName"
						readonly />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item :label="activeName==='his'?'上片数量':'进片数量'" prop="innum">
					<el-input-number
						:min="0"
						style="width: 90%"
						v-model="dataForm.innum"
						clearable
						placeholder="请输入数量" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item :label="activeName==='his'?'下片数量':'出片数量'" prop="outnum">
					<el-input-number
						:min="0"
						style="width: 90%"
						v-model="dataForm.outnum"
						clearable
						placeholder="请输入数量" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="良品率" prop="ratio">
					<el-input-number
						:min="0"
						style="width: 90%"
						v-model="dataForm.ratio"
						clearable
						placeholder="请输入良品率" />
					(%)
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
import basicAdd from '@/mixins/basic-add';
import { updateDeepRatioHis } from '@/api/cost/costDeepRatioHis';

export default {
	mixins: [basicAdd],
	props: {
		nameArr: {
			type: Array,
			default: () => [],
		},
	},
	data() {
		return {
			urlOptions: {
				updateURL: updateDeepRatioHis,
			},
			dataForm: {
				id: undefined,
				productionLineName: undefined,
				innum: undefined,
				outnum: undefined,
				ratio: undefined,
			},
			dataRule: {},
      activeName: 'his'
		};
	},
	methods: {
		init(val, statisticType, activeName) {
      this.activeName = activeName
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['dataForm'].resetFields();
				this.dataForm = JSON.parse(JSON.stringify(val));
				this.dataForm.statisticType = statisticType;
				this.dataForm.ratio =
					this.dataForm.ratio >= 0 ? this.dataForm.ratio * 100 : '';
			});
		},
		// 表单提交
		dataFormSubmit() {
			this.$refs['dataForm'].validate((valid) => {
				if (!valid) {
					return false;
				}
				const udata = {
					id: this.dataForm.id,
					statisticType: this.dataForm.statisticType,
					modifyInnum: this.dataForm.innum,
					modifyOutnum: this.dataForm.outnum,
					modifyRatio:
						this.dataForm.ratio >= 0 ? this.dataForm.ratio / 100 : '',
				};
				// 修改的提交
				this.urlOptions.updateURL(udata).then((response) => {
					this.$modal.msgSuccess('修改成功');
					this.visible = false;
					this.$emit('refreshDataList');
				});
			});
		},
	},
};
</script>
