Kaynağa Gözat

fix: use weixin origin modal

wangyuan 2 yıl önce
ebeveyn
işleme
280bd31192

+ 15 - 0
api/appointment.js

@@ -0,0 +1,15 @@
+// 预约 api
+import { wxRequest } from './request'
+
+const appointmentListURL = '/appointment/list' // 我的预约列表
+const cancelAppointmentURL = '/cancel/appointment' // 取消预约
+const submitAppointmentURL = '/submit/appointment' // 提交预约
+const getResetNumberURL = '/get/rest/number' // 区域剩余可用预约次数
+
+export const appointmentList =  (data) => wxRequest(appointmentListURL, data)
+
+export const cancelAppointment =  (data) => wxRequest(cancelAppointmentURL, data)
+
+export const submitAppointment =  (data) => wxRequest(submitAppointmentURL, data)
+
+export const getResetNumber =  (data) => wxRequest(getResetNumberURL, data)

+ 1 - 7
api/my.js

@@ -7,8 +7,6 @@ const loginURL = '/user/login' // 登录
 const bindBaseInfoURL = '/user/bind/base/info' // 绑定用户头像昵称
 
 const chargeListURL = '/get/charge/list' // 我的充值记录
-const appointmentListURL = '/appointment/list' // 我的预约列表
-const cancelAppointmentURL = '/cancel/appointment'
 
 export const ittLogin =  (data) => wxRequest(loginURL, data)
 
@@ -16,8 +14,4 @@ export const bindMobile =  (data) => wxRequest(bindMobileURL, data)
 
 export const bindBaseInfo =  (data) => wxRequest(bindBaseInfoURL, data)
 
-export const chargeList =  (data) => wxRequest(chargeListURL, data)
-
-export const appointmentList =  (data) => wxRequest(appointmentListURL, data)
-
-export const cancelAppointment =  (data) => wxRequest(cancelAppointmentURL, data)
+export const chargeList =  (data) => wxRequest(chargeListURL, data)

+ 3 - 26
api/request.js

