diff --git a/pages/appointment/appointment.js b/pages/appointment/appointment.js index 4a37071..556a23e 100644 --- a/pages/appointment/appointment.js +++ b/pages/appointment/appointment.js @@ -3,6 +3,9 @@ const { formatDate } = require('../../utils/util') const { appointmentDB } = require('../../utils/api') const app = getApp() +// 订阅消息模板ID +const SUBSCRIBE_TEMPLATE_ID = 'Csf_dJU7DhvVFt_03sphPPBCGlnmcWQSPhgqfxHZ5RQ' + Page({ data: { form: { @@ -106,10 +109,19 @@ Page({ if (!this.validateForm()) return if (this.data.submitting) return + // 先请求订阅消息授权,再提交预约 + try { + await wx.requestSubscribeMessage({ + tmplIds: [SUBSCRIBE_TEMPLATE_ID] + }) + } catch (e) { + // 用户拒绝授权也允许继续提交,只是收不到通知 + console.warn('订阅消息授权失败或用户拒绝', e) + } + this.setData({ submitting: true }) try { - // 通过后端API创建预约 const openid = app.globalData.userInfo.openid await appointmentDB.create({ ...this.data.form, openid })