Kaynağa Gözat

fix: bud appiontment api

wangyuan 2 yıl önce
ebeveyn
işleme
32522267a7

+ 7 - 1
api/my.js

@@ -7,6 +7,8 @@ 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)
 
@@ -14,4 +16,8 @@ export const bindMobile =  (data) => wxRequest(bindMobileURL, data)
 
 export const bindBaseInfo =  (data) => wxRequest(bindBaseInfoURL, data)
 
-export const chargeList =  (data) => wxRequest(chargeListURL, data)
+export const chargeList =  (data) => wxRequest(chargeListURL, data)
+
+export const appointmentList =  (data) => wxRequest(appointmentListURL, data)
+
+export const cancelAppointment =  (data) => wxRequest(cancelAppointmentURL, data)

+ 3 - 1
api/request.js

@@ -21,7 +21,9 @@ export const wxRequest = (url,data) => {
       },
       method: 'POST',
       success (response) {
-        console.log('当前请求地址:', url, '当前请求返回:', response.data);
+        console.log('当前请求地址:', url);
+        console.log('当前请求参数:', data);
+        console.log('当前请求返回:', response.data);
         if (response.statusCode !== 200) {
           wx.showToast({
             title: response.errMsg || '请求错误',

+ 60 - 36
pages/myAppointment/myAppointment.js

@@ -1,4 +1,6 @@
 // pages/myAppointment/myAppointment.js
+import { appointmentList, cancelAppointment } from '../../api/my'
+const app = getApp()
 Page({
 
   /**
@@ -6,77 +8,99 @@ Page({
    */
   data: {
     navItemActive: '0',
-    dataList: [1,1,1,1,1,1,1,1,1],
-    vanoverlayshow: false
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
+    appointmentList: [],
+    dialogshow: false,
+    currentPage: 1,
+    hasNext: false,
+    globalDataUserName: app.globalData.userInfo.userName,
+    appointmentId: ''
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    wx.showLoading({
-      title: '加载中...',
-      mask: true
+    this.setData({
+      navItemActive: '0'
     })
-    setTimeout(() => {
-      wx.hideLoading({
-        success: (res) => {},
-      })
-    }, 1500);
+    this.getAppointmentList()
   },
 
   /**
-   * 生命周期函数--监听页面隐藏
+   * 获取预约列表 
+   * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
    */
-  onHide() {
-
+  getAppointmentList() {
+    var status = ''
+    if (this.data.navItemActive == '0' ) {
+      status = ''
+    } else if (this.data.navItemActive == '1') {
+      status = 1
+    } else if (this.data.navItemActive == '2') {
+      status = 3
+    }
+    var data = {
+      status: status,
+      currentPage: this.data.currentPage
+    }
+    appointmentList(data).then(res => {
+      this.setData({
+        hasNext: res.data.hasNext,
+        appointmentList: res.data.vos
+      })
+    })
   },
 
   /**
-   * 生命周期函数--监听页面卸载
+   * 生命周期函数--监听到底
    */
-  onUnload() {
-
+  onReachBottom() {
+    if (this.data.hasNext) {
+      var _currentPag = this.data.currentPag + 1
+      this.getAppointmentList()
+    }
   },
-  handleOverlayCancel() {
+  handleOverlayCancel(e) {
     this.setData({
-      vanoverlayshow: false
+      dialogshow: false
     })
   },
-  handleoverlayConfirm () {
 
+  handleoverlayConfirm (e) {
+    var that = this
+    cancelAppointment({
+      appointmentId: this.data.appointmentId
+    }).then(res => {
+      wx.showToast({
+        title: '取消成功',
+        icon: 'success',
+        success () {
+          that.appointmentList()
+        }
+      })
+    })
   },
 
   /**
    * 取消预约
    */
-  handleCancel() {
+  handleCancel(e) {
     this.setData({
-      vanoverlayshow: true
+      dialogshow: true,
+      appointmentId: e.currentTarget.dataset.id
     })
   },
 
   /**
    * 切换nav
+   * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
    */
   handleChangeNav(e) {
     var navItemActive = e.currentTarget.dataset.index
     this.setData({
-      navItemActive: navItemActive
+      navItemActive: navItemActive,
+      currentPage: 1
     })
+    this.getAppointmentList()
   }
 })

+ 12 - 11
pages/myAppointment/myAppointment.wxml

@@ -5,23 +5,24 @@
     <view class="nav-item nav-wait ittflex {{navItemActive == '1' ? 'nav-item-active' : ''}}" bindtap="handleChangeNav" data-index="1">待服务</view>
     <view class="nav-item nav-done ittflex {{navItemActive == '2' ? 'nav-item-active' : ''}}" bindtap="handleChangeNav" data-index="2">已完成</view>
   </view>
-  <block wx:if="{{dataList.length == 0}}">
+  <block wx:if="{{appointmentList.length == 0}}">
     <view class="nodate" >
       <van-empty description="暂无数据" />
     </view>
   </block>
   <block wx:else>
-    <view wx:for="{{dataList}}" wx:key="index" class="data-item">
+    <view wx:for="{{appointmentList}}" wx:key="index" class="data-item">
       <view class="top date ittflex-jcb">
-        <text class="top-date">2022-09-20 13:00-18:00</text>
-        <!-- <text class="status s-wait">待服务</text>
-        <text class="status s-done">已完成</text> -->
-        <text class="status s-cancel">已取消</text>
+        <text class="top-date">{{item.appointmentTime}}</text>
+        <!-- status 1:申请 待服务 2.取消 3.完成 -->
+        <text class="status s-wait" wx:if="{{item.status == 1}}">待服务</text>
+        <text class="status s-done" wx:if="{{item.status == 3}}">已完成</text>
+        <text class="status s-cancel" wx:if="{{item.status == 2}}">已取消</text>
       </view>
       <view class="center info">
         <view class="username info-item">
           <text>预约账号:</text>
-          <text>测试用户</text>
+          <text>{{globalDataUserName}}</text>
         </view>
         <view class="username-w info-item">
           <text>待检测账号:</text>
@@ -29,17 +30,17 @@
         </view>
         <view class="order-time info-item">
           <text>下单时间:</text>
-          <text>2022-09-09 22:57</text>
+          <text>{{item.addTime}}</text>
         </view>
       </view>
-      <view class="bototm actions">
-        <view class="cancel-button ittflex" bindtap="handleCancel">取消</view>
+      <view class="bototm actions" wx:if="{{item.status == 1}}">
+        <view class="cancel-button ittflex" bindtap="handleCancel" data-id="{{item.id}}">取消</view>
       </view>
     </view>
   </block>
   <van-dialog
       title="确定要取消预约吗?"
-      show="{{ vanoverlayshow }}"
+      show="{{ dialogshow }}"
       show-cancel-button
       confirm-button-text="确定"
       confirm-button-color="#333"