|
@@ -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()
|
|
|
}
|
|
|
})
|