| | |
| | | <template> |
| | | <wd-form ref="form" :model="model" class="relative form_box"> |
| | | <wd-cell-group :border="true"> |
| | | <wd-picker |
| | | v-model="diskMaterialValue" |
| | | :columns="diskMaterialOptions" |
| | | label="芯线类型" |
| | | label-width="100px" |
| | | prop="diskMaterial" |
| | | placeholder="请选择芯线类型" |
| | | clearable |
| | | @confirm="handleDiskMaterialChange" |
| | | /> |
| | | <wd-input |
| | | v-model="model.model" |
| | | label="规格型号" |
| | |
| | | <script lang="ts" setup> |
| | | import useFormData from "@/hooks/useFormData"; |
| | | import TwistApi from "@/api/product/twist"; |
| | | import ManageApi from "@/api/product/manage"; |
| | | import { useToast } from "wot-design-uni"; |
| | | |
| | | const props = defineProps({ |
| | |
| | | type: Object, |
| | | default: null, |
| | | }, |
| | | wireId: { |
| | | type: [String, Number], |
| | | default: undefined, |
| | | }, |
| | | }); |
| | | |
| | | const emits = defineEmits(["refresh"]); |
| | |
| | | const allListData = ref<any[]>([]); // 存储完整列表数据 |
| | | const toast = useToast(); |
| | | const { form: model } = useFormData({ |
| | | diskMaterial: undefined, // 芯线类型 |
| | | model: undefined, // 规格型号 |
| | | monofilamentNumber: undefined, // 样品编号 |
| | | amount: undefined, // 数量 |
| | |
| | | type: "钢芯", |
| | | }); |
| | | |
| | | // 芯线类型字典数据 |
| | | const diskMaterialOptions = ref<Array<{ label: string; value: string }>>([]); |
| | | const diskMaterialValue = ref(""); |
| | | |
| | | // 加载芯线类型字典数据 |
| | | const loadDiskMaterialDict = async () => { |
| | | try { |
| | | const res = await ManageApi.dictAPI("core_wire_type"); |
| | | if (res.data && Array.isArray(res.data)) { |
| | | diskMaterialOptions.value = res.data.map((item: any) => ({ |
| | | label: item.dictLabel || "", |
| | | value: item.dictValue || "", |
| | | })); |
| | | } |
| | | } catch (error) { |
| | | // 加载字典失败,静默处理 |
| | | } |
| | | }; |
| | | |
| | | // 处理芯线类型选择 |
| | | const handleDiskMaterialChange = (val: any) => { |
| | | model.diskMaterial = val.value; |
| | | }; |
| | | |
| | | // 监听 model.diskMaterial 变化,同步选择器显示 |
| | | watch( |
| | | () => model.diskMaterial, |
| | | (newValue) => { |
| | | diskMaterialValue.value = newValue || ""; |
| | | }, |
| | | { immediate: true } |
| | | ); |
| | | |
| | | // 新增提交 |
| | | const submit = async () => { |
| | | const currentWireId = props.wireId || paramsId.value; |
| | | const { code } = await TwistApi.addStrandedWireDish([ |
| | | { |
| | | wireId: paramsId.value, |
| | | wireId: currentWireId, |
| | | ...model, |
| | | }, |
| | | ]); |
| | |
| | | // 保留原有数据,然后更新修改的字段 |
| | | const updatedItem = { |
| | | ...item, // 先保留原有的所有数据 |
| | | diskMaterial: model.diskMaterial, |
| | | model: model.model, |
| | | monofilamentNumber: model.monofilamentNumber, |
| | | amount: model.amount, |
| | |
| | | const setFormData = (list: any[], currentEditId: number) => { |
| | | // 安全检查:确保list是数组 |
| | | if (!Array.isArray(list)) { |
| | | console.error("setFormData: list 参数不是数组", list); |
| | | return; |
| | | } |
| | | |
| | |
| | | // 找到当前编辑项并回显到表单 |
| | | const currentItem = list.find((item) => item.id === currentEditId); |
| | | if (currentItem) { |
| | | model.diskMaterial = currentItem.diskMaterial; |
| | | model.model = currentItem.model; |
| | | model.monofilamentNumber = currentItem.monofilamentNumber; |
| | | model.amount = currentItem.amount; |
| | | model.weight = currentItem.weight; |
| | | model.supplier = currentItem.supplier; |
| | | model.type = currentItem.type || "钢芯"; |
| | | // 设置芯线类型的回显值 |
| | | diskMaterialValue.value = currentItem.diskMaterial || ""; |
| | | } |
| | | }; |
| | | |
| | |
| | | () => props.editData, |
| | | (newData) => { |
| | | if (newData && props.mode === "edit") { |
| | | model.diskMaterial = newData.diskMaterial || ""; |
| | | model.model = newData.model || ""; |
| | | model.monofilamentNumber = newData.monofilamentNumber || ""; |
| | | model.amount = newData.amount || ""; |
| | | model.weight = newData.weight || ""; |
| | | model.supplier = newData.supplier || ""; |
| | | model.type = newData.type || "钢芯"; |
| | | diskMaterialValue.value = newData.diskMaterial || ""; |
| | | } |
| | | }, |
| | | { immediate: true, deep: true } |
| | |
| | | |
| | | // 重置表单数据 |
| | | const resetFormData = () => { |
| | | model.diskMaterial = undefined; |
| | | model.model = undefined; |
| | | model.monofilamentNumber = undefined; |
| | | model.amount = undefined; |
| | | model.weight = undefined; |
| | | model.supplier = undefined; |
| | | model.type = "钢芯"; |
| | | diskMaterialValue.value = ""; |
| | | }; |
| | | |
| | | // 填充表单数据(用于扫码后回显) |
| | | const fillFormData = (data: any) => { |
| | | if (data) { |
| | | model.diskMaterial = data.diskMaterial || ""; |
| | | model.model = data.model || ""; |
| | | model.monofilamentNumber = data.monofilamentNumber || ""; |
| | | model.amount = data.oneLength || data.amount || ""; |
| | | model.weight = data.weight || ""; |
| | | model.supplier = data.supplier || ""; |
| | | model.type = data.type || "钢芯"; |
| | | diskMaterialValue.value = data.diskMaterial || ""; |
| | | } |
| | | }; |
| | | |
| | | onLoad((options: any) => { |
| | | paramsId.value = options.id; |
| | | }); |
| | | |
| | | onMounted(async () => { |
| | | await loadDiskMaterialDict(); |
| | | }); |
| | | |
| | | defineExpose({ |
| | |
| | | submitEdit, |
| | | setFormData, |
| | | resetFormData, |
| | | fillFormData, |
| | | }); |
| | | </script> |
| | | |