YLouie
2025-10-23 8460eac918d8c8e825a0f78ac0af1c03cad8fd49
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
  <wd-form ref="form" :model="model" class="relative form_box">
    <wd-cell-group :border="true">
      <wd-input
        v-model="model.poleNumber"
        label="领用杆号"
        label-width="100px"
        prop="poleNumber"
        placeholder="请输入领用杆号"
      >
        <template #suffix>
          <wd-icon name="scan" @click="openScan" />
        </template>
      </wd-input>
      <wd-input
        v-model="model.poleWeight"
        label="杆重"
        label-width="100px"
        prop="poleWeight"
        clearable
        placeholder="请输入杆重"
      />
      <wd-input
        v-model="model.poleModel"
        label="杆型号"
        label-width="100px"
        prop="poleModel"
        clearable
        placeholder="请输入杆型号"
      />
      <wd-input
        v-model="model.model"
        label="规格型号"
        label-width="100px"
        prop="model"
        clearable
        placeholder="请输入规格型号"
      />
      <wd-input
        v-model="model.oneLength"
        label="盘长(m)"
        label-width="100px"
        prop="oneLength"
        clearable
        placeholder="请输入盘长"
      />
      <wd-input
        v-model="model.polePackageNumber"
        label-width="100px"
        prop="polePackageNumber"
        clearable
        placeholder="请输入杆包号"
      >
        <template #label>
          <span style="color: #f56c6c">杆包号</span>
        </template>
      </wd-input>
      <wd-input
        v-model="model.dishModel"
        label-width="100px"
        prop="dishModel"
        clearable
        placeholder="请输入盘型号"
      >
        <template #label>
          <span style="color: #f56c6c">盘型号</span>
        </template>
      </wd-input>
      <wd-input
        v-model="model.actuallyLength"
        label-width="100px"
        prop="actuallyLength"
        clearable
        placeholder="请输入实际长度"
      >
        <template #label>
          <span style="color: #f56c6c">实际长度(m)</span>
        </template>
      </wd-input>
      <wd-input
        v-model="model.actuallyWeight"
        label-width="100px"
        prop="actuallyWeight"
        clearable
        placeholder="请输入实际重量"
      >
        <template #label>
          <span style="color: #f56c6c">实际重量(kg)</span>
        </template>
      </wd-input>
    </wd-cell-group>
    <wd-toast />
    <Scan ref="scanRef" />
  </wd-form>
</template>
 
<script lang="ts" setup>
import useFormData from "@/hooks/useFormData";
import { useToast } from "wot-design-uni";
import WireApi from "@/api/product/wire";
import Scan from "@/components/scan/index.vue";
 
const paramsId = ref();
const scanRef = ref();
const toast = useToast();
const { form: model, resetForm } = useFormData({
  poleNumber: undefined, // 领用杆号
  poleWeight: undefined, // 杆重
  poleModel: undefined, // 杆型号
  model: undefined, // 规格型号
  polePackageNumber: undefined, // 杆包号
  dishModel: undefined, // 盘型号
  oneLength: undefined, // 盘长
  actuallyLength: undefined, // 实际长度
  actuallyWeight: undefined, // 实际重量
});
 
const submit = async () => {
  // 在调用API前先保存poleNumber的值,确保我们有正确的值
  const poleNumberValue = model.poleNumber;
 
  const { code } = await WireApi.addWireOutput({
    wireId: paramsId.value,
    type: "拉丝",
    ...model,
  });
 
  if (code == 200) {
    toast.success("提交成功");
    // 创建返回结果对象,使用提前保存的poleNumber值
    const result = {
      success: true,
      poleNumber: poleNumberValue,
    };
    // 在返回之前执行resetForm()
    resetForm();
    // 返回结果
    return result;
  } else {
    toast.error("提交失败");
    return { success: false };
  }
};
 
const openScan = () => {
  scanRef.value.triggerScan();
};
 
//  监听扫码
const getScanCode = (code: any) => {
  console.log("自定义扫描的结果回调函数:", code.code);
  // console.log("自定义扫描的结果回调函数", JSON.parse(code));
  const arr = code.code.split(",");
  model.poleNumber = arr[3]; //  领用杆号
  model.poleWeight = arr[4]; //  杆重
  model.poleModel = arr[2]; //  杆型号
};
 
onLoad((options: any) => {
  paramsId.value = options.id;
  model.model = options.model;
  console.log("options", options);
  model.oneLength = options.oneLength;
  // 开启广播监听事件
  uni.$on("scan", getScanCode);
});
 
onUnload(() => {
  // 开启广播监听事件
  uni.$off("scan", getScanCode);
});
 
defineExpose({
  submit,
});
</script>
 
<style lang="scss" scoped>
.submit_btn {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>