Selaa lähdekoodia

fix: reservation logic and calendar operation processing

wangyuan 2 vuotta sitten
vanhempi
commit
6b370b8ae4

+ 2 - 1
app.js

@@ -14,6 +14,7 @@ App({
     auth: {
       camera: true
     },
-    selectedInex: 2 // 自定义tabbar选中的index
+    selectedInex: 2, // 自定义tabbar选中的index
+    navigateBackParams: {}, // 使用wx.navigateBack 返回上一个页面的参数
   }
 })

+ 6 - 1
app.wxss

@@ -41,7 +41,12 @@ page {
   font-size: 26rpx;
   font-weight: 400;
 }
-itt-btn-disabled {
+.itt-btn-disabled {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: 26rpx;
+  font-weight: 400;
   background: #CCCCCC;
   color: #FFFFFF;
 }

+ 15 - 5
pages/address/address.js

@@ -1,11 +1,19 @@
 // pages/checkAddress/handleAddCheck.js
+const app = getApp()
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    addressList: [1,1,1],
+    addressList: [
+      {
+        address: '河南省信阳市固始县赵刚乡新堰村西寨组新堰村西寨组新堰村西寨组新堰村西寨组'
+      },
+      {
+        address: '上海市上海市嘉定区'
+      }
+    ],
     dialogshow: false,
     formPage: '',
     formback:0,
@@ -44,17 +52,19 @@ Page({
   },
 
   /**
-   * 生命周期函数--监听页面卸载
+   * 编辑地址
    */
-  onUnload() {
-
+  handleEdit(e) {
+    var value = e.currentTarget.dataset.address
+    console.log(value);
   },
 
   /**
    * 点击地址Item 我的地址进入不做处理 预约页面进入返回预约页面
    */
-  handleAddressChose () {
+  handleAddressChose (e) {
     if (this.data.formback == '1') {
+      app.globalData.navigateBackParams.address = e.currentTarget.dataset.address
       wx.navigateBack()
     }
   },

+ 5 - 5
pages/address/address.wxml

@@ -1,18 +1,18 @@
 <!--pages/checkAddress/handleAddCheck.wxml-->
 <view class="address-content">
   <view class="main-content">
-    <view class="addrss-item" wx:for="{{addressList}}" wx:key="index" bindtap="handleAddressChose">
-      <view class="top userinfo">
+    <view class="addrss-item" wx:for="{{addressList}}" wx:key="index">
+      <view class="top userinfo" data-address="{{item.address}}" bindtap="handleAddressChose">
         <view class="username ittflex-jcs">
           <text class="name">测试用户</text>
           <text class="phone">18626576880</text>
         </view>
-        <view class="address-detail">河南省信阳市固始县赵刚乡新堰村西寨组</view>
+        <view class="address-detail">{{item.address}}</view>
       </view>
       <view class="actions button ittflex">
-        <view class="edit-btn btn ittflex">
+        <view class="edit-btn btn ittflex" data-address="{{item.address}}" bindtap="handleEdit">
           <image class="btn-icon" src="./../../imaes/bianji@2x.png"></image>
-          <text class="btn-text">编辑</text>
+          <text class="btn-text" >编辑</text>
         </view>
         <view class="delete-btn btn ittflex" data-id="10010" bindtap="handleDelAddres">
           <image class="btn-icon" src="./../../imaes/shanchu@2x.png"></image>

+ 4 - 2
pages/addressAdd/addressAdd.js

@@ -5,6 +5,7 @@ Page({
    * 页面的初始数据
    */
   data: {
+    region:['浙江省','杭州市','富阳区'],
     rangText: ''
   },
 
@@ -26,7 +27,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    
   },
 
   /**
@@ -62,8 +63,9 @@ Page({
    */
   bindRegonPickerChange(e) {
     var value = e.detail.value
+    console.log(value);
     this.setData({
-      rangText: value
+      region: value
     })
   }
 })

+ 2 - 2
pages/addressAdd/addressAdd.wxml

@@ -4,9 +4,9 @@
     <view class="form-item chose-region ittflex-jcb">
       <view class="label ittflex">所在区域</view>
       <view class="actions">
-        <picker class="my-picker" mode="region" bindchange="bindRegonPickerChange">
+        <picker class="my-picker" mode="region" value="{{region}}" bindchange="bindRegonPickerChange">
           <view class="picker-item ittflex">
-              <text class="picker-text">{{rangText}}</text>
+              <text class="picker-text">{{region[0]}},{{region[1]}},{{region[2]}}</text>
               <van-icon name="arrow" color="#999" style="margin-right: 30rpx;"/>
             </view>
         </picker>

+ 95 - 10
pages/appointment/appointment.js

@@ -1,4 +1,5 @@
 // pages/appointment/appointment.js
+const app = getApp()
 Page({
 
   /**
@@ -6,9 +7,30 @@ Page({
    */
   data: {
     hasAddress: false,
+    address: '',
     calendarcolor: '#45A6B5',
-    timeActive: '9',
-    dialogsShow: true
+    timeActive: '0',
+    dialogsShow: false,
+    appointmentSuccess: false, 
+    newDate: '',
+    curYear: '-',
+    curMonth: '-',
+    maxDate: '',
+    defaultDate: '',
+    formatter(day) {
+      const time = day.date.getTime();
+      const cDate = new Date()
+      const cyear = cDate.getFullYear()
+      const cmonth = cDate.getMonth() + 1;
+      const cdate = cDate.getDate();
+      const str = cyear + '-' + cmonth + '-' + cdate
+      if (time == new Date(str).getTime() || time == new Date(str).getTime() - 86400000) {
+        day.text = '约满'
+        day.type = 'disabled'
+        day.className = 'calendar-all-full'
+      }
+      return day;
+    }
   },
 
   /**
@@ -17,7 +39,35 @@ Page({
   onLoad(options) {
 
   },
-
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+    if (app.globalData.navigateBackParams.address ) {
+      this.setData({
+        hasAddress: true,
+        address: app.globalData.navigateBackParams.address
+      })
+    }
+    this.handleDate()
+  },
+  // 处理日期
+  handleDate () {
+    const date = new Date()
+    const time = date.getTime()
+    const year = date.getFullYear()
+    const month = date.getMonth() + 1
+    const day = date.getDate()
+    const str = year + '-' + month + '-' + day 
+    const _maxDate= 2592000000 + time
+    const _defaultDate = new Date(str).getTime() + 86400000
+    this.setData({
+      curYear: year,
+      curMonth: month,
+      maxDate: _maxDate,
+      defaultDate: _defaultDate
+    })
+  },
   /**
    * 选择地址
    */
@@ -26,12 +76,20 @@ Page({
       url: '/pages/address/address?form=appointment&back=1',
     })
   },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-    
+  handleChangeAddress () {
+    if (!this.data.appointmentSuccess) {
+      wx.navigateTo({
+        url: '/pages/address/address?form=appointment&back=1',
+      })
+    }
+  },
+  handleSelect (val) {
+    var selectMonth = new Date(val.detail).getMonth() + 1
+    var selectYear = new Date(val.detail).getFullYear()
+    this.setData({
+      curYear: selectYear,
+      curMonth: selectMonth
+    })
   },
   handleTime (e) {
     console.log(e);
@@ -47,5 +105,32 @@ Page({
     })
   },
   // 去充值
-  handleCharge () {}
+  handleCharge () {},
+  // 确定
+  handleConfirm () {
+    if (!this.data.hasAddress) {
+      wx.showToast({
+        title: '请选择地址!',
+        icon: 'error',
+        mask: true
+      })
+    } else {
+      var itt = this
+      wx.showLoading({
+        title: '预约中...'
+      })
+      setTimeout(() => {
+        wx.hideLoading({
+          success: (res) => {
+            wx.showToast({
+              title: '预约成功!',
+            })
+            itt.setData({
+              appointmentSuccess: true
+            })
+          }
+        })
+      }, 1200);
+    }
+  }
 })

+ 11 - 6
pages/appointment/appointment.wxml

@@ -24,11 +24,11 @@
             <text class="ad-phone">18626576880</text>
           </view>
           <view class="ad-bottom address-detail">
-            内蒙古自治区兴安盟科尔沁右翼前旗友爱胡同459号
+            {{address}}
           </view>
         </view>
         <view class="ad-right ittflex">
-          <view class="itt-btn chose-address-btn">更换地址</view>
+          <view class="chose-address-btn {{appointmentSuccess ? 'itt-btn-disabled' : 'itt-btn'}}"  bindtap="handleChangeAddress">更换地址</view>
         </view>
       </view>
       <view class="ad-tips">注:预约成功后,检测地址不允许更改</view>
@@ -37,7 +37,9 @@
       <view class="sub-title ca-title">预约上门服务时间</view>
       <view class="calendar-card">
       <view class="calendar-card-header">
-        <view class="curr-date">2022年9月</view>
+        <view class="curr-date">
+          <text>{{curYear}}年{{curMonth}}月</text>
+        </view>
         <view class="cal-tips ittflex">
           <view class="warn-icon"></view>
           <text class="warn-text">代表繁忙时间</text>
@@ -51,14 +53,17 @@
           first-day-of-week="{{ 1 }}"
           show-subtitle="{{false}}"
           color="{{calendarcolor}}"
-          max-date="1664496000000"
+          max-date="{{maxDate}}"
+          default-date="{{defaultDate}}"
+          formatter="{{ formatter }}"
           row-height="45"
+          bind:select="handleSelect"
         />
       </view>
       <view class="time-list ittflex">
         <view class="time-a time-item time-nurse {{timeActive == '0' ? 'time-active' : ''}}" data-time="0" bindtap="handleTime">
           <text class="t-text">8:00-12:00</text>
-          <text class="time-nurse-text">剩余紧张</text>
+          <!-- <text class="time-nurse-text">剩余紧张</text> -->
         </view>
         <view class="time-b time-item {{timeActive == '1' ? 'time-active' : ''}}" data-time="1" bindtap="handleTime">
           <text class="t-text">13:00-18:00</text>
@@ -70,7 +75,7 @@
     </view>
     <view class="footer-actions ittflex-jcb">
       <view class="f-btn cancel-btn ittflex">取消</view>
-      <view class="f-btn confirm-btn itt-btn">确定</view>
+      <view class="f-btn confirm-btn itt-btn" bindtap="handleConfirm">确定</view>
     </view>
     <van-dialog
       title="您当前的检测次数为0,先充值次数"

+ 4 - 0
pages/appointment/appointment.wxss

@@ -209,6 +209,7 @@ view .van-calendar__days {
 }
 .time-active {
   background-color: var(--maincolor);
+  border: 1rpx solid var(--maincolor);
 }
 .time-active .t-text{
   color: #fff;
@@ -259,4 +260,7 @@ view .van-calendar__days {
 .w-confirm-btn {
   border-left: 1rpx solid #DDDDDD;
   font-weight: bold;
+}
+.calendar-all-full {
+  color: #9A1D16 !important;
 }

+ 5 - 1
pages/my/my.js

@@ -86,6 +86,7 @@ Page({
     wx.login({
       success (res) {
         if (res.code) {
+          console.log(res.code, 'code');
           let data = {
             code: res.code
           }
@@ -113,7 +114,10 @@ Page({
   // 路由跳转
   handleNavTo (e) {
     var url = e.currentTarget.dataset.url
-    this.authNavTo(url)
+    wx.navigateTo({
+      url: url,
+    })
+    // this.authNavTo(url)
   },
   /**
    * 路由拦截