spring
2025-10-15 7cf708376b46741dbee847e59c64a8e11ad088c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
  <view>
    <CardTitle title="绞线钢芯领用" :hideAction="false" />
    <SteelCoreForm ref="formRef" class="mx-4" />
    <view class="footer">
      <wd-button
        class="submit_btn"
        type="primary"
        size="large"
        block
        :round="false"
        @click="handleSubmit"
      >
        保存
      </wd-button>
    </view>
  </view>
  <wd-toast />
</template>
<script lang="ts" setup>
import CardTitle from "@/components/card-title/index.vue";
import SteelCoreForm from "./form.vue";
import { useToast } from "wot-design-uni";
import { onLoad, onUnload } from "@dcloudio/uni-app";
 
const formRef = ref();
const toast = useToast();
 
const handleSubmit = async () => {
  const success = await formRef.value.submitEdit();
  if (success) {
    setTimeout(() => {
      uni.navigateBack();
    }, 500);
  }
};
 
// 接收列表页传递的数据
const receiveEditData = (data: any) => {
  console.log("receiveEditData 接收到的数据:", data);
  if (data && formRef.value) {
    // 确保 list 和 editId 都存在
    if (data.list && data.editId) {
      formRef.value.setFormData(data.list, data.editId);
    } else {
      console.error("数据格式错误:", data);
    }
  }
};
 
onLoad((options: any) => {
  // 监听数据传递事件
  uni.$on("steelCoreEditData", receiveEditData);
});
 
onUnload(() => {
  // 页面卸载时移除监听
  uni.$off("steelCoreEditData", receiveEditData);
});
</script>
<style lang="scss" scoped>
.footer {
  margin: 20px 16px 0 16px;
}
</style>