sign.js 5.3 KB

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