sign.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '报名', leftArrow: true, useBar: false },
  5. id: '',
  6. form: {},
  7. user: {},
  8. //是否试课
  9. is_try: '0',
  10. //状态
  11. statusList: [],
  12. //学员
  13. student: {},
  14. // 教练
  15. coach: {}
  16. },
  17. // 跳转菜单
  18. back(e) {
  19. wx.navigateBack({ delta: 1 })
  20. },
  21. //试课
  22. toClass: function () {
  23. const that = this;
  24. wx.showModal({
  25. title: '提示',
  26. content: '您是否确定试课?',
  27. async success(res) {
  28. if (res.confirm) {
  29. that.setData({ is_try: '1' })
  30. } else if (res.cancel) { }
  31. }
  32. });
  33. },
  34. //提交
  35. onSubmit: async function (e) {
  36. const that = this;
  37. const form = that.data.form;
  38. const user = that.data.user;
  39. wx.showModal({
  40. title: '提示',
  41. content: '您是否确定报名?',
  42. async success(res) {
  43. if (res.confirm) {
  44. let arr;
  45. let params = {
  46. school_id: form.school_id,
  47. lesson_id: form._id,
  48. student_id: user.info.id,
  49. money: form.money || 0,
  50. is_try: that.data.is_try,
  51. try_status: '0'
  52. }
  53. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, student_id: user.info.id })
  54. if (student.errcode == '0' && student.total > 0) arr = await app.$post(`/lessonStudent/${student.data[0]._id}`, params);
  55. else arr = await app.$post(`/lessonStudent`, params);
  56. if (arr.errcode == '0') { wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
  57. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  58. } else if (res.cancel) { }
  59. }
  60. });
  61. },
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad: async function (options) {
  66. const that = this;
  67. await that.setData({ id: options.id || null })
  68. // 查询其他信息
  69. await that.searchOther();
  70. // 监听用户是否登录
  71. await that.watchLogin();
  72. },
  73. searchOther: async function () {
  74. const that = this;
  75. let arr;
  76. // 状态
  77. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  78. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  79. },
  80. // 监听用户是否登录
  81. watchLogin: async function () {
  82. const that = this;
  83. let statusList = that.data.statusList;
  84. wx.getStorage({
  85. key: 'user',
  86. success: async res => {
  87. that.setData({ user: res.data })
  88. if (that.data.id) {
  89. const arr = await app.$get(`/lesson/${that.data.id}`);
  90. if (arr.errcode == '0') {
  91. let status = statusList.find(i => i.value == arr.data.status)
  92. if (status) arr.data.zhStatus = status.label;
  93. if (arr.data.school_id) {
  94. const school = await app.$get(`/school/${arr.data.school_id}`)
  95. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  96. }
  97. const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
  98. if (coach.errcode == '0') that.setData({ coach: coach.data })
  99. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, try_status: '1' })
  100. if (student.errcode == '0') that.setData({ student: student.data })
  101. that.setData({ form: arr.data })
  102. } else {
  103. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  104. }
  105. }
  106. },
  107. fail: async res => {
  108. wx.redirectTo({ url: '/pages/index/index' })
  109. }
  110. })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () { },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. }
  144. })