info.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '课程信息', leftArrow: true, useBar: false },
  5. id: '',
  6. form: {},
  7. //状态
  8. statusList: [],
  9. //学员
  10. student: {},
  11. // 教练
  12. coach: {},
  13. // 选中
  14. tabs: {
  15. active: '0',
  16. menu: [
  17. { title: '课程信息', active: '0' },
  18. { title: '教练人员', active: '1' },
  19. { title: '学生人员', active: '2' },
  20. ]
  21. },
  22. },
  23. // 跳转菜单
  24. back(e) {
  25. wx.navigateBack({ delta: 1 })
  26. },
  27. // 选项卡选择
  28. tabsChange: function (e) {
  29. const that = this;
  30. let data = e.detail;
  31. that.setData({ 'tabs.active': data.active })
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: async function (options) {
  37. const that = this;
  38. await that.setData({ id: options.id || null })
  39. // 查询其他信息
  40. await that.searchOther();
  41. // 监听用户是否登录
  42. await that.watchLogin();
  43. },
  44. searchOther: async function () {
  45. const that = this;
  46. let arr;
  47. // 状态
  48. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  49. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  50. },
  51. // 监听用户是否登录
  52. watchLogin: async function () {
  53. const that = this;
  54. let statusList = that.data.statusList;
  55. wx.getStorage({
  56. key: 'user',
  57. success: async res => {
  58. if (that.data.id) {
  59. const arr = await app.$get(`/lesson/${that.data.id}`);
  60. if (arr.errcode == '0') {
  61. let status = statusList.find(i => i.value == arr.data.status)
  62. if (status) arr.data.zhStatus = status.label;
  63. if (arr.data.school_id) {
  64. const school = await app.$get(`/school/${arr.data.school_id}`)
  65. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  66. }
  67. const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
  68. if (coach.errcode == '0') that.setData({ coach: coach.data })
  69. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
  70. if (student.errcode == '0') that.setData({ student: student.data })
  71. that.setData({ form: arr.data })
  72. } else {
  73. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  74. }
  75. }
  76. },
  77. fail: async res => {
  78. wx.redirectTo({ url: '/pages/index/index' })
  79. }
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () { },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow: function () {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })