info.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: async function (options) {
  41. const that = this;
  42. await that.setData({ id: options.id || null })
  43. // 查询其他信息
  44. await that.searchOther();
  45. // 监听用户是否登录
  46. await that.watchLogin();
  47. },
  48. searchOther: async function () {
  49. const that = this;
  50. let arr;
  51. // 状态
  52. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  53. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  54. },
  55. // 监听用户是否登录
  56. watchLogin: async function () {
  57. const that = this;
  58. let statusList = that.data.statusList;
  59. wx.getStorage({
  60. key: 'user',
  61. success: async res => {
  62. that.setData({ user: res.data })
  63. if (that.data.id) {
  64. const arr = await app.$get(`/lesson/${that.data.id}`);
  65. if (arr.errcode == '0') {
  66. // 课程状态
  67. let status = statusList.find(i => i.value == arr.data.status)
  68. if (status) arr.data.zhStatus = status.label;
  69. // 学校名称
  70. const school = await app.$get(`/school/${arr.data.school_id}`)
  71. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  72. // 课程信息
  73. that.setData({ form: arr.data })
  74. // 教练信息
  75. const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
  76. if (coach.errcode == '0') that.setData({ coach: coach.data })
  77. // 学员信息
  78. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
  79. if (student.errcode == '0') that.setData({ student: student.data })
  80. }
  81. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  82. }
  83. },
  84. fail: async res => {
  85. wx.redirectTo({ url: '/pages/index/index' })
  86. }
  87. })
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () { },
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow: function () {
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload: function () {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })