浏览代码

页面问题修复

QAQ 陈 4 月之前
父节点
当前提交
c40ff293e7

+ 17 - 1
pages/baoxiuList/baoxiuList.js

@@ -10,6 +10,14 @@ Page({
     imageList: [], // 存储图片路径的数组
     showCustomPreview: false, // 是否显示自定义预览
     currentPreviewImages: [], // 当前预览的图片数组
+    // 添加维修类型映射
+    repairTypeMap: [
+      {name: '换表', value: '1'},
+      {name: '换前阀', value: '2'},
+      {name: '换后阀', value: '3'},
+      {name: '换前后阀', value: '4'},
+      {name: '其他', value: '5'}
+    ],
   },
 
   /**
@@ -111,12 +119,20 @@ Page({
           } else {
             data.recoverydate = '';
           }
+          
+          // 转换维修类型值为名称
+          if (data.repairtype) {
+            const repairTypeItem = _this.data.repairTypeMap.find(item => item.name === data.repairtype);
+            data.repairtype = repairTypeItem ? repairTypeItem.name : '未知类型';
+          } else {
+            data.repairtype = '未知类型';
+          }
         });
-        
         app.globalData.mineRepairList = listData;
         _this.setData({
           noticeList: listData,
         })
+
         debugger
       },
       fail(error) {

+ 98 - 24
pages/baoxiudj/baoxiudj.js

@@ -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: []
     });

+ 3 - 1
pages/baoxiudj/baoxiudj.wxml

@@ -78,7 +78,9 @@
   </view>
 
   <!-- 提交按钮,仅在非预览模式下显示 -->
-  <button class="submit-btn" bindtap="submitForm" wx:if="{{!isPreviewMode}}">提交</button>
+  <button class="submit-btn" bindtap="submitForm" wx:if="{{!isPreviewMode}}" disabled="{{isSubmitting}}">
+    {{isSubmitting ? '提交中...' : '提交'}}
+  </button>
 
   <!-- 报修须知弹窗,仅在非预览模式下显示 -->
   <view class="notification-modal" wx:if="{{showNotification && !isPreviewMode}}">

+ 86 - 45
pages/tousujianyi/tousujianyi.js

@@ -1,4 +1,4 @@
-const  app= getApp();
+const app = getApp();
 Page({
   data: {
     contact: '',
@@ -14,10 +14,12 @@ Page({
     content: '',
     replyTime: '',
     replyContent: '',
-    formSubmitted: false
+    formSubmitted: false,
+    isSubmitting: false, // 新增保存标志位
+    lastSubmitTime: 0, // 上次提交时间(通过防抖(Debounce)技术,限制用户在一定时间内只能提交一次。)
   },
 
-  onLoad: function(options) {
+  onLoad: function (options) {
     this.startCountDown();
 
     // 检查是否是预览模式
@@ -35,7 +37,7 @@ Page({
     }
   },
 
-  onShow: function() {
+  onShow: function () {
     // 检查是否是从成功页面返回
     if (this.data.formSubmitted) {
       // 重置表单数据
@@ -47,9 +49,9 @@ Page({
     }
   },
 
-  startCountDown: function() {
+  startCountDown: function () {
     let that = this;
-    let timer = setInterval(function() {
+    let timer = setInterval(function () {
       if (that.data.countDown > 0) {
         that.setData({
           countDown: that.data.countDown - 1
@@ -60,25 +62,25 @@ Page({
     }, 1000);
   },
 
-  goBack: function() {
+  goBack: function () {
     wx.navigateBack();
   },
 
-  radioChange: function(e) {
+  radioChange: function (e) {
     this.setData({
       category: e.detail.value
     });
     this.checkFormValidity();
   },
 
-  inputContact: function(e) {
+  inputContact: function (e) {
     this.setData({
       contact: e.detail.value
     });
     this.checkFormValidity();
   },
 
-  inputPhone: function(e) {
+  inputPhone: function (e) {
     const value = e.detail.value;
     const phoneNumber = value.replace(/\D/g, '');
     this.setData({
@@ -87,19 +89,19 @@ Page({
     this.checkFormValidity();
   },
 
-  validatePhone: function(phone) {
+  validatePhone: function (phone) {
     const phoneReg = /^1[3-9]\d{9}$/;
     return phoneReg.test(phone);
   },
 
-  inputDescription: function(e) {
+  inputDescription: function (e) {
     this.setData({
       description: e.detail.value
     });
     this.checkFormValidity();
   },
 
-  chooseImage: function() {
+  chooseImage: function () {
     let that = this;
     if (that.data.imageList.length >= 10) {
       wx.showToast({
@@ -114,7 +116,7 @@ Page({
       mediaType: ['image'],
       sourceType: ['album', 'camera'],
       sizeType: ['compressed'],
-      success: function(res) {
+      success: function (res) {
         let tempFiles = res.tempFiles;
         let validFiles = [];
 
@@ -140,7 +142,7 @@ Page({
     });
   },
 
-  previewImage: function(e) {
+  previewImage: function (e) {
     let index = e.currentTarget.dataset.index;
     wx.previewImage({
       current: this.data.imageList[index],
@@ -148,7 +150,7 @@ Page({
     });
   },
 
-  deleteImage: function(e) {
+  deleteImage: function (e) {
     let index = e.currentTarget.dataset.index;
     let imageList = this.data.imageList;
     imageList.splice(index, 1);
@@ -157,8 +159,13 @@ Page({
     });
   },
 
-  checkFormValidity: function() {
-    const { contact, phone, description, category } = this.data;
+  checkFormValidity: function () {
+    const {
+      contact,
+      phone,
+      description,
+      category
+    } = this.data;
     // 只检查必填项:联系人、联系电话和内容说明
     const isValid = contact.trim() !== '' && this.validatePhone(phone) && description.trim() !== '';
 
@@ -169,9 +176,13 @@ Page({
     return isValid;
   },
 
-  onInputChange: function(e) {
-    const { field } = e.currentTarget.dataset;
-    const { value } = e.detail;
+  onInputChange: function (e) {
+    const {
+      field
+    } = e.currentTarget.dataset;
+    const {
+      value
+    } = e.detail;
 
     this.setData({
       [field]: value
@@ -180,12 +191,17 @@ Page({
     this.checkFormValidity();
   },
 
-  bindPickerChange: function(e) {
+  bindPickerChange: function (e) {
     this.checkFormValidity();
   },
 
   // 添加submitForm方法
-  submitForm: function() {
+  submitForm: function () {
+    // 如果正在提交中,直接返回
+    if (this.data.isSubmitting) {
+      return;
+    }
+   
     if (!this.checkFormValidity()) {
       let errorMsg = '';
 
@@ -203,11 +219,27 @@ Page({
       });
       return;
     }
-    debugger;
+
+    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=>{
+    this.data.imageList.map(imgInfo => {
       const base64 = fileManager.readFileSync(imgInfo.tempFilePath, 'base64');
-      imgInfo.base64=base64;
+      imgInfo.base64 = base64;
       return imgInfo;
     })
     // 构建提交数据
@@ -218,13 +250,17 @@ Page({
       description: this.data.description,
       images: this.data.imageList
     };
+debugger
+    // 设置正在提交中 防止重复点击提交按钮
+    this.setData({
+      isSubmitting: true,
+    });
 
     console.log('提交的数据:', submitData);
 
     wx.showLoading({
       title: '提交中...',
     });
-    debugger
     wx.request({
       url: app.globalData.interfaceUrls.feedback,
       method: 'POST',
@@ -234,33 +270,38 @@ Page({
         'source': "wc",
         '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
       },
-      data:submitData,
+      data: submitData,
       success(res) {
         wx.hideLoading();
-        if(res.data.code=='200'){
-            wx.navigateTo({
-              url: '/pages/tousujianyiSuccess/tousujianyiSuccess',
-            });
+        if (res.data.code == '200') {
+          wx.navigateTo({
+            url: '/pages/tousujianyiSuccess/tousujianyiSuccess',
+          });
         }
       },
       fail(error) {
         wx.hideLoading()
         utils.simleInfo('登记失败,请稍后再试')
-      }
+      },
+      complete: () => {
+        this.setData({
+          isSubmitting: false, // 提交完成,重置标志位,可继续提交
+          formSubmitted: true // 在提交成功后设置标记,返回将重置表单
+        });
+      },
     })
-
-    // 在提交成功后设置标记
-    this.setData({
-      formSubmitted: true
-    });
+    // 在提交成功后设置标记,返回将重置表单
+    // this.setData({
+    //   formSubmitted: true
+    // });
   },
 
-  submitRepair: function() {
+  submitRepair: function () {
     this.submitForm();
   },
 
   // 根据ID获取数据
-  getDataById: function(id) {
+  getDataById: function (id) {
     // 这里应该是从服务器获取数据
     // 但为了演示,我们从本地数据中获取
     const pages = getCurrentPages();
@@ -293,12 +334,12 @@ Page({
   },
 
   // 添加重置表单的方法
-  resetForm: function() {
+  resetForm: function () {
     this.setData({
-      contact: '', 
-      phone: '', 
-      description: '', 
+      contact: '',
+      phone: '',
+      description: '',
       imageList: []
     });
   }
-});
+});

+ 4 - 2
pages/tousujianyi/tousujianyi.wxml

@@ -76,6 +76,8 @@
   </view>
 
   <!-- 提交按钮,仅在非预览模式下显示 -->
-  <button class="submit-btn" bindtap="submitForm" wx:if="{{!isPreviewMode}}">提交</button>
+  <button class="submit-btn" bindtap="submitForm" wx:if="{{!isPreviewMode}}" disabled="{{isSubmitting}}">
+    {{isSubmitting ? '提交中...' : '提交'}}
+  </button>
 
-</view>
+</view>