Initial Commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// index.js
|
||||
const { appointmentDB } = require('../../utils/cloud')
|
||||
const app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
latestRecord: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
if (app.globalData.isLoggedIn) {
|
||||
this.onLoginReady()
|
||||
} else {
|
||||
app.loginReadyCallback = () => {
|
||||
this.onLoginReady()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (app.globalData.isLoggedIn) {
|
||||
this.loadLatestRecord()
|
||||
}
|
||||
},
|
||||
|
||||
onLoginReady() {
|
||||
this.setData({ isLoggedIn: true })
|
||||
this.loadLatestRecord()
|
||||
},
|
||||
|
||||
async loadLatestRecord() {
|
||||
if (!this.data.isLoggedIn) {
|
||||
this.setData({ latestRecord: null })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const openid = app.globalData.userInfo.openid
|
||||
const record = await appointmentDB.getLatest(openid)
|
||||
if (record) {
|
||||
this.setData({ latestRecord: this.formatRecord(record) })
|
||||
} else {
|
||||
this.setData({ latestRecord: null })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载最新预约失败', err)
|
||||
this.setData({ latestRecord: null })
|
||||
}
|
||||
},
|
||||
|
||||
formatRecord(record) {
|
||||
const date = record.createTime
|
||||
let createTimeStr = ''
|
||||
if (date) {
|
||||
if (typeof date === 'object' && date.$date) {
|
||||
createTimeStr = new Date(date.$date).toLocaleString('zh-CN')
|
||||
} else {
|
||||
createTimeStr = new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
}
|
||||
return { ...record, createTime: createTimeStr }
|
||||
},
|
||||
|
||||
goAppointment() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/appointment/appointment'
|
||||
})
|
||||
},
|
||||
|
||||
goRecords() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/records/records'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user