Kaynağa Gözat

fix: bugFixed appointmnt

wangyuan 2 yıl önce
ebeveyn
işleme
917599f019
2 değiştirilmiş dosya ile 122 ekleme ve 59 silme
  1. 114 53
      pages/appointment/appointment.js
  2. 8 6
      pages/appointment/appointment.wxml

+ 114 - 53
pages/appointment/appointment.js

@@ -26,7 +26,10 @@ Page({
     currentWeek: '',
     currentYear: '',
     appusername: '',
-    appuserheadimg: ''
+    appuserheadimg: '',
+    durationOne: false,
+    durationTwo: false,
+    durationThree: false
   },
 
   /**
@@ -58,6 +61,52 @@ Page({
       })
     }
   },
+
+  // 获取当天可预约的次数
+  getResetNumberFn (data) {
+    var that = this
+    var data = {
+      province: this.data.province,
+      city: this.data.city,
+      county: this.data.county,
+      appointmentDate: data
+    }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
+    getResetNumber(data).then(res => {
+      wx.hideLoading()
+      const response = res.data.carDurationConfigs
+      console.log(response)
+      response.forEach(item => {
+        console.log(item);
+        if (item.duration == 1) {
+          that.setData({
+            durationOne: item.isBusy
+          })
+        }
+        if (item.duration == 2) {
+          that.setData({
+            durationTwo: item.isBusy
+          })
+        }
+        if (item.duration == 3) {
+          that.setData({
+            durationThree: item.isBusy
+          })
+        }
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
+  },
+
   onPullDownRefresh () {
     wx.vibrateShort({
       type: 'medium'
@@ -125,7 +174,8 @@ Page({
           date: bDate.getDate(),
           dateStr: bDate.getFullYear() + '-' + _month + '-' + _day,
           disabled: true,
-          status: ''
+          status: '',
+          busy: false
         })
       }
       that.setData({
@@ -136,15 +186,43 @@ Page({
   },
   setCalendarItem () {
     var that = this
+    console.log(this.data.currentWeek, 'that.data.currentWeek');
+    console.log(that.data.weekList, 'that.data.weekList');
     var _mapWeekList = that.data.weekList
     _mapWeekList.map((item, index) => {
       const baseDate = new Date((index - that.data.currentWeek) * 86400000 + that.data.currentTime)
       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()
+      const _week = baseDate.getDay()
+      item.week = _week
+      if (_week == 0) {
+        item.weekStr = '周日'
+        item.busy = true
+      }
+      if (_week == 1) {
+        item.weekStr = '周一'
+      }
+      if (_week == 2) {
+        item.weekStr = '周二'
+      }
+      if (_week == 3) {
+        item.weekStr = '周三'
+      }
+      if (_week == 4) {
+        item.weekStr = '周四'
+      }
+      if (_week == 5) {
+        item.weekStr = '周五'
+      }
+      if (_week == 6) {
+        item.weekStr = '周六'
+        item.busy = true
+      }
       if (index > that.data.currentWeek) {
         if (index == that.data.currentWeek + 1) {
           item.date = '约满'
+          item.busy = false
           item.disabled = true
           that.setData({
             curYear: _year,
@@ -154,10 +232,7 @@ Page({
           item.date = baseDate.getDate()
         }
         if (index == that.data.currentWeek + 2) {
-           item.active = true
-           if (that.data.currentWeek == 4 || that.data.currentWeek == 5) {
-             item.busy = true
-           }
+           // item.active = true
            that.setData({
             choseDate: _year + '-' + _month + '-' + _day
           })
@@ -165,9 +240,11 @@ Page({
         item.dateStr = _year + '-' + _month + '-' + _day
       } else {
         item.disabled = true
+        item.busy = false
         item.dateStr = baseDate.getFullYear() + '-' + _month + '-' + _day
         if (index == that.data.currentWeek) {
           item.date = '约满'
+          
         } else {
           item.date = baseDate.getDate()
         }
@@ -197,34 +274,35 @@ Page({
 
   // 选择日期
   handleSelectDate (e) {
-    const disabled = e.currentTarget.dataset.disabled
-    if (!disabled) {
-      const cDate = e.currentTarget.dataset.date
-      const index = e.currentTarget.dataset.index
-      console.log(cDate, 'cDate', new Date(cDate).getDay(), index);
-      const _year = cDate.split('-')[0]
-      const _month = cDate.split('-')[1]
-      const _weeklist = this.data.weekList
-      //_weeklist[index].active = true
-      _weeklist.map((item, i) => {
-        if (index == i ) {
-          item.active = true
-          if (new Date(cDate).getDay() == 6 || new Date(cDate).getDay() == 0) {
-            item.busy = true
+    if (!this.data.hasAddress) {
+      wx.showToast({
+        title: '请选择地址',
+        icon: 'error',
+        mask: true
+      })
+    } else {
+      const disabled = e.currentTarget.dataset.disabled
+      if (!disabled) {
+        const cDate = e.currentTarget.dataset.date
+        const index = e.currentTarget.dataset.index
+        const _year = cDate.split('-')[0]
+        const _month = cDate.split('-')[1]
+        const _weeklist = this.data.weekList
+        _weeklist.map((item, i) => {
+          if (index == i ) {
+            item.active = true
           } else {
-            item.busy = false
+            item.active = false
           }
-        } else {
-          item.active = false
-          item.busy = false
-        }
-      })
-      this.setData({
-        curYear: _year,
-        curMonth: _month,
-        weekList: _weeklist,
-        choseDate: cDate
-      })
+        })
+        this.setData({
+          curYear: _year,
+          curMonth: _month,
+          weekList: _weeklist,
+          choseDate: cDate
+        })
+        this.getResetNumberFn(cDate)
+      }
     }
   },
 
@@ -279,27 +357,7 @@ Page({
         mask: true
       })
     } else {
-      var itt = this
-      wx.showLoading({
-        title: '预约中...'
-      })
-      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
-        })
-      })
+      this.submitAppointmentFn()
     }
   },
   // 提交预约信息
@@ -309,6 +367,9 @@ Page({
       duration: this.data.timeActive,
       addressId: this.data.addressId
     }
+    wx.showLoading({
+      title: '预约中...'
+    })
     var timer = null
     submitAppointment(data).then(res => {
       wx.hideLoading()

+ 8 - 6
pages/appointment/appointment.wxml

@@ -61,23 +61,25 @@
             <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' : ''}} {{item.date == '约满' ? 'week-body-item-full' : ''}} {{item.busy ? 'week-body-item-active-busy-dot' : ''}}" 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 wx:if="{{item.busy}}" class="week-body-item-active-busy-dot"></view>
+            <view class="week-body-item {{noralitem.disabled ? 'week-body-item-disabled' : ''}} {{noralitem.active ? 'week-body-item-active' : ''}} {{noralitem.date == '约满' ? 'week-body-item-full' : ''}}" wx:for="{{weekList}}" wx:key="index" wx:for-item="noralitem">
+              <view class="date" data-date="{{noralitem.dateStr}}" data-disabled="{{noralitem.disabled}}" data-index="{{index}}" bindtap="handleSelectDate">{{noralitem.date}}</view>
+              <view wx:if="{{noralitem.busy}}" class="week-body-item-active-busy-dot"></view>
             </view>
           </view>
         </view>
       </view>
       <view class="time-list ittflex">
-        <view class="time-a time-item {{timeActive == '1' ? 'time-active' : ''}}" data-time="1" 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" wx:if="{{durationOne}}">剩余紧张</text>
         </view>
-        <view class="time-b time-item {{timeActive == '2' ? 'time-active' : ''}}" data-time="2" bindtap="handleTime">
+        <view class="time-b time-item time-nurse {{timeActive == '2' ? 'time-active' : ''}}" data-time="2" bindtap="handleTime">
           <text class="t-text">13:00-18:00</text>
+          <text class="time-nurse-text" wx:if="{{durationTwo}}">剩余紧张</text>
         </view>
         <view class="time-c time-item time-nurse {{timeActive == '3' ? 'time-active' : ''}}" data-time="3" bindtap="handleTime">
           <text class="t-text">18:00-21:00</text>
-          <text class="time-nurse-text">剩余紧张</text>
+          <text class="time-nurse-text" wx:if="{{durationThree}}">剩余紧张</text>
         </view>
       </view>
     </view>