appointment.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/appointment/appointment.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. hasAddress: false,
  9. address: '',
  10. calendarcolor: '#45A6B5',
  11. timeActive: '0',
  12. dialogsShow: false,
  13. appointmentSuccess: false,
  14. newDate: '',
  15. curYear: '-',
  16. curMonth: '-',
  17. maxDate: '',
  18. defaultDate: '',
  19. formatter(day) {
  20. const time = day.date.getTime();
  21. const cDate = new Date()
  22. const cyear = cDate.getFullYear()
  23. const cmonth = cDate.getMonth() + 1;
  24. const cdate = cDate.getDate();
  25. const str = cyear + '-' + cmonth + '-' + cdate
  26. if (time == new Date(str).getTime() || time == new Date(str).getTime() - 86400000) {
  27. day.text = '约满'
  28. day.type = 'disabled'
  29. day.className = 'calendar-all-full'
  30. }
  31. return day;
  32. }
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow() {
  43. if (app.globalData.navigateBackParams.address ) {
  44. this.setData({
  45. hasAddress: true,
  46. address: app.globalData.navigateBackParams.address
  47. })
  48. }
  49. this.handleDate()
  50. },
  51. // 处理日期
  52. handleDate () {
  53. const date = new Date()
  54. const time = date.getTime()
  55. const year = date.getFullYear()
  56. const month = date.getMonth() + 1
  57. const day = date.getDate()
  58. const str = year + '-' + month + '-' + day
  59. const _maxDate= 2592000000 + time
  60. const _defaultDate = new Date(str).getTime() + 86400000
  61. this.setData({
  62. curYear: year,
  63. curMonth: month,
  64. maxDate: _maxDate,
  65. defaultDate: _defaultDate
  66. })
  67. },
  68. /**
  69. * 选择地址
  70. */
  71. handleChoseAddress() {
  72. wx.navigateTo({
  73. url: '/pages/address/address?form=appointment&back=1',
  74. })
  75. },
  76. handleChangeAddress () {
  77. if (!this.data.appointmentSuccess) {
  78. wx.navigateTo({
  79. url: '/pages/address/address?form=appointment&back=1',
  80. })
  81. }
  82. },
  83. handleSelect (val) {
  84. var selectMonth = new Date(val.detail).getMonth() + 1
  85. var selectYear = new Date(val.detail).getFullYear()
  86. this.setData({
  87. curYear: selectYear,
  88. curMonth: selectMonth
  89. })
  90. },
  91. handleTime (e) {
  92. console.log(e);
  93. var timeActiveIndex = e.currentTarget.dataset.time
  94. this.setData({
  95. timeActive: timeActiveIndex
  96. })
  97. },
  98. // 激活卡片
  99. handleActiveCard () {
  100. wx.navigateTo({
  101. url: '/pages/scan/scan?form=appointment',
  102. })
  103. },
  104. // 去充值
  105. handleCharge () {},
  106. // 确定
  107. handleConfirm () {
  108. if (!this.data.hasAddress) {
  109. wx.showToast({
  110. title: '请选择地址!',
  111. icon: 'error',
  112. mask: true
  113. })
  114. } else {
  115. var itt = this
  116. wx.showLoading({
  117. title: '预约中...'
  118. })
  119. setTimeout(() => {
  120. wx.hideLoading({
  121. success: (res) => {
  122. wx.showToast({
  123. title: '预约成功!',
  124. })
  125. itt.setData({
  126. appointmentSuccess: true
  127. })
  128. }
  129. })
  130. }, 1200);
  131. }
  132. }
  133. })