sign.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. const app = getApp()
  2. const moment = require("../../../utils/moment.min")
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '详细信息', leftArrow: true, useBar: false },
  6. id: '',
  7. form: {},
  8. user: {},
  9. //是否试课
  10. is_try: '0',
  11. //状态
  12. statusList: [],
  13. //学员
  14. student: {},
  15. // 教练
  16. coach: {},
  17. // 选中
  18. tabs: {
  19. active: '0',
  20. menu: [
  21. { title: '课程信息', active: '0' },
  22. { title: '教练人员', active: '1' },
  23. { title: '学生人员', active: '2' },
  24. ]
  25. },
  26. },
  27. // 跳转菜单
  28. back(e) {
  29. wx.navigateBack({ delta: 1 })
  30. },
  31. // 选项卡选择
  32. tabsChange: function (e) {
  33. const that = this;
  34. let data = e.detail;
  35. that.setData({ 'tabs.active': data.active })
  36. },
  37. //试课
  38. toClass: function () {
  39. const that = this;
  40. const form = that.data.form;
  41. const user = that.data.user;
  42. wx.showModal({
  43. title: '提示',
  44. content: '您是否确定试课?',
  45. async success(res) {
  46. if (res.confirm) {
  47. let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id }
  48. let arr = await app.$post(`/tryLessonApply`, params);
  49. if (arr.errcode == '0') { wx.showToast({ title: `试课申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
  50. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  51. } else if (res.cancel) { }
  52. }
  53. });
  54. },
  55. //提交
  56. onSubmit: async function (e) {
  57. const that = this;
  58. const form = that.data.form;
  59. const user = that.data.user;
  60. var money = '';
  61. if (form.type == '0') money = form.real_money;
  62. else if (form.type == '1') money = form.money;
  63. wx.showModal({
  64. title: '提示',
  65. content: '您是否确定报名?',
  66. async success(res) {
  67. if (res.confirm) {
  68. wx.getStorage({
  69. key: 'user',
  70. success: async (res) => {
  71. let obj = { openid: res.data.openid, money: money, school_id: form.school_id, payer_id: user.info.id, payer_role: 'Student', pay_for: 'lessonStudent', time: moment().format('YYYY-MM-DD HH:mm:ss') }
  72. const arr = await app.$post(`/payOrder`, obj)
  73. if (arr.errcode == '0') {
  74. wx.requestPayment({
  75. "timeStamp": arr.data.wxSign.timestamp,
  76. "nonceStr": arr.data.wxSign.nonceStr,
  77. "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
  78. "signType": arr.data.wxSign.signType,
  79. "paySign": arr.data.wxSign.paySign,
  80. "success": async function (res) {
  81. 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' }
  82. let lessonStudent = await app.$post(`/lessonStudent`, params);
  83. if (lessonStudent.errcode == '0') {
  84. wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 });
  85. const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id });
  86. if (pay.errcode == '0') that.watchLogin();
  87. }
  88. else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
  89. },
  90. "fail": async function (res) {
  91. const pay = await app.$delete(`/payOrder/${arr.data.data._id}`);
  92. },
  93. })
  94. }
  95. },
  96. fail: async (res) => {
  97. wx.redirectTo({ url: '/pages/index/index' });
  98. },
  99. });
  100. } else if (res.cancel) { }
  101. }
  102. });
  103. },
  104. /**
  105. * 生命周期函数--监听页面加载
  106. */
  107. onLoad: async function (options) {
  108. const that = this;
  109. await that.setData({ id: options.id || null })
  110. // 查询其他信息
  111. await that.searchOther();
  112. // 监听用户是否登录
  113. await that.watchLogin();
  114. },
  115. searchOther: async function () {
  116. const that = this;
  117. let arr;
  118. // 状态
  119. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  120. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  121. },
  122. // 监听用户是否登录
  123. watchLogin: async function () {
  124. const that = this;
  125. let statusList = that.data.statusList;
  126. wx.getStorage({
  127. key: 'user',
  128. success: async res => {
  129. that.setData({ user: res.data })
  130. if (that.data.id) {
  131. if (res.data.type == '3') {
  132. const arr = await app.$post(`/lessonStudent/toComputed`, { lesson_id: that.data.id, student_id: res.data.info.id });
  133. if (arr.errcode == '0') {
  134. let status = statusList.find(i => i.value == arr.data.status)
  135. if (status) arr.data.zhStatus = status.label;
  136. if (arr.data.school_id) {
  137. const school = await app.$get(`/school/${arr.data.school_id}`)
  138. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  139. const lesson = await app.$post(`/tryLessonApply/checkCanUse`, { school_id: arr.data.school_id, lesson_id: that.data.id, student_id: res.data.info.id })
  140. if (lesson.errcode == '0') arr.data.type_try = '0';
  141. else wx.showToast({ title: `${lesson.errmsg}`, icon: 'none', duration: 2000 })
  142. const lessonStudent = await app.$post(`/lessonStudent/checkCanUse`, { school_id: arr.data.school_id, student_id: res.data.info.id, lesson_id: that.data.id })
  143. if (lessonStudent.errcode == '0') arr.data.sign = '0';
  144. else arr.data.sign = '1';
  145. }
  146. that.setData({ form: arr.data })
  147. } else {
  148. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  149. }
  150. }
  151. else {
  152. const arr = await app.$get(`/lesson/${that.data.id}`);
  153. if (arr.errcode == '0') {
  154. let status = statusList.find(i => i.value == arr.data.status)
  155. if (status) arr.data.zhStatus = status.label;
  156. if (arr.data.school_id) {
  157. const school = await app.$get(`/school/${arr.data.school_id}`)
  158. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  159. }
  160. that.setData({ form: arr.data })
  161. } else {
  162. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  163. }
  164. }
  165. const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
  166. if (coach.errcode == '0') that.setData({ coach: coach.data })
  167. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
  168. if (student.errcode == '0') that.setData({ student: student.data })
  169. }
  170. },
  171. fail: async res => {
  172. wx.redirectTo({ url: '/pages/index/index' })
  173. }
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function () { },
  180. /**
  181. * 生命周期函数--监听页面显示
  182. */
  183. onShow: function () {
  184. },
  185. /**
  186. * 页面上拉触底事件的处理函数
  187. */
  188. /**
  189. * 生命周期函数--监听页面隐藏
  190. */
  191. onHide: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面卸载
  195. */
  196. onUnload: function () {
  197. },
  198. /**
  199. * 页面相关事件处理函数--监听用户下拉动作
  200. */
  201. onPullDownRefresh: function () {
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage: function () {
  207. }
  208. })