detail.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="wrap">
  3. <u-navbar :autoBack="true" title="讲师" bgColor="rgba(255,255,255,255)" :placeholder="true" titleStyle="font-weight:bold;color:#121212"></u-navbar>
  4. <view class="user-view">
  5. <view class="b-avatar">
  6. <image :src="teacherData.avatar_url || '/static/imgs/user.png'" mode="aspectFill"></image>
  7. </view>
  8. <view class="b-info">
  9. <view class="s-name">{{ teacherData.name }}</view>
  10. <view class="s-title" v-if="teacherData.intro">{{ teacherData.intro }}</view>
  11. </view>
  12. </view>
  13. <view class="box">
  14. <!-- <view class="box-head">全部课程</view> -->
  15. <view class="box-main course-list">
  16. <course-item v-for="(item, index) in courseList" :key="index" :item="item"></course-item>
  17. </view>
  18. </view>
  19. <!-- 加载中 -->
  20. <load-more :loadingType="loadingType" :loadingText="loadingText"></load-more>
  21. <!-- 首页 -->
  22. <app-home></app-home>
  23. </view>
  24. </template>
  25. <script>
  26. // import {
  27. // getTeacherDetail,
  28. // getCourseList
  29. // } from '@/service/api/teacher.js'
  30. import mixinsCommon from '@/mixins/common.js';
  31. let that;
  32. export default {
  33. mixins: [mixinsCommon],
  34. data() {
  35. return {
  36. teacherData: {},
  37. courseList: [],
  38. loadingType: 1,
  39. loadingText: ''
  40. };
  41. },
  42. onLoad(options) {
  43. that = this;
  44. this.teacherId = options.id;
  45. this.$api.getTeacherDetail({ id: this.teacherId }, function (res) {
  46. console.log('getTeacherDetail', res);
  47. if (res.code == 1) {
  48. that.loadingType = -1;
  49. that.teacherData = res.data;
  50. uni.setNavigationBarTitle({
  51. title: res.data.name
  52. });
  53. } else {
  54. that.loadingType = 3;
  55. // this.loadingText = err.data.msg || '加载失败';
  56. }
  57. });
  58. // getTeacherDetail(this.teacherId).then(([err, res]) => {
  59. // console.log('getTeacherDetail', err, res);
  60. // if (!err) {
  61. // this.loadingType = -1;
  62. // this.teacherData = res;
  63. // uni.setNavigationBarTitle({
  64. // title: res.name
  65. // });
  66. // } else {
  67. // this.loadingType = 3;
  68. // this.loadingText = err.data.msg || '加载失败';
  69. // }
  70. // });
  71. this.loadCourseList(true);
  72. },
  73. onReachBottom() {
  74. if (this.loadingType !== 1 && this.loadingType !== 2) {
  75. this.loadCourseList();
  76. }
  77. },
  78. methods: {
  79. loadCourseList(refresh) {
  80. console.log('loadCourseList', refresh);
  81. if (refresh) {
  82. this.page = 1;
  83. this.courseList = [];
  84. } else {
  85. this.page++;
  86. }
  87. this.loadingType = 1;
  88. this.loadingText = '';
  89. this.$api.getCourseList(
  90. {
  91. teacherId: that.teacherId,
  92. page: that.page,
  93. page_size: 10
  94. },
  95. function (res) {
  96. console.log(res, 6565);
  97. that.loadingType = -1;
  98. if (res.code == 1) {
  99. if (res.data.items.length > 0) {
  100. that.courseList = [...that.courseList, ...res.data.items];
  101. } else {
  102. that.loadingType = 2;
  103. if (that.page == 1) {
  104. that.loadingText = '暂无数据';
  105. }
  106. that.page--; // 重置分页
  107. }
  108. } else {
  109. that.loadingType = 3;
  110. }
  111. }
  112. );
  113. // getCourseList(this.teacherId, this.page, 10).then(([err, res]) => {
  114. // console.log('getCourseList', err, res);
  115. // this.loadingType = -1;
  116. // if (!err) {
  117. // if (res.items.length > 0) {
  118. // this.courseList = [...this.courseList, ...res.items];
  119. // } else {
  120. // this.loadingType = 2;
  121. // if (this.page == 1) {
  122. // this.loadingText = '暂无数据';
  123. // }
  124. // this.page--; // 重置分页
  125. // }
  126. // } else {
  127. // this.loadingType = 3;
  128. // }
  129. // });
  130. }
  131. }
  132. };
  133. </script>
  134. <style>
  135. .wrap {
  136. background: #fff;
  137. }
  138. .user-view {
  139. padding: 50upx 0 50upx 0;
  140. display: flex;
  141. align-items: center;
  142. flex-direction: column;
  143. z-index: 1;
  144. background: #eee;
  145. }
  146. .user-view .b-avatar {
  147. width: 180upx;
  148. height: 180upx;
  149. }
  150. .user-view .b-avatar image {
  151. width: 180upx;
  152. height: 180upx;
  153. border: 5upx solid #fff;
  154. border-radius: 50%;
  155. }
  156. .user-view .b-info {
  157. margin-top: 20upx;
  158. display: flex;
  159. flex-direction: column;
  160. align-items: center;
  161. }
  162. .user-view .b-info .s-name {
  163. margin-top: 20upx;
  164. font-weight: bold;
  165. font-size: 32upx;
  166. color: #333;
  167. }
  168. .user-view .b-info .s-title {
  169. margin-top: 10upx;
  170. font-size: 28upx;
  171. color: #666;
  172. }
  173. .box {
  174. background: #fff;
  175. }
  176. .box .box-head {
  177. padding: 0 30upx;
  178. text-align: center;
  179. height: 100upx;
  180. line-height: 100upx;
  181. font-size: 30upx;
  182. color: #333;
  183. border-top: 2upx solid #eee;
  184. border-bottom: 2upx solid #eee;
  185. }
  186. .course-list .course-item {
  187. border-bottom: 1upx solid #eee;
  188. }
  189. .course-list .course-item:last-child {
  190. border-bottom: none;
  191. }
  192. </style>