@@ -5,10 +5,6 @@ import itt from '../utils/util'
 const app = getApp()
 export const wxRequest = (url,data) => {
   return new Promise((resolve, reject) => {
-    wx.showLoading({
-      title: '加载中...',
-      mask: true
-    })
     wx.request({
       url: BASE_API + url + BASE_VERSION,
       data: data,
@@ -25,36 +21,17 @@ export const wxRequest = (url,data) => {
         console.log('当前请求参数:', data);
         console.log('当前请求返回:', response.data);
         if (response.statusCode !== 200) {
-          wx.showToast({
-            title: response.errMsg || '请求错误',
-            icon:'none',
-            duration: 2500,
-            mask: true
-          })
+          reject(response.data.msg || '请求错误')
         } else {
           if (response.data.code !== '000') {
-            wx.showToast({
-              title: response.data.msg || '请求错误',
-              icon:'none',
-              duration: 2500,
-              mask: true
-            })
+            reject(response.data.msg || '请求错误')
           } else {
             resolve(response.data)
           }
         }
       },
       fail (e) {
-        wx.showToast({
-          title: '网络错误',
-          icon: 'error',
-          duration: 2500,
-          mask: true
-        })
-        reject(e)
-      },
-      complete () {
-        wx.hideLoading()
+        reject('网络错误')
       }
     })
   })

+ 24 - 0
pages/address/address.js

@@ -38,11 +38,23 @@ Page({
     var data = {
       currentPage: this.data.currentPage
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     addressList(data).then(res => {
+      wx.hideLoading()
       this.setData({
         hasNext: res.data.hasNext,
         addressList: res.data.vos
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
 
@@ -106,11 +118,23 @@ Page({
     var data = {
       addressId: that.data.addressId
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     deleteAddress(data).then(res => {
+      wx.hideLoading()
       that.setData({
         currentPage: 1
       })
       that.getAddressList()
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
   handleCancel () {

+ 20 - 0
pages/addressAdd/addressAdd.js

@@ -44,16 +44,36 @@ Page({
         contactPhone: this.data.contactPhone,
         isDefault: false
       }
+      wx.showLoading({
+        title: '加载中...',
+        mask: true
+      })
       if (that.data.isEdit) {
         data.addressId = this.data.addressId
         editAddress(data).then(res => {
+          wx.hideLoading()
           that.resetForm()
           wx.navigateBack()
+        }).catch(e => {
+          wx.hideLoading()
+          wx.showModal({
+            content: e,
+            confirmColor: '#333',
+            showCancel: false
+          })
         })
       } else {
         addAddress(data).then(res => {
+          wx.hideLoading()
           that.resetForm()
           wx.navigateBack()
+        }).catch(e => {
+          wx.hideLoading()
+          wx.showModal({
+            content: e,
+            confirmColor: '#333',
+            showCancel: false
+          })
         })
       }
     }

+ 1 - 0
pages/appointment/appointment.js

@@ -1,5 +1,6 @@
 // pages/appointment/appointment.js
 const app = getApp()
+import { submitAppointment } from '../../api/appointment'
 Page({
 
   /**

+ 12 - 0
pages/index/index.js

@@ -21,7 +21,12 @@ Page({
     this.initIndexData(true)
   },
   initIndexData (pullDownRefresh = false) {
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     homePage({}).then(hoemRes => {
+      wx.hideLoading()
       if (pullDownRefresh) {
         wx.stopPullDownRefresh()
       }
@@ -33,6 +38,13 @@ Page({
         useNumber: hoemRes.data.useNumber,
         documentVos: response
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
   /**

+ 46 - 2
pages/my/my.js

@@ -82,7 +82,12 @@ Page({
           var data = {
             code: res.code
           }
+          wx.showLoading({
+            title: '登录中...',
+            mask: true
+          })
           ittLogin(data).then(loginRes => {
+            wx.hideLoading()
             app.globalData.accessToken = loginRes.data.accessToken
             that.setData({
               isNeedPhone: loginRes.data.isNeedPhone,
@@ -116,7 +121,12 @@ Page({
               }
             }
           }).catch(e => {
-            console.log(e, 'ittlogin');
+            wx.hideLoading()
+            wx.showModal({
+              content: e,
+              confirmColor: '#333',
+              showCancel: false
+            })
           })
         }
       }
@@ -146,10 +156,20 @@ Page({
           let data = {
             code: res.code
           }
+          wx.showLoading({
+            title: '登录中...',
+            mask: true
+          })
           ittLogin(data).then(ittLoginRes => {
+            wx.hideLoading()
             that.bindMobileFn(phoneCode, ittLoginRes)
           }).catch(e => {
-            console.log(e, 'ittlogin');
+            wx.hideLoading()
+            wx.showModal({
+              content: e,
+              confirmColor: '#333',
+              showCancel: false
+            })
           })
         }
       }
@@ -162,7 +182,12 @@ Page({
     var data = {
       mobileCode: phoneCode
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     bindMobile(data).then(res => {
+      wx.hideLoading()
       app.globalData.userInfo.phoneNumber = res.data
       if (that.data.isRegister) {
         that.setData({
@@ -184,6 +209,13 @@ Page({
         app.globalData.userInfo.headImg = ittLoginRes.data.headImg
         app.globalData.userInfo.userName = ittLoginRes.data.userName
       }
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
   bindNickNameInput (e) {
@@ -198,7 +230,12 @@ Page({
       avatarUrl: that.data.avatarUrl,
       nickName: that.data.nickname
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     bindBaseInfo(data).then(res => {
+      wx.hideLoading()
       app.globalData.userInfo.login = true
       that.setData({
         pageLogin: true,
@@ -208,6 +245,13 @@ Page({
       })
       app.globalData.userInfo.headImg = that.data.confirmAvatarUrl
       app.globalData.userInfo.userName = that.data.confirmNickname
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
   /**

+ 43 - 12
pages/myAppointment/myAppointment.js

@@ -1,5 +1,5 @@
 // pages/myAppointment/myAppointment.js
-import { appointmentList, cancelAppointment } from '../../api/my'
+import { appointmentList, cancelAppointment } from '../../api/appointment'
 const app = getApp()
 Page({
 
@@ -9,7 +9,6 @@ Page({
   data: {
     navItemActive: '0',
     appointmentList: [],
-    dialogshow: false,
     currentPage: 1,
     hasNext: false,
     globalDataUserName: app.globalData.userInfo.userName,
@@ -43,11 +42,23 @@ Page({
       status: status,
       currentPage: this.data.currentPage
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     appointmentList(data).then(res => {
+      wx.hideLoading()
       this.setData({
         hasNext: res.data.hasNext,
         appointmentList: res.data.vos
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
 
@@ -57,27 +68,37 @@ Page({
   onReachBottom() {
     if (this.data.hasNext) {
       var _currentPag = this.data.currentPag + 1
+      that.setData({
+        currentPag: _currentPag
+      })
       this.getAppointmentList()
     }
   },
-  handleOverlayCancel(e) {
-    this.setData({
-      dialogshow: false
-    })
-  },
 
-  handleoverlayConfirm (e) {
+  handleCancelAppoint (e) {
     var that = this
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     cancelAppointment({
       appointmentId: this.data.appointmentId
     }).then(res => {
+      wx.hideLoading()
       wx.showToast({
         title: '取消成功',
         icon: 'success',
         success () {
-          that.appointmentList()
+          that.handleChangeNav(that.data.navItemActive, false)
         }
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
 
@@ -85,18 +106,28 @@ Page({
    * 取消预约
    */
   handleCancel(e) {
+    var that = this
     this.setData({
-      dialogshow: true,
       appointmentId: e.currentTarget.dataset.id
     })
+    wx.showModal({
+      content: '确定要取消预约吗?',
+      confirmColor: '#333',
+      cancelColor: '#666',
+      success (res) {
+        if (res.confirm) {
+          that.handleCancelAppoint()
+        }
+      }
+    })
   },
 
   /**
    * 切换nav
    * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
    */
-  handleChangeNav(e) {
-    var navItemActive = e.currentTarget.dataset.index
+  handleChangeNav(e, navFlag = true) {
+    var navItemActive = navFlag ? e.currentTarget.dataset.index : e
     this.setData({
       navItemActive: navItemActive,
       currentPage: 1

+ 0 - 12
pages/myAppointment/myAppointment.wxml

@@ -38,16 +38,4 @@
       </view>
     </view>
   </block>
-  <van-dialog
-      title="确定要取消预约吗?"
-      show="{{ dialogshow }}"
-      show-cancel-button
-      confirm-button-text="确定"
-      confirm-button-color="#333"
-      cancel-button-text="取消"
-      cancel-button-color="#666"
-      bind:confirm="handleoverlayConfirm"
-      bind:cancel="handleOverlayCancel"
-    >
-    </van-dialog>
 </view>

+ 17 - 10
pages/myFile/myFile.js

@@ -5,7 +5,6 @@ Page({
    * 页面的初始数据
    */
   data: {
-    vanoverlayshow: false,
     qrcodeDialog: false,
     currentPage: 1,
     hasNext: false,
@@ -24,8 +23,12 @@ Page({
     var data = {
       currentPage: this.data.currentPage
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     documentList(data).then(res => {
-      console.log(res, 'documentList');
+      wx.hideLoading()
       var response = res.data.vos
       response.map(item => {
         item.birthDay = item.birthday.split(' ')[0]
@@ -34,6 +37,13 @@ Page({
         hasNext: res.data.hasNext,
         fileList: response
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },
 
@@ -47,18 +57,15 @@ Page({
     }
   },
 
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  handleConfirm() {
-    this.setData({ vanoverlayshow: false })
-  },
-
   /**
    * 新建档案
    */
   handleAddFile() {
-    this.setData({ vanoverlayshow: true })
+    wx.showModal({
+      content: '建档人数已达上限',
+      confirmColor: '#333',
+      showCancel: false
+    })
   },
 
   /**

+ 0 - 8
pages/myFile/myFile.wxml

@@ -29,14 +29,6 @@
       <view class="handle-btn itt-btn" bindtap="handleAddFile">新建档案</view>
     </view>
   </view>
-  <van-dialog
-    title="建档人数已达上限"
-    show="{{ vanoverlayshow }}"
-    confirm-button-text="确定"
-    confirm-button-color="#333"
-    bind:confirm="handleConfirm"
-  >
-  </van-dialog>
   <van-dialog use-slot closeOnClickOverlay showConfirmButton="{{false}}" show="{{ qrcodeDialog }}">
     <view class="qrcode">
       <image class="qrcode-src" src="../../imaes/erweima@2x.png" />

+ 12 - 0
pages/myRecord/myRecord.js

@@ -42,11 +42,23 @@ Page({
     var data = {
       currentPage: this.data.currentPage
     }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
     chargeList(data).then(res => {
+      wx.hideLoading()
       this.setData({
         hasNext: res.data.hasNext,
         chargeRecordList: res.data.vos
       })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
     })
   },