appointment.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const app = getApp();
  2. import productApi from '../../api/product'
  3. import storeApi from '../../api/store'
  4. import createTimeApi from '../../utils/date'
  5. import orderApi from '../../api/order'
  6. import until from '../../utils/util'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. peopleNum: 1,
  13. activeTab: 0,
  14. shopInfo: {},
  15. shopId: 0,
  16. storeName: '',
  17. productId: 0,
  18. productImg: '',
  19. productName: '',
  20. price: 0,
  21. tabs: [],
  22. orderTime: "",
  23. orderTimeHeight: 0,
  24. days: [],
  25. hasMobile: false
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: async function (options) {
  31. var shopId = options.shopId;
  32. var productId = options.productId
  33. var productImg = options.productImg;
  34. var productName = options.productName;
  35. var price = options.price;
  36. this.setData({
  37. shopId,
  38. productId,
  39. productImg,
  40. productName,
  41. price
  42. })
  43. },
  44. checkAuth: async function () {
  45. const self = this
  46. const isAuth = await app.isAuth()
  47. if (!isAuth) {
  48. wx.redirectTo({
  49. url: '/pages/prompt/prompt?page=' + this.route,
  50. })
  51. }
  52. console.log(self.productInfo)
  53. let data = {
  54. productId: self.data.productId,
  55. storeId: self.data.shopId,
  56. appointmentTime: self.data.orderTime,
  57. num: self.data.peopleNum,
  58. mobile: 15656942279
  59. }
  60. const rs = await orderApi.createOrder(data)
  61. console.log(rs)
  62. let orderId = rs.orderId;
  63. wx.navigateTo({
  64. url: '../order/order?status=2&id='+orderId,
  65. })
  66. },
  67. getMobile:function (params) {
  68. },
  69. onSlideChangeEnd: function (e) {
  70. var that = this;
  71. that.setData({
  72. activeTab: e.detail.index
  73. })
  74. },
  75. //生成当前可预约的时间
  76. createTimeList: async function () {
  77. var storeId = this.data.shopId;
  78. var price = this.data.price;
  79. var shopInfo = await storeApi.getStoreById(storeId);
  80. var openTime = shopInfo.info.openTime;
  81. var closeTime = shopInfo.info.closeTime;
  82. var date = await storeApi.getStoreAppointTime(storeId);
  83. var days = date.date;
  84. console.log(days)
  85. const tabs = createTimeApi.createTimeList(openTime, closeTime, days, price);
  86. console.log(tabs)
  87. this.setData({
  88. storeName: shopInfo.info.storeName,
  89. days,
  90. tabs
  91. })
  92. },
  93. getOrderTime: function (e) {
  94. //选中日期的下标
  95. var i = this.data.activeTab;
  96. //选中时间的下标
  97. var index = e.currentTarget.dataset.i;
  98. //获取选中的日期
  99. var date = this.data.days[i];
  100. var time = e.currentTarget.dataset.time;
  101. var year = (new Date()).getFullYear()
  102. var oTime = year + '-' + date + ' ' + time;
  103. //设置选中的样式
  104. var tabs = this.data.tabs;
  105. var list = tabs[i].list;
  106. //先清空其他选中的样式
  107. list.forEach(function (item, i, array) {
  108. item.checked = false;
  109. })
  110. if (list[index].inTime) {
  111. list[index].checked = true;
  112. this.data.tabs[i].list = list;
  113. }
  114. this.setData({
  115. orderTime: oTime,
  116. tabs
  117. })
  118. },
  119. addPeopleNum: function (e) {
  120. var num = e.currentTarget.dataset.num;
  121. var maxNum = 9;
  122. if (num < maxNum) {
  123. num++;
  124. }
  125. this.setData({
  126. peopleNum: num
  127. })
  128. },
  129. reducePeopleNum: function (e) {
  130. var num = e.currentTarget.dataset.num;
  131. if (num > 1) {
  132. num--;
  133. }
  134. this.setData({
  135. peopleNum: num
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow: async function () {
  147. this.createTimeList();
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. },
  174. })