<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2024-09-02 15:54:20
 * @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="bindObjectName">
					<el-input
						v-model="dataForm.bindObjectName"
						disabled
						placeholder="产线" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="上片数量" prop="inCount">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.inCount"
						clearable
						placeholder="请输入上片数量" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="下片数量" prop="outCount">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.outCount"
						clearable
						placeholder="请输入下片数量" />
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="良品率" prop="ratio">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.ratio"
						clearable
						placeholder="请输入良品率" />
            (%)
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="深加工成本" prop="costSum">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.costSum"
						clearable
						placeholder="请输入深加工成本" />
					(元)
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="单片成本" prop="costPiece">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.costPiece"
						clearable
						placeholder="请输入单片成本" />
					(元)
				</el-form-item>
			</el-col>
			<el-col :span="12">
				<el-form-item label="每平米成本" prop="costArea">
					<el-input-number
						:min="0"
						style="width: 80%"
						v-model="dataForm.costArea"
						clearable
						placeholder="请输入每平米成本" />
					(元)
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

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

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
				updateURL: updateDeepCostStatistics,
			},
			dataForm: {
				id: undefined,
				bindObjectName: undefined,
				inCount: undefined,
				ratio: undefined,
				costPiece: undefined,
				costArea: undefined,
				costSum: undefined,
				outCount: undefined,
			},
			dataRule: {
				costSum: [
					{ required: true, message: '深加工成本不能为空', trigger: 'blur' },
				],
			},
		};
	},
	methods: {
		init(val, statisticType) {
			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 data = {
					id: this.dataForm.id,
          statisticType: this.dataForm.statisticType,
					bindObjectName: this.dataForm.bindObjectName,
					modifyInCount: this.dataForm.inCount,
					modifyRatio:
						this.dataForm.ratio >= 0 ? this.dataForm.ratio / 100 : '',
					modifyCostPiece: this.dataForm.costPiece,
					modifyCostArea: this.dataForm.costArea,
					modifyCostSum: this.dataForm.costSum,
					modifyOutCount: this.dataForm.outCount,
				};
				// 修改的提交
				this.urlOptions.updateURL(data).then((response) => {
					this.$modal.msgSuccess('修改成功');
					this.visible = false;
					this.$emit('refreshDataList');
				});
			});
		},
	},
};
</script>
