sign.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id }
  47. let arr = await app.$post(`/tryLessonApply`, params);
  48. if (arr.errcode == '0') { wx.showToast({ title: `试课申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
  49. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  50. } else if (res.cancel) { }
  51. }
  52. });
  53. },
  54. //提交
  55. onSubmit: async function (e) {
  56. const that = this;
  57. const form = that.data.form;
  58. const user = that.data.user;
  59. var payer_role = '';
  60. var money = '';
  61. if (form.type == '0') money = form.real_money;
  62. else if (form.type == '1') money = form.money;
  63. if (user.type == '0') payer_role = 'User';
  64. else if (user.type == '2') payer_role = 'Coach';
  65. else if (user.type == '3') payer_role = 'Student';
  66. wx.showModal({
  67. title: '提示',
  68. content: '您是否确定报名?',
  69. async success(res) {
  70. if (res.confirm) {
  71. wx.getStorage({
  72. key: 'user',
  73. success: async (res) => {
  74. let obj = { openid: res.data.openid, money: 0.1, school_id: form.school_id, payer_id: user.info.id, payer_role: payer_role, pay_for: 'lessonStudent' }
  75. const arr = await app.$post(`/payOrder`, obj)
  76. if (arr.errcode == '0') {
  77. wx.requestPayment({
  78. "timeStamp": arr.data.wxSign.timestamp,
  79. "nonceStr": arr.data.wxSign.nonceStr,
  80. "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
  81. "signType": arr.data.wxSign.signType,
  82. "paySign": arr.data.wxSign.paySign,
  83. "success": async function (res) {
  84. let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, pay_id: arr.data.data._id, is_pay: '1' }
  85. let lessonStudent = await app.$post(`/lessonStudent`, params);
  86. if (lessonStudent.errcode == '0') {
  87. wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 });
  88. const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id });
  89. if (pay.errcode == '0') that.watchLogin();
  90. }
  91. else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
  92. },
  93. "fail": async function (res) {
  94. const pay = await app.$delete(`/payOrder/${arr.data.data._id}`);
  95. },
  96. })
  97. }
  98. },
  99. fail: async (res) => {
  100. wx.redirectTo({ url: '/pages/index/index' });
  101. },
  102. });
  103. } else if (res.cancel) { }
  104. }
  105. });
  106. },
  107. /**
  108. * 生命周期函数--监听页面加载
  109. */
  110. onLoad: async function (options) {
  111. const that = this;
  112. await that.setData({ id: options.id || null })
  113. // 查询其他信息
  114. await that.searchOther();
  115. // 监听用户是否登录
  116. await that.watchLogin();
  117. },
  118. searchOther: async function () {
  119. const that = this;
  120. let arr;
  121. // 状态
  122. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  123. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  124. },
  125. // 监听用户是否登录
  126. watchLogin: async function () {
  127. const that = this;
  128. let statusList = that.data.statusList;
  129. wx.getStorage({
  130. key: 'user',
  131. success: async res => {
  132. that.setData({ user: res.data })
  133. if (that.data.id) {
  134. const arr = await app.$post(`/lessonStudent/toComputed`, { lesson_id: that.data.id, student_id: res.data.info.id });
  135. if (arr.errcode == '0') {
  136. let status = statusList.find(i => i.value == arr.data.status)
  137. if (status) arr.data.zhStatus = status.label;
  138. if (arr.data.school_id) {
  139. const school = await app.$get(`/school/${arr.data.school_id}`)
  140. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  141. const lesson = await app.$post(`/tryLessonApply/checkCanUse`, { school_id: arr.data.school_id, lesson_id: that.data.id, student_id: res.data.info.id })
  142. if (lesson.errcode == '0') arr.data.type_try = '0';
  143. else wx.showToast({ title: `${lesson.errmsg}`, icon: 'none', duration: 2000 })
  144. const lessonStudent = await app.$post(`/lessonStudent/checkCanUse`, { school_id: arr.data.school_id, student_id: res.data.info.id, lesson_id: that.data.id })
  145. if (lessonStudent.errcode == '0') arr.data.sign = '0';
  146. else arr.data.sign = '1';
  147. }
  148. const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
  149. if (coach.errcode == '0') that.setData({ coach: coach.data })
  150. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
  151. if (student.errcode == '0') that.setData({ student: student.data })
  152. that.setData({ form: arr.data })
  153. } else {
  154. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  155. }
  156. }
  157. },
  158. fail: async res => {
  159. wx.redirectTo({ url: '/pages/index/index' })
  160. }
  161. })
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady: function () { },
  167. /**
  168. * 生命周期函数--监听页面显示
  169. */
  170. onShow: function () {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. /**
  176. * 生命周期函数--监听页面隐藏
  177. */
  178. onHide: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面卸载
  182. */
  183. onUnload: function () {
  184. },
  185. /**
  186. * 页面相关事件处理函数--监听用户下拉动作
  187. */
  188. onPullDownRefresh: function () {
  189. },
  190. /**
  191. * 用户点击右上角分享
  192. */
  193. onShareAppMessage: function () {
  194. }
  195. })