xiaojiao
2026-03-23 f02d3a8ffc05a10a64859b2a16d5d43c8abb0fb9
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<template>
    <view>
        <view>
            <u-table font-size="25">
                <u-tr>
                    <u-td>
                        <xfl-select :list="UserArray" :initValue="this.$UserTool.UserInfo.userName" :clearable="false"
                            :disabled="true">
                        </xfl-select>
                    </u-td>
                    <u-td width="25%">现在时间:</u-td>
                    <u-td width="25%">{{date}}</u-td>
                </u-tr>
            </u-table>
        </view>
 
        <view style="padding: 20rpx 0rpx">
            <u-table>
                <u-tr>
                    <u-td width="30%">托盘RFID码</u-td>
                    <u-td>
                        <u-input v-model="value_rfid" :border="true" placeholder="托盘码" id="value_rfid"
                            :focus="value_rfidfocus" />
                    </u-td>
                </u-tr>
            </u-table>
        </view>
        <view style="padding: 0rpx 0rpx;">
            <u-table>
                <u-tr>
                    <u-td>
                        <!-- 关键1:根据提交状态禁用按钮,提示用户正在处理 -->
                        <u-button 
                            style="width:100px" 
                            type="primary" 
                            @click="SaveInfomation"
                            :disabled="isSubmitting"
                            :loading="isSubmitting"
                        >
                            {{ isSubmitting ? '处理中...' : '确认' }}
                        </u-button>
                    </u-td>
                </u-tr>
            </u-table>
        </view>
    </view>
</template>
 
<script>
    // 移除全局_this,改用箭头函数避免this指向问题
    export default {
        data() {
            return {
                date: '',
                CurrentUser: '', //当前用户
                value_rfid: '',
                value_qrcode: '',
                value_rfidfocus: false,
                timer: null, // 定时器变量(补充定义,避免undefined)
                isSubmitting: false, // 关键2:提交状态锁,标记是否正在处理请求
                lastSubmitTime: 0, // 关键3:记录最后一次提交时间,防防抖
                submitInterval: 3000 // 防抖间隔:3秒内不允许重复提交(可调整)
            }
        },
        methods: {
            UserChange(value) {
 
            },
            setTimer() {
                if (this.timer == null) {
                    this.timer = setInterval(() => {
                        this.date = this.$DateTool.getDate();
                    }, 1000)
                }
            },
            SaveInfomation() {
                // 防抖校验:3秒内重复点击直接拦截
                const now = Date.now();
                if (now - this.lastSubmitTime < this.submitInterval) {
                    uni.showToast({
                        title: "请勿重复提交!",
                        duration: 2000,
                        icon: 'none'
                    });
                    return;
                }
 
                // 提交状态锁:正在处理中则拦截
                if (this.isSubmitting) {
                    uni.showToast({
                        title: "请稍候,正在处理中...",
                        duration: 2000,
                        icon: 'none'
                    });
                    return;
                }
 
                // 原有字段校验
                if (this.value_rfid.length == 0) {
                    uni.showToast({
                        title: "托盘码不能为空",
                        duration: 2000
                    });
                    return;
                }
                if (this.value_rfid.length > 6) {
                    uni.showToast({
                        title: "托盘长度不能大于6位数。",
                        duration: 2000,
                        icon: 'none',
                    });
                    return;
                }
 
                // 标记为提交中,禁用按钮
                this.isSubmitting = true;
                // 记录提交时间,用于防抖
                this.lastSubmitTime = now;
 
                uni.showModal({
                    title: '提示',
                    content: '请核对托盘码是否正确?',
                    // 关键4:改用箭头函数,避免this指向丢失
                    success: (res) => {
                        if (res.confirm) {
                            let data = {
                                MainData: {
                                    barcode: this.value_rfid
                                },
                            };
                            this.$AjaxRequest.Params('post', 'Dt_boxing_head/CreateEmptyPalletTask',
                                data, this.$UserTool.UserInfo.token);
                            this.$AjaxRequest.Request().then((result) => {
                                // 请求完成,重置提交状态
                                this.isSubmitting = false;
                                if (result.data.status) {
                                    uni.showToast({
                                        title: "创建空托入库成功!",
                                        duration: 2000
                                    });
                                    this.value_rfid = "";
                                    this.value_qrcode = "";
                                    this.value_rfidfocus = true;
                                } else {
                                    uni.showToast({
                                        icon: 'none',
                                        title: "请求错误:" + result.data.message,
                                        duration: 2000
                                    });
                                }
                            }).catch((err) => {
                                // 异常情况,也要重置提交状态
                                this.isSubmitting = false;
                                uni.showToast({
                                    icon: 'none',
                                    title: "请求后台异常,错误信息:" + err.errMsg,
                                    duration: 2000
                                });
                            });
                        } else if (res.cancel) {
                            // 取消确认,重置提交状态
                            this.isSubmitting = false;
                            this.value_rfidfocus = true;
                        }
                    },
                    // 关键5:弹窗关闭(如点击空白处),必须重置提交状态
                    complete: () => {
                        if (!this.isSubmitting) return; // 已处理完成则跳过
                        this.isSubmitting = false;
                    }
                });
            },
        },
        created: function() {
            // 每次进入界面时,先清除之前的所有定时器,然后启动新的定时器
            clearInterval(this.timer)
            this.timer = null;
            this.setTimer();
            this.CurrentUser = this.$UserTool.UserInfo.userName;
            this.UserArray = [this.$UserTool.AllUserInfo];
            this.value_rfidfocus = true;
        },
        destroyed: function() {
            // 每次离开当前界面时,清除定时器
            clearInterval(this.timer);
            this.timer = null;
        },
        mounted() {
            // 移除全局_this赋值,彻底避免this指向问题
        }
    }
</script>
 
<style scoped lang="scss">
    .tdHeight {
        height: 80rpx;
    }
 
    .loopView {
        height: 160px;
        background-color: #f0f0f0;
        margin-top: 10px;
    }
 
    .loopItem {
        margin-top: 5px;
        margin-left: 15px;
    }
 
    .deleteBtn {
        margin-top: 25px;
        margin-left: 10px;
        width: 120px;
        background-color: orangered;
    }
</style>