Sfoglia il codice sorgente

fix: debug appointment api

wangyuan 2 anni fa
parent
commit
d7ef4bd74b

+ 9 - 2
pages/address/address.js

@@ -93,8 +93,15 @@ Page({
    */
   handleAddressChose (e) {
     if (this.data.formback == '1') {
-      /* app.globalData.navigateBackParams.address = e.currentTarget.dataset.address
-      wx.navigateBack() */
+      const address = e.currentTarget.dataset.info
+      app.globalData.navigateBackParams.contactName = address.contactName
+      app.globalData.navigateBackParams.addressId = address.addressId
+      app.globalData.navigateBackParams.contactPhone = address.contactPhone
+      app.globalData.navigateBackParams.province = address.province
+      app.globalData.navigateBackParams.city = address.city
+      app.globalData.navigateBackParams.county = address.county
+      app.globalData.navigateBackParams.address = address.province + address.city + address.county + address.detailAddress
+      wx.navigateBack()
     }
   },
 

+ 1 - 1
pages/address/address.wxml

@@ -2,7 +2,7 @@
 <view class="address-content">
   <view class="main-content">
     <view class="addrss-item" wx:for="{{addressList}}" wx:key="index">
-      <view class="top userinfo" data-address="{{item.address}}" bindtap="handleAddressChose">
+      <view class="top userinfo" data-info="{{item}}" bindtap="handleAddressChose">
         <view class="username ittflex-jcs">
           <text class="name">{{item.contactName}}</text>
           <text class="phone">{{item.contactPhone}}</text>

+ 87 - 28
pages/appointment/appointment.js

@@ -1,6 +1,6 @@
 // pages/appointment/appointment.js
 const app = getApp()
-import { submitAppointment } from '../../api/appointment'
+import { submitAppointment, getResetNumber } from '../../api/appointment'
 Page({
 
   /**
@@ -8,11 +8,16 @@ Page({
    */
   data: {
     hasAddress: false,
+    addressId: '',
     address: '',
-    timeActive: '0',
+    province: '',
+    city: '',
+    county: '',
+    timeActive: '1',
     appointmentSuccess: false, 
     curYear: '-',
     curMonth: '-',
+    choseDate: '',
     weekList: [],
     backupWeekList: [],
     currentTime: '',
@@ -58,10 +63,11 @@ Page({
       let _bankupWeekList = []
       for (let index = 0; index < 7; index++) {
         const bDate = new Date(that.data.currentTime - (index + 1) * 86400000).getDate()
-        const _month = baseDate.getMonth() + 1
+        const _month = Number(baseDate.getMonth() + 1) < 10 ? '0' + Number(baseDate.getMonth() + 1) : baseDate.getMonth() + 1
+        const _day = Number(baseDate.getDate()) < 10 ? '0' + baseDate.getDate() : baseDate.getDate()
         _bankupWeekList.unshift({
           date: index == 0 ? '约满' : bDate.getDate(),
-          dateStr: bDate.getFullYear() + '-' + _month,
+          dateStr: bDate.getFullYear() + '-' + _month + '-' + _day,
           disabled: true,
           status: ''
         })
@@ -77,21 +83,23 @@ Page({
     var _mapWeekList = that.data.weekList
     _mapWeekList.map((item, index) => {
       const baseDate = new Date((index - that.data.currentWeek) * 86400000 + that.data.currentTime)
-      const _month = baseDate.getMonth() + 1
+      const _month = Number(baseDate.getMonth() + 1) < 10 ? '0' + Number(baseDate.getMonth() + 1) : baseDate.getMonth() + 1
       const _year = baseDate.getFullYear()
+      const _day = Number(baseDate.getDate()) < 10 ? '0' + baseDate.getDate() : baseDate.getDate()
       if (index > that.data.currentWeek) {
         if (index == that.data.currentWeek + 1) {
           item.active = true
           that.setData({
             curYear: _year,
-            curMonth: _month
+            curMonth: _month,
+            choseDate: _year + '-' + _month + '-' + _day
           })
         }
         item.date = baseDate.getDate()
-        item.dateStr = baseDate.getFullYear() + '-' + _month
+        item.dateStr = _year + '-' + _month + '-' + _day
       } else {
         item.disabled = true
-        item.dateStr = baseDate.getFullYear() + '-' + _month
+        item.dateStr = baseDate.getFullYear() + '-' + _month + '-' + _day
         if (index == that.data.currentWeek || index == that.data.currentWeek - 1) {
           item.date = '约满'
         } else {
@@ -126,8 +134,7 @@ Page({
     if (!disabled) {
       const cDate = e.currentTarget.dataset.date
       const index = e.currentTarget.dataset.index
-
-      console.log(index, 'cDate');
+      console.log(cDate, 'cDate');
       const _year = cDate.split('-')[0]
       const _month = cDate.split('-')[1]
       const _weeklist = this.data.weekList
@@ -142,7 +149,8 @@ Page({
       this.setData({
         curYear: _year,
         curMonth: _month,
-        weekList: _weeklist
+        weekList: _weeklist,
+        choseDate: cDate
       })
     }
   },
@@ -150,16 +158,19 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    if (app.globalData.navigateBackParams.address ) {
+    if (app.globalData.navigateBackParams.address) {
       this.setData({
         hasAddress: true,
-        address: app.globalData.navigateBackParams.address
+        address: app.globalData.navigateBackParams.address,
+        contactName: app.globalData.navigateBackParams.contactName,
+        contactPhone: app.globalData.navigateBackParams.contactPhone,
+        addressId: app.globalData.navigateBackParams.addressId,
+        province: app.globalData.navigateBackParams.province,
+        city: app.globalData.navigateBackParams.city,
+        county: app.globalData.navigateBackParams.county
       })
     }
   },
-  formatterFn (day) {
-    console.log(day);
-  },
   /**
    * 选择地址
    */
@@ -190,7 +201,7 @@ Page({
   },
   // 去充值
   handleCharge () {},
-  // 确定
+  // 确定 先查询 区域的剩余预约次数
   handleConfirm () {
     if (!this.data.hasAddress) {
       wx.showToast({
@@ -203,18 +214,66 @@ Page({
       wx.showLoading({
         title: '预约中...'
       })
-      setTimeout(() => {
-        wx.hideLoading({
-          success: (res) => {
-            wx.showToast({
-              title: '预约成功',
-            })
-            itt.setData({
-              appointmentSuccess: true
-            })
-          }
+      var data = {
+        province: this.data.province,
+        city: this.data.city,
+        county: this.data.county,
+        appointmentDate: this.data.choseDate
+      }
+      getResetNumber(data).then(res => {
+        wx.hideLoading()
+        itt.submitAppointmentFn()
+      }).catch(e => {
+        wx.hideLoading()
+        wx.showModal({
+          content: e,
+          confirmColor: '#333',
+          showCancel: false
         })
-      }, 1200);
+      })
     }
+  },
+  // 提交预约信息
+  submitAppointmentFn () {
+    var data = {
+      appointmentTime: this.data.choseDate,
+      duration: this.data.timeActive,
+      addressId: this.data.addressId
+    }
+    submitAppointment(data).then(res => {
+      wx.hideLoading()
+      wx.showToast({
+        title: '预约成功',
+        icon: 'success'
+      })
+      this.setData({
+        appointmentSuccess: true
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
+  },
+  resetData () {
+    app.globalData.navigateBackParams.address = ''
+    app.globalData.navigateBackParams.contactName = ''
+    app.globalData.navigateBackParams.contactPhone = ''
+    app.globalData.navigateBackParams.addressId = ''
+    app.globalData.navigateBackParams.province = ''
+    app.globalData.navigateBackParams.city = ''
+    app.globalData.navigateBackParams.county = ''
+    this.setData({
+      hasAddress: true,
+      appointmentSuccess: false,
+      timeActive: '1'
+    })
+  },
+  handleCancel () {
+    this.resetData()
+    wx.navigateBack()
   }
 })

+ 8 - 8
pages/appointment/appointment.wxml

@@ -20,8 +20,8 @@
       <view wx:else class="address-card ittflex-jcs">
         <view class="ad-left">
           <view class="ad-top ittflex-jcs">
-            <text class="ad-name">测试用户</text>
-            <text class="ad-phone">18626576880</text>
+            <text class="ad-name">{{contactName}}</text>
+            <text class="ad-phone">{{contactPhone}}</text>
           </view>
           <view class="ad-bottom address-detail">
             {{address}}
@@ -56,30 +56,30 @@
             <view class="week-item">六</view>
           </view>
           <view class="week-body">
-            <view class="week-body-item backup-week-body-item {{item.disabled ? 'week-body-item-disabled' : ''}}" wx:for="{{backupWeekList}}" wx:key="index">
+            <view class="week-body-item backup-week-body-item {{item.disabled ? 'week-body-item-disabled' : ''}} {{item.date == '约满' ? 'week-body-item-full' : ''}}" wx:for="{{backupWeekList}}" wx:key="index">
               <view class="date">{{item.date}}</view>
             </view>
-            <view class="week-body-item {{item.disabled ? 'week-body-item-disabled' : ''}} {{item.active ? 'week-body-item-active' : ''}}" wx:for="{{weekList}}" wx:key="index">
+            <view class="week-body-item {{item.disabled ? 'week-body-item-disabled' : ''}} {{item.active ? 'week-body-item-active' : ''}} {{item.date == '约满' ? 'week-body-item-full' : ''}}" wx:for="{{weekList}}" wx:key="index">
               <view class="date" data-date="{{item.dateStr}}" data-disabled="{{item.disabled}}" data-index="{{index}}" bindtap="handleSelectDate">{{item.date}}</view>
             </view>
           </view>
         </view>
       </view>
       <view class="time-list ittflex">
-        <view class="time-a time-item time-nurse {{timeActive == '0' ? 'time-active' : ''}}" data-time="0" bindtap="handleTime">
+        <view class="time-a time-item time-nurse {{timeActive == '1' ? 'time-active' : ''}}" data-time="1" bindtap="handleTime">
           <text class="t-text">8:00-12:00</text>
           <!-- <text class="time-nurse-text">剩余紧张</text> -->
         </view>
-        <view class="time-b time-item {{timeActive == '1' ? 'time-active' : ''}}" data-time="1" bindtap="handleTime">
+        <view class="time-b time-item {{timeActive == '2' ? 'time-active' : ''}}" data-time="2" bindtap="handleTime">
           <text class="t-text">13:00-18:00</text>
         </view>
-        <view class="time-c time-item {{timeActive == '2' ? 'time-active' : ''}}" data-time="2" bindtap="handleTime">
+        <view class="time-c time-item {{timeActive == '3' ? 'time-active' : ''}}" data-time="3" bindtap="handleTime">
           <text class="t-text">18:00-21:00</text>
         </view>
       </view>
     </view>
     <view class="footer-actions ittflex-jcb">
-      <view class="f-btn cancel-btn ittflex">取消</view>
+      <view class="f-btn cancel-btn ittflex" bindtap="handleCancel">取消</view>
       <view class="f-btn confirm-btn itt-btn" bindtap="handleConfirm">确定</view>
     </view>
   </view>

+ 3 - 0
pages/appointment/appointment.wxss

@@ -180,6 +180,9 @@
   background-color: #45A6B5;
   border-radius: 50%;
 }
+.week-body-item-full {
+  color: #9A1D16;
+}
 .date {
   width: 100%;
   height: 100%;