lessoninfo.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. const app = getApp()
  2. const moment = require("../../utils/moment.min")
  3. const util = require('../../utils/util.js')
  4. Page({
  5. data: {
  6. frameStyle: { useTop: true, name: '课程详细信息', leftArrow: true, useBar: false },
  7. iconUrl: app.globalData.icon,
  8. id: '',
  9. tabs: {
  10. active: 'a',
  11. menu: [
  12. { title: '课程信息', active: 'a' },
  13. { title: '教练信息', active: 'b' },
  14. { title: '学员信息', active: 'c' },
  15. ],
  16. },
  17. // 课程信息
  18. form: {},
  19. // 教练信息
  20. coachList: [],
  21. // 学员信息
  22. studentList: [],
  23. total: 0,
  24. skip: 0,
  25. limit: 10,
  26. page: 0,
  27. // 字典表
  28. //状态
  29. statusList: [],
  30. },
  31. // 跳转菜单
  32. back(e) {
  33. wx.navigateBack({ delta: 1 })
  34. },
  35. tabsChange: function (e) {
  36. const that = this;
  37. let { active } = e.detail;
  38. that.setData({ 'tabs.active': active });
  39. },
  40. // 报名
  41. async toSign(e) {
  42. const that = this;
  43. const { item } = e.currentTarget.dataset;
  44. let id = that.data.id;
  45. wx.getStorage({
  46. key: 'user',
  47. success: async res => {
  48. let user = res.data;
  49. if (user && user.type == '3') {
  50. let obj = { openid: user.openid, money: item.money, school_id: item.school_id, student_id: user.info._id, lesson_id: id };
  51. // 创建报名
  52. await that.createLesson(obj);
  53. } else {
  54. wx.showToast({
  55. title: '账号角色不对,不可报名',
  56. icon: 'none'
  57. })
  58. }
  59. },
  60. fail: res => {
  61. wx.redirectTo({ url: '/pages/index/index', })
  62. }
  63. })
  64. },
  65. // 创建报名信息
  66. async createLesson(e) {
  67. const that = this;
  68. let res = await app.$post(`/lessonStudent`, e);
  69. if (res.errcode == '0') {
  70. // wxSign有值:余额不够,需手动支付
  71. // 无值:余额够,无需支付
  72. if (res?.data?.wxSign) {
  73. // 调取支付窗口
  74. let wxSign = res.data.wxSign;
  75. wx.requestPayment({
  76. timeStamp: wxSign.timestamp,
  77. nonceStr: wxSign.nonceStr,
  78. package: `prepay_id=${wxSign.prepay_id}`,
  79. signType: wxSign.signType,
  80. paySign: wxSign.paySign,
  81. async success(payRes) {
  82. wx.showToast({ title: '报名成功', icon: 'none' })
  83. that.watchLogin();
  84. },
  85. async fail(payErr) {
  86. wx.showToast({ title: '支付不成功', icon: 'none' })
  87. }
  88. })
  89. } else {
  90. wx.showToast({ title: '报名成功', icon: 'none' });
  91. that.watchLogin()
  92. }
  93. } else {
  94. wx.showToast({ title: res.errmsg, icon: 'none' })
  95. }
  96. },
  97. /**
  98. * 生命周期函数--监听页面加载
  99. */
  100. onLoad: async function (options) {
  101. const that = this;
  102. await that.setData({ id: options.id || '63563bbd8018a39220eca774' })
  103. // 查询其他信息
  104. await that.searchOther();
  105. // 监听用户是否登录
  106. await that.watchLogin();
  107. },
  108. // 监听用户是否登录
  109. watchLogin: async function () {
  110. const that = this;
  111. if (that.data.id) {
  112. await that.searchInfo();
  113. // 查询教练
  114. await that.searchCoach();
  115. // 查询学员信息
  116. await that.searchStudent()
  117. }
  118. },
  119. async searchInfo() {
  120. const that = this;
  121. const res = await app.$get(`/lesson/${that.data.id}`);
  122. if (res.errcode == '0') {
  123. // 课程状态
  124. res.data.zhStatus = that.searchStatus(res.data.status);
  125. // 课程信息
  126. that.setData({ form: res.data })
  127. }
  128. else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  129. },
  130. searchStatus(e) {
  131. const that = this;
  132. let data = that.data.statusList.find(i => i.value == e);
  133. if (data) return data.label
  134. },
  135. async searchCoach() {
  136. const that = this;
  137. let id = that.data.id;
  138. let res = await app.$get(`/lessonCoach`, { lesson_id: id });
  139. if (res.errcode == '0') {
  140. for (const val of res.data) {
  141. if (val.coach_id_phone) val.coach_id_phone = util.hidePhone(val.coach_id_phone);
  142. }
  143. that.setData({ coachList: res.data })
  144. } else {
  145. wx.showToast({ title: res.errmsg, icon: 'none' })
  146. }
  147. },
  148. async searchStudent() {
  149. const that = this;
  150. let id = that.data.id;
  151. let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: id }
  152. let res = await app.$get(`/lessonStudent`, { ...info });
  153. if (res.errcode == '0') {
  154. let list = [...that.data.studentList, ...res.data];
  155. for (const val of list) {
  156. if (val.student_id_phone) val.student_id_phone = util.hidePhone(val.student_id_phone);
  157. }
  158. that.setData({ studentList: list })
  159. that.setData({ total: res.total })
  160. } else {
  161. wx.showToast({ title: res.errmsg, icon: 'none' })
  162. }
  163. },
  164. // 清空列表
  165. clearPage() {
  166. const that = this;
  167. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  168. },
  169. // 分页
  170. toPage: function () {
  171. const that = this;
  172. let list = that.data.studentList;
  173. let limit = that.data.limit;
  174. if (that.data.total > list.length) {
  175. wx.showLoading({ title: '加载中', mask: true })
  176. let page = that.data.page + 1;
  177. that.setData({ page: page })
  178. let skip = page * limit;
  179. that.setData({ skip: skip })
  180. that.searchStudent();
  181. wx.hideLoading()
  182. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  183. },
  184. searchOther: async function () {
  185. const that = this;
  186. let arr;
  187. // 状态
  188. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  189. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  190. },
  191. /**
  192. * 生命周期函数--监听页面初次渲染完成
  193. */
  194. onReady: function () { },
  195. /**
  196. * 生命周期函数--监听页面显示
  197. */
  198. onShow: function () { },
  199. /**
  200. * 页面上拉触底事件的处理函数
  201. */
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload: function () {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function () {
  216. },
  217. /**
  218. * 用户点击右上角分享
  219. */
  220. onShareAppMessage: function () {
  221. }
  222. })