sign.js 5.9 KB

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