info.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. const app = getApp()
  2. const util = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '羽校信息', leftArrow: true, useBar: false },
  9. id: '',
  10. // 选中
  11. tabs: {
  12. active: '0',
  13. menu: [
  14. { title: '羽校信息', active: '0' },
  15. { title: '师资信息', active: '1' },
  16. { title: '学员信息', active: '2' },
  17. { title: '课程信息', active: '3' },
  18. ]
  19. },
  20. // 学校详细信息
  21. info: {},
  22. // 师资信息
  23. teacherList: [],
  24. // 学员信息
  25. studentList: [],
  26. // 课程信息
  27. lessonList: [],
  28. // 分页
  29. total: 0,
  30. page: 0,
  31. skip: 0,
  32. limit: 10,
  33. // 字典表
  34. // 教练等级
  35. levelList: [],
  36. // 课程类型
  37. typeList: [],
  38. // 课程状态
  39. statusList: [],
  40. //运动等级
  41. stlevelList: [],
  42. },
  43. // 跳转菜单
  44. back(e) {
  45. wx.navigateBack({ delta: 1 })
  46. },
  47. // 清空列表
  48. clearPage() {
  49. const that = this;
  50. that.setData({ teacherList: [], studentList: [], lessonList: [], skip: 0, limit: 10, page: 0 })
  51. },
  52. // 选项卡选择
  53. tabsChange: function (e) {
  54. const that = this;
  55. let data = e.detail;
  56. that.setData({ 'tabs.active': data.active });
  57. if (data.active == '1' || data.active == '2' || data.active == '3') {
  58. that.clearPage();
  59. that.search();
  60. }
  61. },
  62. // 公共跳转
  63. toCommon(e) {
  64. const { route, id } = e.currentTarget.dataset;
  65. wx.navigateTo({ url: `/pagesSchool/${route}?id=${id}` })
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad: async function (options) {
  71. const that = this;
  72. that.setData({ id: options.id || '6355f251cb0f85380e83520b' });
  73. await that.searchOther();
  74. await that.search();
  75. },
  76. // 查询信息
  77. async search() {
  78. const that = this;
  79. let id = that.data.id;
  80. if (id) {
  81. let res = await app.$get(`/school/${id}`)
  82. if (res.errcode == '0') { that.setData({ info: res.data }) }
  83. else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  84. // 查询师资信息
  85. that.searchCoach();
  86. // 查询学员信息
  87. that.searchStu();
  88. // 查询课程信息
  89. that.searchLess();
  90. }
  91. },
  92. // 查询师资信息
  93. async searchCoach() {
  94. const that = this;
  95. let id = that.data.id;
  96. let info = { skip: that.data.skip, limit: that.data.limit, school_id: id }
  97. const arr = await app.$get(`/rcs`, { ...info });
  98. if (arr.errcode == '0') {
  99. let list = [...that.data.teacherList, ...arr.data];
  100. // 教练等级
  101. for (const val of list) {
  102. if (val.coach_id_phone) val.coach_id_phone = util.hidePhone(val.coach_id_phone);
  103. val.zhLevel = that.searchLevel(val.coach_id_level)
  104. }
  105. that.setData({ teacherList: list });
  106. that.setData({ total: arr.total })
  107. }
  108. },
  109. // 教練等級
  110. searchLevel: function (e) {
  111. const that = this;
  112. let levelList = that.data.levelList;
  113. let data = levelList.find(i => i.value == e);
  114. if (data) return data.label;
  115. else return '暂无'
  116. },
  117. // 查询学员信息
  118. async searchStu() {
  119. const that = this;
  120. let id = that.data.id;
  121. let info = { skip: that.data.skip, limit: that.data.limit, school_id: id }
  122. const arr = await app.$get(`/rss`, { ...info });
  123. if (arr.errcode == '0') {
  124. let list = [...that.data.studentList, ...arr.data];
  125. for (const val of list) {
  126. if (val.student_id_phone) val.student_id_phone = util.hidePhone(val.student_id_phone);
  127. val.student_id_zhlevel = that.searchstLevel(val.student_id_level)
  128. }
  129. that.setData({ studentList: list });
  130. that.setData({ total: arr.total })
  131. }
  132. },
  133. // 运动等级
  134. searchstLevel: function (e) {
  135. const that = this;
  136. let stlevelList = that.data.stlevelList;
  137. let data = stlevelList.find(i => i.value == e);
  138. if (data) return data.label;
  139. else return '暂无'
  140. },
  141. // 查询课程信息
  142. async searchLess() {
  143. const that = this;
  144. let id = that.data.id;
  145. let info = { skip: that.data.skip, limit: that.data.limit, school_id: id }
  146. const arr = await app.$get(`/lesson`, { ...info });
  147. if (arr.errcode == '0') {
  148. let list = [...that.data.lessonList, ...arr.data];
  149. for (const val of list) {
  150. val.zhType = that.searchType(val.type);
  151. val.zhStatus = that.searchStatus(val.status);
  152. }
  153. that.setData({ lessonList: list });
  154. that.setData({ total: arr.total })
  155. }
  156. },
  157. // 课程类型
  158. searchType: function (e) {
  159. const that = this;
  160. let typeList = that.data.typeList;
  161. let data = typeList.find(i => i.value == e);
  162. if (data) return data.label;
  163. else return '暂无'
  164. },
  165. // 课程状态
  166. searchStatus: function (e) {
  167. const that = this;
  168. let statusList = that.data.statusList;
  169. let data = statusList.find(i => i.value == e);
  170. if (data) return data.label;
  171. else return '暂无'
  172. },
  173. // 分页
  174. toPage: function () {
  175. const that = this;
  176. let active = that.data.tabs.active;
  177. let list = [];
  178. if (active == '1') list = that.data.teacherList;
  179. else if (active == '2') list = that.data.studentList;
  180. else if (active == '3') list = that.data.lessonList;
  181. let limit = that.data.limit;
  182. if (that.data.total > list.length) {
  183. wx.showLoading({ title: '加载中', mask: true })
  184. let page = that.data.page + 1;
  185. that.setData({ page: page })
  186. let skip = page * limit;
  187. that.setData({ skip: skip })
  188. that.search();
  189. wx.hideLoading()
  190. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  191. },
  192. // 查询其他信息
  193. searchOther: async function () {
  194. const that = this;
  195. let arr;
  196. // 教练等级
  197. arr = await app.$get(`/dict`, { code: 'coach_grade' })
  198. if (arr.errcode == '0' && arr.total > 0) {
  199. let data = arr.data[0];
  200. if (data.list && data.list.length > 0) that.setData({ levelList: data.list })
  201. }
  202. // 课程类型
  203. arr = await app.$get(`/dict`, { code: 'lesson_type' })
  204. if (arr.errcode == '0' && arr.total > 0) {
  205. let data = arr.data[0];
  206. if (data.list && data.list.length > 0) that.setData({ typeList: data.list })
  207. }
  208. // 课程状态
  209. arr = await app.$get(`/dict`, { code: 'lesson_status' })
  210. if (arr.errcode == '0' && arr.total > 0) {
  211. let data = arr.data[0];
  212. if (data.list && data.list.length > 0) that.setData({ statusList: data.list })
  213. }
  214. // 运动等级
  215. arr = await app.$get(`/dict`, { code: 'student_grade' });
  216. if (arr.errcode == '0' && arr.total > 0) {
  217. let list = arr.data[0].list;
  218. that.setData({ stlevelList: list })
  219. }
  220. },
  221. /**
  222. * 生命周期函数--监听页面初次渲染完成
  223. */
  224. onReady: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面显示
  228. */
  229. onShow: function () {
  230. },
  231. /**
  232. * 生命周期函数--监听页面隐藏
  233. */
  234. onHide: function () {
  235. },
  236. /**
  237. * 生命周期函数--监听页面卸载
  238. */
  239. onUnload: function () {
  240. },
  241. /**
  242. * 页面相关事件处理函数--监听用户下拉动作
  243. */
  244. onPullDownRefresh: function () {
  245. },
  246. /**
  247. * 页面上拉触底事件的处理函数
  248. */
  249. onReachBottom: function () {
  250. },
  251. /**
  252. * 用户点击右上角分享
  253. */
  254. onShareAppMessage: function () {
  255. }
  256. })