myCourse.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view>
  3. <u-navbar title="我的课表">
  4. <view class="slot-wrap" @click="getToday()">
  5. 今天
  6. </view>
  7. </u-navbar>
  8. <!-- 日期 -->
  9. <view class="date-picker">
  10. <view class="check" @click="beforeWeek">
  11. <u-icon name="arrow-left" size="32"></u-icon>前一周
  12. </view>
  13. <view class="date">
  14. {{date}}
  15. </view>
  16. <view class="check" @click="afterWeek">
  17. 后一周<u-icon name="arrow-right" size="32"></u-icon>
  18. </view>
  19. </view>
  20. <view class="date-item">
  21. <view class="item" v-for="(item,index) in weekDate" :key="index"
  22. :class="activeClass == index ? 'checked' : ''" @click="activeClassClick(item,index)">
  23. <view :class="item.isDotShow ? 'dot' : ''"
  24. :style="activeClass == index ? 'background-color: #fff;' : ''">
  25. </view>
  26. <view class="week ">
  27. {{item.week}}
  28. </view>
  29. <view class="day ">
  30. {{parseInt(item.day.slice(8))}}
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 课表信息 -->
  35. <view class="class-infos">
  36. <view class="info-box" v-for="(item,index) in courseList" :key="index"
  37. @click="gotoUrl('pages/teacher/myCourse/CourseDetails?id=' + item.sheetId)">
  38. <view class="infos">
  39. <view class="time">
  40. <img src="../../../assets/img/riLine-time-line@1x.png" alt="">
  41. {{item.coursePeriods!=null ? item.coursePeriods : '线下约时间'}}
  42. </view>
  43. <view class="class-name">
  44. {{item.className}}
  45. </view>
  46. <view class="location">
  47. {{item.classroomName}}
  48. </view>
  49. </view>
  50. <view class="icon">
  51. <u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- <u-divider>没有更多数据了</u-divider> -->
  56. </view>
  57. </template>
  58. <script>
  59. import * as myCourseApi from '@/apis/teacher/myCourse.js'
  60. export default {
  61. data() {
  62. return {
  63. date: '',
  64. weekDate: [],
  65. weekN: ["一", "二", "三", "四", "五", "六", "日"],
  66. activeClass: 0,
  67. weekDate1: '',
  68. courseList: [],
  69. teacherId: ''
  70. }
  71. },
  72. onReady() {
  73. this.getToday();
  74. },
  75. methods: {
  76. getCourseList() {
  77. this.courseList = [];
  78. uni.showLoading({
  79. title: "加载中",
  80. mask: true,
  81. })
  82. myCourseApi.loadMySchedule({
  83. startDate: this.weekDate[0].day,
  84. endDate: this.weekDate[6].day
  85. }).then((response) => {
  86. uni.hideLoading();
  87. var list = response.data;
  88. for (var i = 0; i < list.length; i++) {
  89. if (this.date == list[i].courseDate) {
  90. this.courseList.push(list[i]);
  91. }
  92. for (var j = 0; j < this.weekDate.length; j++) {
  93. if (this.weekDate[j].day == list[i].courseDate) {
  94. this.weekDate[j].isDotShow = true;
  95. }
  96. }
  97. }
  98. }).catch(error => {
  99. uni.showToast({
  100. title: error,
  101. icon: "none"
  102. })
  103. })
  104. },
  105. getToday() {
  106. this.weekDate = [];
  107. let date = new Date(); //当前日期
  108. let year = date.getFullYear(); //当前年
  109. let month = date.getMonth() + 1; //当前月
  110. let day = date.getDate(); //当天
  111. let mydate = new Date(year, month - 1, day);
  112. let weekday = mydate.getDay();
  113. this.weekDate1 = new Date(year, month - 1, day + 1 - weekday);
  114. this.getWeekDate(true);
  115. },
  116. getWeekDate(bl) {
  117. let weekDate2 = new Date(this.weekDate1.getTime());
  118. for (var i = 0; i < 7; i++) {
  119. for (var j = 0; j < this.weekN.length; j++) {
  120. if (i == j) {
  121. this.weekDate.push({
  122. week: this.weekN[j],
  123. day: this.getFormatDate(new Date(weekDate2.setDate(this.weekDate1.getDate() + i))),
  124. isDotShow: false
  125. })
  126. }
  127. }
  128. }
  129. if (bl) {
  130. let date = new Date(); //当前日期
  131. date = this.getFormatDate(date);
  132. for (var m = 0; m < this.weekDate.length; m++) {
  133. if (date == this.weekDate[m].day) {
  134. this.activeClass = m;
  135. this.date = this.weekDate[m].day;
  136. }
  137. }
  138. this.getCourseList();
  139. }
  140. },
  141. getFormatDate(date) {
  142. let myyear = date.getFullYear();
  143. let mymonth = date.getMonth() + 1;
  144. let myweekday = date.getDate();
  145. if (mymonth < 10) {
  146. mymonth = "0" + mymonth;
  147. }
  148. if (myweekday < 10) {
  149. myweekday = "0" + myweekday;
  150. }
  151. return (myyear + "-" + mymonth + "-" + myweekday);
  152. },
  153. beforeWeek() {
  154. this.weekDate = [];
  155. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() - 7));
  156. this.getWeekDate();
  157. for (var m = 0; m < this.weekDate.length; m++) {
  158. if (this.activeClass == m) {
  159. this.date = this.weekDate[m].day;
  160. }
  161. }
  162. this.getCourseList();
  163. },
  164. afterWeek() {
  165. this.weekDate = [];
  166. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() + 7));
  167. this.getWeekDate();
  168. for (var m = 0; m < this.weekDate.length; m++) {
  169. if (this.activeClass == m) {
  170. this.date = this.weekDate[m].day;
  171. }
  172. }
  173. this.getCourseList();
  174. },
  175. activeClassClick(item, index) {
  176. this.activeClass = index;
  177. for (var m = 0; m < this.weekDate.length; m++) {
  178. if (index == m) {
  179. this.date = this.weekDate[m].day;
  180. }
  181. }
  182. this.getCourseList();
  183. },
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. // 日期
  189. .date-picker {
  190. background-color: #fff;
  191. display: flex;
  192. justify-content: space-between;
  193. padding: 10px 12px 17px 12px;
  194. color: rgba(13, 186, 199, 1);
  195. .date {
  196. font-size: 16px
  197. }
  198. }
  199. .date-item {
  200. background-color: #fff;
  201. display: flex;
  202. justify-content: space-around;
  203. padding: 0 12px 16px 12px;
  204. border-radius: 0px 0px 9px 9px;
  205. box-shadow: 0px 4px 4px 0px #CFD2D5;
  206. .item {
  207. line-height: 20px;
  208. border-radius: 8px;
  209. background-color: rgba(238, 238, 238, 1);
  210. color: #1C222A;
  211. text-align: center;
  212. width: 12%;
  213. padding: 12rpx 0;
  214. position: relative;
  215. .week {
  216. font-size: 12px;
  217. }
  218. .day {
  219. font-size: 16px;
  220. font-weight: bold;
  221. }
  222. }
  223. .checked {
  224. background-color: rgba(13, 186, 199, 1);
  225. color: #fff;
  226. }
  227. .dot {
  228. width: 6px;
  229. height: 6px;
  230. background-color: rgba(13, 186, 199, 1);
  231. border-radius: 999px;
  232. position: absolute;
  233. top: 8rpx;
  234. right: 8rpx;
  235. }
  236. .dot-checked {
  237. background-color: #fff;
  238. }
  239. }
  240. // 课表信息
  241. .class-infos {
  242. padding: 0 15px;
  243. margin-bottom: 24rpx;
  244. .info-box {
  245. border-radius: 12px;
  246. background-color: rgba(255, 255, 255, 1);
  247. margin-top: 12px;
  248. padding: 16px 20px;
  249. display: flex;
  250. justify-content: space-between;
  251. align-items: center;
  252. .infos {
  253. .time {
  254. line-height: 20px;
  255. color: rgba(16, 16, 16, 1);
  256. display: flex;
  257. align-items: center;
  258. img {
  259. width: 16px;
  260. height: 16px;
  261. margin-right: 4px;
  262. }
  263. }
  264. .class-name {
  265. margin-top: 4px;
  266. line-height: 28px;
  267. color: rgba(51, 51, 51, 1);
  268. font-size: 20px;
  269. font-weight: bold;
  270. }
  271. .location {
  272. line-height: 16px;
  273. color: rgba(119, 119, 119, 1);
  274. font-size: 14px;
  275. margin-top: 4px;
  276. }
  277. }
  278. }
  279. }
  280. /deep/.u-slot-content {
  281. display: block;
  282. text-align: right !important;
  283. margin-right: 16px;
  284. color: #333333;
  285. }
  286. </style>