info.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // 跳转菜单
  11. back(e) {
  12. wx.navigateBack({ delta: 1 })
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: async function (options) {
  18. const that = this;
  19. await that.setData({ id: options.id || null })
  20. // 查询其他信息
  21. await that.searchOther();
  22. // 监听用户是否登录
  23. await that.watchLogin();
  24. },
  25. searchOther: async function () {
  26. const that = this;
  27. let arr;
  28. // 状态
  29. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  30. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  31. },
  32. // 监听用户是否登录
  33. watchLogin: async function () {
  34. const that = this;
  35. let statusList = that.data.statusList;
  36. wx.getStorage({
  37. key: 'user',
  38. success: async res => {
  39. if (that.data.id) {
  40. const arr = await app.$get(`/lessonPrivate/${that.data.id}`);
  41. if (arr.errcode == '0') {
  42. let status = statusList.find(i => i.value == arr.data.status)
  43. if (status) arr.data.zhStatus = status.label;
  44. if (arr.data.coach_id) {
  45. const coach = await app.$get(`/coach/${arr.data.coach_id}`);
  46. if (coach.errcode == '0') arr.data.zhCoach = coach.data.name;
  47. }
  48. if (arr.data.school_id) {
  49. const school = await app.$get(`/school/${arr.data.school_id}`)
  50. if (school.errcode == '0') arr.data.zhSchool = school.data.name;
  51. }
  52. that.setData({ form: arr.data })
  53. } else {
  54. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  55. }
  56. }
  57. },
  58. fail: async res => {
  59. wx.redirectTo({ url: '/pages/index/index' })
  60. }
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () { },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. }
  95. })