<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2025-06-13 10:59:54
 * @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="activeName === 'his' ? '产线' : '工段'"
					prop="bindObjectName">
					<el-input
						style="width: 100%"
						v-model="dataForm.bindObjectName"
						disabled />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="所属日期" prop="recTime">
					<el-date-picker
						v-model="dataForm.recTime"
						type="date"
						value-format="timestamp"
						:style="{ width: '100%' }"
						disabled
						placeholder="选择所属日期"></el-date-picker>
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="activeName === 'his'">
				<el-form-item label="厚度" prop="thick">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.thick"
						clearable
						placeholder="请输入厚度" />
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="activeName === 'his'">
				<el-form-item label="在线速度" prop="speed">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.speed"
						clearable
						placeholder="请输入在线速度" />
				</el-form-item>
			</el-col>
			<el-col :span="12" v-if="activeName === 'his'">
				<el-form-item label="掰边宽度" prop="width">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.width"
						clearable
						placeholder="请输入掰边宽度" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item
					:label="activeName === 'his' ? '拉引量' : '进片数'"
					prop="inArea">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.inArea"
						clearable />
					{{ activeName === 'his' ? '(m²)' : '片' }}
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item
					:label="activeName === 'his' ? '下片面积' : '出片数'"
					prop="outArea">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.outArea"
						clearable />
					{{ activeName === 'his' ? '(m²)' : '片' }}
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="良品率" prop="ratio">
					<el-input-number
						:min="0"
						style="width: 85%"
						v-model="dataForm.ratio"
						clearable
						placeholder="请输入良品率" />
					(%)
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

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

export default {
	mixins: [basicAdd],
	props: {
		nameArr: {
			type: Array,
			default: () => [],
		},
	},
	data() {
		return {
			urlOptions: {
				updateURL: updatecostOriginRatioHis,
			},
			dataForm: {
				id: undefined,
				bindObjectName: undefined,
				thick: undefined,
				speed: undefined,
				width: undefined,
				inArea: undefined,
				outArea: undefined,
				ratio: undefined,
				recTime: 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;
				}
				let udata = {
					id: this.dataForm.id,
					statisticType: this.dataForm.statisticType,
					modifyInArea: this.dataForm.inArea,
					modifyOutArea: this.dataForm.outArea,
					modifyRatio:
						this.dataForm.ratio >= 0 ? this.dataForm.ratio / 100 : '',
				};
				if (this.activeName === 'his') {
					udata = {
						...udata,
						modifyThick: this.dataForm.thick,
						modifySpeed: this.dataForm.speed,
						modifyWidth: this.dataForm.width,
					};
				}
				// 修改的提交
				this.urlOptions.updateURL(udata).then((response) => {
					this.$modal.msgSuccess('修改成功');
					this.visible = false;
					this.$emit('refreshDataList');
				});
			});
		},
	},
};
</script>
