<template>
|
<wd-form ref="form" :model="model" class="relative form_box">
|
<wd-cell-group :border="true">
|
<wd-input
|
v-model="model.actuallyLength"
|
label="生产长度(m)"
|
label-width="100px"
|
prop="actuallyLength"
|
clearable
|
placeholder="请输入生产长度"
|
type="digit"
|
>
|
<template #label>
|
<span style="color: #f56c6c">生产长度(m)</span>
|
</template>
|
</wd-input>
|
<wd-input
|
v-model="model.tare"
|
label="盘具皮重(kg)"
|
label-width="100px"
|
prop="tare"
|
:disabled="!isFirstReport"
|
:clearable="isFirstReport"
|
:placeholder="isFirstReport ? '请输入盘具皮重' : '盘具皮重自动带出'"
|
type="digit"
|
>
|
<template #label>
|
<span style="color: #f56c6c">盘具皮重(kg)</span>
|
</template>
|
</wd-input>
|
</wd-cell-group>
|
</wd-form>
|
</template>
|
|
<script lang="ts" setup>
|
import { computed, watch } from "vue";
|
import useFormData from "@/hooks/useFormData";
|
import { useToast, dayjs } from "wot-design-uni";
|
import TwistApi from "@/api/product/twist";
|
|
// 定义 props
|
const props = defineProps<{
|
firstTareValue?: number;
|
teamId?: string | number | null;
|
isFirstReport?: boolean; // 是否是第一条报工
|
}>();
|
|
// 计算是否是第一条报工
|
const isFirstReport = computed(() => props.isFirstReport ?? true);
|
|
const paramsId = ref();
|
const toast = useToast();
|
const { form: model, resetForm } = useFormData({
|
actuallyLength: undefined, // 生产长度(m)
|
tare: undefined, // 盘具皮重(kg)
|
});
|
|
// 主表数据(从父组件传入)
|
const mainTableData = ref<any>({});
|
|
// 设置主表数据
|
const setMainTableData = (data: any) => {
|
mainTableData.value = data;
|
};
|
|
// 监听 firstTareValue 变化,如果不是第一条,自动填充
|
watch(
|
() => props.firstTareValue,
|
(newVal) => {
|
if (!isFirstReport.value && newVal !== undefined) {
|
model.tare = newVal;
|
}
|
},
|
{ immediate: true }
|
);
|
|
const submit = async () => {
|
// 获取第一条数据的皮重值,用于后续新增的报工
|
const firstTareValue = props.firstTareValue;
|
|
// 如果主表数据未获取,尝试重新获取
|
if (!mainTableData.value.model) {
|
try {
|
const { data } = await TwistApi.getTwistDetailById({
|
id: paramsId.value,
|
});
|
mainTableData.value = {
|
model: data.model,
|
totalLength: data.totalLength,
|
systemNo: data.systemNo,
|
};
|
} catch (error) {
|
console.error("获取主表数据失败:", error);
|
toast.error("获取规格型号数据失败,请重试");
|
return false;
|
}
|
}
|
|
// 再次检查主表数据
|
if (!mainTableData.value.model) {
|
toast.error("规格型号数据未获取,请重试");
|
return false;
|
}
|
|
const submitData = {
|
teamId: props.teamId || null,
|
wireId: paramsId.value,
|
type: "绞线",
|
actuallyLength: model.actuallyLength,
|
tare: model.tare || firstTareValue,
|
// 从主表获取的字段
|
model: mainTableData.value.model, // 规格型号
|
oneLength: mainTableData.value.totalLength,
|
systemNo: mainTableData.value.systemNo,
|
monofilamentNumber: undefined, // 批次号(后端自动生成)
|
// 生产日期自动设置为当前时间
|
productTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
};
|
|
// 调试日志
|
console.log("提交数据:", submitData);
|
console.log("主表数据:", mainTableData.value);
|
|
const { code } = await TwistApi.addTwistOutput(submitData);
|
if (code == 200) {
|
toast.success("提交成功");
|
resetForm();
|
return true;
|
} else {
|
toast.error("提交失败");
|
return false;
|
}
|
};
|
|
// 获取表单数据
|
const getFormData = () => {
|
return { ...model };
|
};
|
|
onLoad((options: any) => {
|
paramsId.value = options.id;
|
});
|
|
defineExpose({
|
submit,
|
getFormData,
|
setMainTableData,
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.submit_btn {
|
position: absolute;
|
bottom: 0;
|
width: 100%;
|
}
|
</style>
|