school.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/school/school.js
  2. import { getApi, postApi } from "../../apis/api";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. school: {},
  9. noticeList: [],
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad(options) {
  15. this.getSchoolInfo();
  16. },
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onReady() {},
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow() {
  25. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  26. this.getTabBar().setData({
  27. selected: 5,
  28. });
  29. }
  30. },
  31. /**
  32. * 生命周期函数--监听页面隐藏
  33. */
  34. onHide() {},
  35. /**
  36. * 生命周期函数--监听页面卸载
  37. */
  38. onUnload() {},
  39. /**
  40. * 页面相关事件处理函数--监听用户下拉动作
  41. */
  42. onPullDownRefresh() {},
  43. /**
  44. * 页面上拉触底事件的处理函数
  45. */
  46. onReachBottom() {},
  47. /**
  48. * 用户点击右上角分享
  49. */
  50. share(e) {
  51. this.setData({
  52. shareNoticeId: e.currentTarget.dataset.id,
  53. shareNoticeTitle: e.currentTarget.dataset.title,
  54. });
  55. },
  56. onShareAppMessage() {
  57. return {
  58. title: this.data.shareNoticeTitle,
  59. path: `/pages/school/sharePage/sharePage?noticeId=${this.data.shareNoticeId}`,
  60. };
  61. },
  62. makePhoneCall(e) {
  63. const phone = e.currentTarget.dataset.phone;
  64. if (phone) {
  65. wx.makePhoneCall({
  66. phoneNumber: phone,
  67. });
  68. } else {
  69. wx.showToast({
  70. title: "电话号码不存在",
  71. icon: "none",
  72. });
  73. }
  74. },
  75. async getSchoolTrainingNoticeList() {
  76. let { data } = await postApi("/crew/school/training/notices", {
  77. currentPage: 1,
  78. size: 1000,
  79. crewSchoolId: this.data.school.id,
  80. });
  81. if (data.status === 0) {
  82. this.setData({
  83. noticeList: data.result,
  84. });
  85. } else {
  86. this.setData({
  87. noticeList: [],
  88. });
  89. }
  90. },
  91. async getSchoolInfo() {
  92. let { data } = await getApi("/crew/school/info", {});
  93. if (data.status === 0) {
  94. this.setData({
  95. school: data.result,
  96. });
  97. this.getSchoolTrainingNoticeList();
  98. } else {
  99. this.setData({
  100. school: {},
  101. });
  102. }
  103. },
  104. });