<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>
|