eduDetail.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import {formatTime, formatYMD, getEventParam, showLoading, toast} from "../../utils/utils";
  2. import Api from "../../model/api";
  3. import User from "../../model/user";
  4. import {logicStatus, teamState, uploadResTypes} from "../../model/enum";
  5. import Route from "../../model/route";
  6. const app = getApp();
  7. app.Base({
  8. data: {
  9. teamId: '',
  10. isPre: logicStatus.NO,
  11. topClass: 'top',
  12. active: 0,
  13. stuPageNum: 1,
  14. stuPageSize: 5,
  15. courseStart: '',
  16. item: {},
  17. stuData: [],
  18. courseList: [],
  19. //点击课程提醒进入到的页面课程计划id
  20. scheduleId: null,
  21. },
  22. async bindLogin(e){
  23. const isLogin = getEventParam(e,"isLogin")
  24. if (isLogin) {
  25. this.resetData(this);
  26. await this.init();
  27. if (this.data.scheduleId) {
  28. //如果是从课程提醒中打开的页面,跳转到课程详情页
  29. this.jumpToCourseDetail();
  30. }
  31. }
  32. },
  33. async selectDate(e) {
  34. let courseStart = getEventParam(e, "date");
  35. this.data.courseStart = courseStart;
  36. await this.getCourseDate(this.data.item.eduStuId, true);
  37. },
  38. async getCourseDate(studentId, isLoading = false) {
  39. const res3 = await Api.getCourseSchedule({
  40. teamId: this.data.teamId,
  41. studentId,
  42. courseStart: this.data.courseStart,
  43. }, isLoading);
  44. res3.rows.forEach(item => {
  45. if (item.isOnline == logicStatus.YES) {
  46. item.isQuestion = item.suitangUpper;
  47. } else {
  48. item.isQuestion = item.suitangLower;
  49. }
  50. })
  51. this.setData({
  52. courseList: res3.rows,
  53. })
  54. },
  55. onLoad: async function (options) {
  56. this.noInit = true;
  57. let {teamId, scheduleId} = options;
  58. this.data.teamId = teamId;
  59. this.data.scheduleId = scheduleId;
  60. if (scheduleId) {
  61. this.switchPageTab(true);
  62. }
  63. },
  64. jumpToCourseDetail(){
  65. let scheduleId = this.data.scheduleId;
  66. const scheduleInfo = this.data.courseList.find(item => item.id == scheduleId);
  67. if (!scheduleInfo) {
  68. toast('课程不存在!');
  69. return;
  70. }
  71. // console.log(scheduleInfo);
  72. let $eduPlan = this.selectComponent('#eduPlan');
  73. // console.log('$eduPlan', $eduPlan);
  74. wx.nextTick(() => {
  75. $eduPlan.toLive(scheduleInfo);
  76. });
  77. //页面跳转后,置空
  78. this.data.scheduleId = null;
  79. // wx.nextTick(() =>{
  80. // // $eduPlan.scrollToSchedule(scheduleInfo);
  81. // // setTimeout(() => {
  82. // // $eduPlan.toLive(scheduleInfo);
  83. // // }, 1000);
  84. // });
  85. },
  86. async init() {
  87. showLoading();
  88. const [res1, res2] = await Api.promiseAllSettled([
  89. Api.getProjectsWithTeam(this.data.teamId),
  90. // Api.getStudentList({
  91. // teamId: this.data.teamId,
  92. // pageNum: this.data.stuPageNum,
  93. // pageSize: this.data.stuPageSize
  94. // }),
  95. Api.getStudentAvatorList({
  96. teamId: this.data.teamId,
  97. pageNum: this.data.stuPageNum,
  98. pageSize: this.data.stuPageSize
  99. }),
  100. ])
  101. wx.hideLoading();
  102. res1.data.forEach(item => {
  103. item.itemStart = formatYMD(item.itemStart);
  104. item.itemEnd = formatYMD(item.itemEnd);
  105. item.teamStart = formatYMD(item.teamStart),
  106. item.teamEnd = formatYMD(item.teamEnd)
  107. })
  108. const isPre = res1.data[0]['teamState'] == teamState.END ? logicStatus.YES : logicStatus.NO;
  109. const currentPages = getCurrentPages();
  110. if (currentPages[currentPages.length - 1] === "pages/eduDetail/eduDetail"){
  111. if (isPre == logicStatus.YES) {
  112. wx.setNavigationBarTitle({title: "往期培训"})
  113. } else {
  114. wx.setNavigationBarTitle({title: "培训"})
  115. }
  116. }
  117. this.setData({
  118. teamId: this.data.teamId,
  119. isPre,
  120. item: res1.data[0],
  121. stuData: res2.data,
  122. })
  123. await this.getCourseDate(res1.data[0].eduStuId, true);
  124. // if (this.data.scheduleId) {
  125. // this.jumpToCourseDetail();
  126. // }
  127. },
  128. async onPullDownRefresh() {
  129. await this.init();
  130. },
  131. onChange(e) {
  132. wx.createSelectorQuery().select('.container').boundingClientRect(function (rect) {
  133. wx.pageScrollTo({
  134. scrollTop: 0
  135. })
  136. }).exec()
  137. if ("介绍" == getEventParam(e, "title")) {
  138. this.switchPageTab(false, e);
  139. } else {
  140. this.switchPageTab(true, e);
  141. }
  142. },
  143. switchPageTab(isSchedule, e){
  144. let active;
  145. if (e) {
  146. active = getEventParam(e, "index");
  147. } else {
  148. active = isSchedule? 1 : 0;
  149. }
  150. this.setData({
  151. topClass: isSchedule? 'top-bg' : 'top',
  152. disableLoadMore: !!isSchedule,
  153. active,
  154. }, () => {
  155. this.selectComponent("#tabs")?.resize()
  156. });
  157. },
  158. async requestData() {
  159. const res = await Api.getTeamInteraction({
  160. teamId: this.data.teamId,
  161. pageNum: this.pageNum,
  162. pageSize: this.pageSize
  163. });
  164. res.data.rows.forEach(item => {
  165. if (item.attachmentUrlList && item.attachmentType == uploadResTypes.IMAGE) {
  166. let attachmentUrlList = item.attachmentUrlList || [];
  167. item.attachmentUrlList = attachmentUrlList.map(item => {
  168. return {
  169. url: item,
  170. isImage: true
  171. }
  172. })
  173. item.createTime = formatTime(item.createTime);
  174. }
  175. })
  176. return res;
  177. },
  178. onHandlePublish(e) {
  179. const isSuccess = getEventParam(e, "isSuccess");
  180. if (isSuccess) {
  181. this.onPullDownRefresh();
  182. }
  183. },
  184. refreshData() {
  185. console.log('refreshData');
  186. this.onPullDownRefresh();
  187. }
  188. });