info.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 || '' })
  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. console.log(coach);
  69. if (coach.errcode == '0') that.setData({ coach: coach.data })
  70. const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id })
  71. if (student.errcode == '0') that.setData({ student: student.data })
  72. that.setData({ form: arr.data })
  73. } else {
  74. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  75. }
  76. }
  77. },
  78. fail: async res => {
  79. wx.redirectTo({ url: '/pages/index/index' })
  80. }
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () { },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. },
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage: function () {
  114. }
  115. })