|
@@ -5,6 +5,14 @@ Page({
|
|
|
contact: '',
|
|
|
phone: '',
|
|
|
repairType: '',
|
|
|
+ repairTypeValue: '',
|
|
|
+ repairTypeMap: [
|
|
|
+ {name: '换表', value: '1'},
|
|
|
+ {name: '换前阀', value: '2'},
|
|
|
+ {name: '换后阀', value: '3'},
|
|
|
+ {name: '换前后阀', value: '4'},
|
|
|
+ {name: '其他', value: '5'}
|
|
|
+ ],
|
|
|
description: '',
|
|
|
imageList: [],
|
|
|
showNotification: true,
|
|
@@ -17,7 +25,8 @@ Page({
|
|
|
mode: '',
|
|
|
isReplied: false,
|
|
|
formSubmitted: false,
|
|
|
- isSubmitting: false,
|
|
|
+ isSubmitting: false, // 新增保存标志位
|
|
|
+ lastSubmitTime: 0, // 上次提交时间(通过防抖(Debounce)技术,限制用户在一定时间内只能提交一次。)
|
|
|
},
|
|
|
|
|
|
onLoad: function (options) {
|
|
@@ -90,12 +99,16 @@ Page({
|
|
|
|
|
|
showRepairTypeSelector: function () {
|
|
|
let that = this;
|
|
|
+ // 只显示名称列表
|
|
|
+ const typeNames = this.data.repairTypeMap.map(item => item.name);
|
|
|
+
|
|
|
wx.showActionSheet({
|
|
|
- itemList: ['水管漏水', '水表故障', '水龙头故障', '其他问题'],
|
|
|
+ itemList: typeNames,
|
|
|
success: function (res) {
|
|
|
- const types = ['水管漏水', '水表故障', '水龙头故障', '其他问题'];
|
|
|
+ const selectedType = that.data.repairTypeMap[res.tapIndex];
|
|
|
that.setData({
|
|
|
- repairType: types[res.tapIndex]
|
|
|
+ repairType: selectedType.name,
|
|
|
+ repairTypeValue: selectedType.value
|
|
|
});
|
|
|
that.checkFormValidity();
|
|
|
}
|
|
@@ -172,17 +185,19 @@ Page({
|
|
|
phone,
|
|
|
address,
|
|
|
repairType,
|
|
|
+ repairTypeValue,
|
|
|
description
|
|
|
} = this.data;
|
|
|
-
|
|
|
+
|
|
|
const hasAddress = address && address.trim() !== '';
|
|
|
const hasContact = contact && contact.trim() !== '';
|
|
|
const hasPhone = phone && phone.trim() !== '';
|
|
|
const hasValidPhone = this.validatePhone(phone);
|
|
|
const hasRepairType = repairType && repairType.trim() !== '';
|
|
|
+ const hasRepairTypeValue = repairTypeValue && repairTypeValue.trim() !== '';
|
|
|
const hasDescription = description && description.trim() !== '';
|
|
|
-
|
|
|
- const isValid = hasAddress && hasContact && hasPhone && hasValidPhone && hasRepairType && hasDescription;
|
|
|
+
|
|
|
+ const isValid = hasAddress && hasContact && hasPhone && hasValidPhone && hasRepairType && hasRepairTypeValue && hasDescription;
|
|
|
|
|
|
this.setData({
|
|
|
isFormValid: isValid
|
|
@@ -232,6 +247,7 @@ Page({
|
|
|
contact: this.data.contact,
|
|
|
phone: this.data.phone,
|
|
|
repairType: this.data.repairType,
|
|
|
+ repairTypeValue: this.data.repairTypeValue,
|
|
|
description: this.data.description,
|
|
|
images: this.data.imageList
|
|
|
};
|
|
@@ -272,6 +288,14 @@ Page({
|
|
|
const item = prevPage.data.noticeList.find(item => item.id == id);
|
|
|
debugger
|
|
|
if (item) {
|
|
|
+ // 找到对应的报修类型名称
|
|
|
+ let repairTypeName = '';
|
|
|
+ const repairTypeValue = item.repairtype || '';
|
|
|
+ const repairTypeItem = this.data.repairTypeMap.find(type => type.name === repairTypeValue);
|
|
|
+ if (repairTypeItem) {
|
|
|
+ repairTypeName = repairTypeItem.name;
|
|
|
+ }
|
|
|
+
|
|
|
// 格式化时间
|
|
|
const formatTime = (timeString) => {
|
|
|
if (!timeString) return ''; // 如果时间为空,返回空字符串
|
|
@@ -286,7 +310,8 @@ Page({
|
|
|
address: item.address || '',
|
|
|
contact: item.contact || '',
|
|
|
phone: item.contactnumber || '',
|
|
|
- repairType: item.repairtype || '',
|
|
|
+ repairType: repairTypeName,
|
|
|
+ repairTypeValue: repairTypeValue,
|
|
|
description: item.faultdescription || '',
|
|
|
imageList: item.attachments || [],
|
|
|
replyTime: item.isReplied ? formatTime(item.repairtime) : '',
|
|
@@ -299,20 +324,19 @@ Page({
|
|
|
},
|
|
|
|
|
|
submitForm: function () {
|
|
|
+ // 如果正在提交中,直接返回
|
|
|
if (this.data.isSubmitting) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.setData({
|
|
|
- isSubmitting: true
|
|
|
- });
|
|
|
-
|
|
|
if (!this.data.address || this.data.address.trim() === '') {
|
|
|
wx.showToast({
|
|
|
title: '请填写地址',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -321,7 +345,9 @@ Page({
|
|
|
title: '请填写联系人',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -330,7 +356,9 @@ Page({
|
|
|
title: '请填写联系电话',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -339,7 +367,9 @@ Page({
|
|
|
title: '请输入正确的手机号',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -348,7 +378,20 @@ Page({
|
|
|
title: '请选择报修类型',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.data.repairTypeValue || this.data.repairTypeValue.trim() === '') {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择报修类型',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -357,10 +400,28 @@ Page({
|
|
|
title: '请填写故障说明',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- this.setData({ isSubmitting: false });
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ const now = Date.now();
|
|
|
+ const lastSubmitTime = this.data.lastSubmitTime;
|
|
|
+ // 如果距离上次提交时间小于 2 秒,直接返回
|
|
|
+ if (now - lastSubmitTime < 2000) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: '请勿重复提交',
|
|
|
+ // icon: 'none',
|
|
|
+ // });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新上次提交时间
|
|
|
+ this.setData({
|
|
|
+ lastSubmitTime: now,
|
|
|
+ });
|
|
|
+
|
|
|
const fileManager = wx.getFileSystemManager();
|
|
|
this.data.imageList.map(imgInfo => {
|
|
|
const base64 = fileManager.readFileSync(imgInfo.tempFilePath, 'base64');
|
|
@@ -372,11 +433,14 @@ Page({
|
|
|
address: this.data.address,
|
|
|
contact: this.data.contact,
|
|
|
phone: this.data.phone,
|
|
|
- repairType: this.data.repairType,
|
|
|
+ repairType: this.data.repairTypeValue,
|
|
|
description: this.data.description,
|
|
|
images: this.data.imageList
|
|
|
};
|
|
|
-
|
|
|
+ // 设置正在提交中 防止重复点击提交按钮
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: true,
|
|
|
+ });
|
|
|
console.log('提交的数据:', submitData);
|
|
|
|
|
|
wx.showLoading({
|
|
@@ -385,7 +449,6 @@ Page({
|
|
|
});
|
|
|
|
|
|
const that = this;
|
|
|
-
|
|
|
wx.request({
|
|
|
url: app.globalData.interfaceUrls.repairRegistration,
|
|
|
method: 'POST',
|
|
@@ -403,7 +466,9 @@ Page({
|
|
|
url: '/pages/baoxiuSuccess/baoxiuSuccess',
|
|
|
});
|
|
|
}
|
|
|
- that.setData({ isSubmitting: false });
|
|
|
+ that.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
},
|
|
|
fail(error) {
|
|
|
wx.hideLoading();
|
|
@@ -411,8 +476,16 @@ Page({
|
|
|
title: '登记失败,请稍后再试',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
- that.setData({ isSubmitting: false });
|
|
|
- }
|
|
|
+ that.setData({
|
|
|
+ isSubmitting: false
|
|
|
+ });
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ this.setData({
|
|
|
+ isSubmitting: false, // 提交完成,重置标志位,可继续提交
|
|
|
+ formSubmitted: true // 在提交成功后设置标记,返回将重置表单
|
|
|
+ });
|
|
|
+ },
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -440,6 +513,7 @@ Page({
|
|
|
contact: '',
|
|
|
phone: '',
|
|
|
repairType: '',
|
|
|
+ repairTypeValue: '',
|
|
|
description: '',
|
|
|
imageList: []
|
|
|
});
|