selectTime.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // pages/indexPages/yyqhPages/selectTime/selectTime.js
  2. import {
  3. queryReserveDate,
  4. queryReserveTimePeriod,
  5. xcxjxyy
  6. } from "../../../../apis/index"
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. hall: "",
  13. business: "",
  14. dateBoxStyle: '',
  15. orgAreaNumber: "",
  16. dates: [],
  17. dateIndex: 0,
  18. times: [],
  19. timeIndex: 0,
  20. sfYy: false
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. let that = this
  27. that.init(options)
  28. },
  29. init(e) {
  30. let that = this
  31. if (e) {
  32. if (e.business) {
  33. that.setData({
  34. hall: wx.getStorageSync('MY_HALL').bsfwtmc,
  35. business: JSON.parse(e.business)
  36. })
  37. }
  38. that.getData()
  39. }
  40. },
  41. selectDate(e) {
  42. let that = this
  43. let index = e.currentTarget.dataset.index
  44. let item = e.currentTarget.dataset.item
  45. that.setData({
  46. dateIndex: index
  47. })
  48. that.getTime()
  49. },
  50. selectTime(e) {
  51. let that = this
  52. let index = e.currentTarget.dataset.index
  53. let item = e.currentTarget.dataset.item
  54. that.setData({
  55. timeIndex: index
  56. })
  57. },
  58. showHiden() {
  59. let that = this
  60. let dateBoxStyle = that.data.dateBoxStyle
  61. if (dateBoxStyle == '') {
  62. that.setData({
  63. dateBoxStyle: "timesActive"
  64. })
  65. } else {
  66. that.setData({
  67. dateBoxStyle: ""
  68. })
  69. }
  70. },
  71. getWeek(e) {
  72. let weeks = [
  73. "周日",
  74. "周一",
  75. "周二",
  76. "周三",
  77. "周四",
  78. "周五",
  79. "周六",
  80. ]
  81. return weeks[e]
  82. },
  83. getData(e) {
  84. let that = this
  85. wx.showLoading({
  86. title: '正在获取可预约日期',
  87. })
  88. let form = {
  89. bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm
  90. }
  91. queryReserveDate(form).then(res => {
  92. wx.hideLoading()
  93. if (res.code == 200) {
  94. that.setData({
  95. dates: res.billDateList.map((e) => {
  96. return {
  97. week: that.getWeek(new Date(e).getDay()),
  98. date: e.substring(5, 10),
  99. dates: e
  100. }
  101. }),
  102. orgAreaNumber: res.orgAreaNumber
  103. })
  104. that.getTime()
  105. } else {
  106. wx.showToast({
  107. title: res.msg || res.message,
  108. icon: "none",
  109. duration: 5000
  110. })
  111. }
  112. })
  113. },
  114. getTime() {
  115. let that = this
  116. wx.showLoading({
  117. title: '正在获取预约时间段',
  118. })
  119. let form = {
  120. orgAreaNumber: that.data.orgAreaNumber,
  121. billDate: that.data.dates[that.data.dateIndex].dates,
  122. bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm,
  123. ywId: that.data.ywId
  124. }
  125. queryReserveTimePeriod(form).then(res => {
  126. wx.hideLoading()
  127. if (res.code == 200) {
  128. that.setData({
  129. times: res.periodList
  130. })
  131. } else {
  132. wx.showToast({
  133. title: res.msg || res.message,
  134. icon: "none",
  135. duration: 5000
  136. })
  137. }
  138. })
  139. },
  140. next() {
  141. let that = this
  142. let times = that.data.times[that.data.timeIndex]
  143. let dates = that.data.dates[that.data.dateIndex].dates
  144. let orgAreaNumber = that.data.orgAreaNumber
  145. let yyrs = Number(times.capacity) - Number(times.appointNum)
  146. let sfYy = that.data.sfYy
  147. if (!sfYy) {
  148. if (yyrs != 0) {
  149. that.setData({
  150. sfYy: true
  151. })
  152. wx.showLoading({
  153. title: '正在预约中...',
  154. })
  155. let form = {
  156. bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm,
  157. ywId: that.data.business.ywId,
  158. ywxxId: that.data.business.ywxxId,
  159. unionid: wx.getStorageSync('PUBLIC_ID').unionid,
  160. yyrq: dates,
  161. yysjd: times.periodName,
  162. periodCode: times.periodCode,
  163. orgAreaNumber: orgAreaNumber,
  164. remainTicketNum: yyrs,
  165. }
  166. xcxjxyy(form).then(res => {
  167. that.setData({
  168. sfYy: true
  169. })
  170. wx.hideLoading()
  171. if (res.code == 200) {
  172. let datas = res.data
  173. wx.setStorageSync('YYDATA', datas)
  174. wx.reLaunch({
  175. url: '../success/success?business=' + JSON.stringify(that.data.business),
  176. })
  177. } else {
  178. wx.showToast({
  179. title: res.msg || res.message,
  180. icon: "none",
  181. duration: 5000
  182. })
  183. }
  184. })
  185. } else {
  186. wx.showToast({
  187. title: '可预约人数为 0,请换个时间段预约',
  188. icon: "none",
  189. duration: 5000
  190. })
  191. }
  192. }
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady() {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow() {
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage() {
  228. }
  229. })