123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const page = require('../../utils/page.js');
  5. import fetch from '../../utils/http'
  6. const $api = require('../../config/api.js').$api;
  7. Page({
  8. onShow() {
  9. wx.setNavigationBarTitle({
  10. title: '填写预约信息'
  11. })
  12. this.setData({
  13. BuildingId: page.getCurrentPageOptions().id,
  14. BuildingName: page.getCurrentPageOptions().name
  15. })
  16. this.setData({
  17. FormData: {
  18. Name: app.globalData.UserInfo.customerName,
  19. PhoneNum: app.globalData.UserInfo.phone,
  20. }
  21. })
  22. },
  23. data: {
  24. UserInfo: app.globalData.UserInfo, // 用户信息
  25. SubmitOff: true, // 提交判重开关
  26. BuildingId: '',
  27. BuildingName: '',
  28. FormData: { // 提交表单数据
  29. AppointmentDate: '', // 预约时间戳
  30. Name: '', // 姓名
  31. PhoneNum: '', // 手机号
  32. Remark: '' // 备注
  33. },
  34. AppointmentDate: '', // 预约时间
  35. MinDate: new Date().getTime(),
  36. TriggerSelectAppointmentDate: false // 显隐预约时间选择器
  37. },
  38. MakeAnAppointment() { // 预约
  39. if (this.data.SubmitOff) {
  40. this.setData({
  41. SubmitOff: false
  42. })
  43. if (this.data.FormData.AppointmentDate == '') {
  44. wx.showToast({
  45. title: '请选择预约时间',
  46. icon: 'none'
  47. })
  48. return
  49. }
  50. if (this.data.FormData.Name == '') {
  51. wx.showToast({
  52. title: '请填写您的姓名',
  53. icon: 'none'
  54. })
  55. return
  56. }
  57. if (this.data.FormData.PhoneNum == '') {
  58. wx.showToast({
  59. title: '请输入您的手机号',
  60. icon: 'none'
  61. })
  62. return
  63. }
  64. fetch({
  65. url: $api.appointment.save.url.replace(':openid', app.globalData.UserInfo.openid),
  66. method: $api.appointment.save.method,
  67. data: JSON.stringify({
  68. buildingId: this.data.BuildingId,
  69. appointmentDate: new Date(this.data.FormData.AppointmentDate),
  70. customerName: this.data.FormData.Name,
  71. phone: this.data.FormData.PhoneNum,
  72. remark: this.data.FormData.Remark
  73. })
  74. }).then((data) => {
  75. wx.showToast({
  76. title: '预约成功!',
  77. success: () => {
  78. setTimeout(() => {
  79. wx.navigateBack({
  80. delta: 1
  81. })
  82. }, 500)
  83. }
  84. })
  85. })
  86. }
  87. },
  88. FormInput(e) { // 表单输入数据绑定
  89. this.setData({
  90. FormData: {
  91. ...this.data.FormData,
  92. [e.target.dataset.name]: e.detail.value
  93. }
  94. })
  95. },
  96. DateFormat(timetamp) { // 日期格式化
  97. let aDate = new Date(timetamp)
  98. return `${aDate.getFullYear()}-${(aDate.getMonth() + 1).toString().padStart(2, 0)}-${aDate.getDate().toString().padStart(2, 0)} ${aDate.getHours().toString().padStart(2, 0)}:${aDate.getMinutes().toString().padStart(2, 0)}`
  99. },
  100. SelectAppointmentDateCancel() { // 取消选择预约时间
  101. this.setData({
  102. TriggerSelectAppointmentDate: false
  103. })
  104. },
  105. SelectAppointmentDateConfirm(e) { // 确认选择预约时间
  106. this.setData({
  107. FormData: {
  108. ...this.data.FormData,
  109. AppointmentDate: e.detail
  110. },
  111. AppointmentDate: this.DateFormat(e.detail),
  112. TriggerSelectAppointmentDate: false
  113. })
  114. },
  115. SelectAppointmentDate() { // 打开预约时间选择器
  116. this.setData({
  117. MinDate: new Date().getTime(),
  118. TriggerSelectAppointmentDate: true
  119. })
  120. },
  121. onShareAppMessage: function () {
  122. return app.globalData.ShareDate
  123. }
  124. })