classSchedule.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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-box">
  10. <view class="date-picker">
  11. <view class="check" @click="beforeWeek">
  12. <u-icon name="arrow-left" size="32"></u-icon>前一周
  13. </view>
  14. <view class="date" @click="show = true">
  15. {{date}}
  16. </view>
  17. <view class="check" @click="afterWeek">
  18. 后一周<u-icon name="arrow-right" size="32"></u-icon>
  19. </view>
  20. </view>
  21. <u-picker mode="time" v-model="show" :params="params" :defaultTime="defaultTime" @confirm="confirm">
  22. </u-picker>
  23. <view class="date-item">
  24. <view class="item" v-for="(item,index) in weekDate" :key="index"
  25. :class="activeClass == index ? 'checked' : ''" @click="activeClassClick(item,index)">
  26. <view :class="item.isDotShow ? 'dot' : ''" :style="activeClass == index ? 'background-color: #fff;' : ''">
  27. </view>
  28. <view class="week ">
  29. {{item.week}}
  30. </view>
  31. <view class="day ">
  32. {{parseInt(item.day.slice(8))}}
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 课表信息 -->
  38. <!-- <view class="courses-learned">
  39. 已学课程
  40. </view> -->
  41. <view class="main">
  42. <view class="class-box" v-for="(item,index) in courseList" :key="index"
  43. @click="gotoUrl('pages/parents/classSchedule/classScheduleDetails?id=' + item.sheetId)">
  44. <view class="picture">
  45. <img v-if="item.posterUrl!=null" :src="item.posterUrl" alt="">
  46. <img v-else src="../../../assets/img/classschedule.png" alt="">
  47. </view>
  48. <view class="infos">
  49. <view class="title">
  50. {{item.className}}
  51. </view>
  52. <view class="tag">
  53. <view class="item">
  54. {{item.classroomName}}
  55. </view>
  56. <view class="item">
  57. {{item.coursePeriods}}
  58. </view>
  59. </view>
  60. <view class="else">
  61. <view class="teacher">
  62. <view class="photo">
  63. <u-avatar class="avatar"
  64. :src="item.headPhoto != null ? item.headPhoto : '../../../assets/img/teachercard.png'" size="64">
  65. </u-avatar>
  66. </view>
  67. <view class="name">
  68. {{item.teacherNames}}老师
  69. </view>
  70. </view>
  71. <view class="class-times">
  72. <view class="text">
  73. 课次
  74. </view>
  75. <view class="num">
  76. {{item.courseAmount + item.freeAmount}}
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- <view class="courses-learned">
  84. 未学课程
  85. </view> -->
  86. <!-- <view class="class-box">
  87. <view class="picture">
  88. <img src="../../../assets/img/classschedule.png" alt="">
  89. </view>
  90. <view class="infos">
  91. <view class="title">
  92. 中国舞十级班
  93. </view>
  94. <view class="tag">
  95. <view class="item">
  96. 二楼舞蹈一教室
  97. </view>
  98. <view class="item">
  99. 08:30-10:00
  100. </view>
  101. </view>
  102. <view class="else">
  103. <view class="teacher">
  104. <view class="photo">
  105. <img src="../../../assets/img/teachercard.png" alt="">
  106. </view>
  107. <view class="name">
  108. 陈老师
  109. </view>
  110. </view>
  111. <view class="class-times">
  112. <view class="text">
  113. 课次
  114. </view>
  115. <view class="num">
  116. 22
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </view> -->
  122. </view>
  123. </template>
  124. <script>
  125. import * as classScheduleApi from '@/apis/parents/classSchedule.js'
  126. export default {
  127. data() {
  128. return {
  129. date: '',
  130. weekDate: [],
  131. weekN: ["一", "二", "三", "四", "五", "六", "日"],
  132. activeClass: 0,
  133. weekDate1: '',
  134. courseList: [],
  135. studentId: '',
  136. defaultTime: '',
  137. params: {
  138. year: true,
  139. month: true,
  140. day: true,
  141. hour: false,
  142. minute: false,
  143. second: false,
  144. timestamp: true
  145. },
  146. show: false,
  147. }
  148. },
  149. onReady() {
  150. if(this.carhelp.getStudentId()) {
  151. this.studentId = this.carhelp.getStudentId().studentId;
  152. }
  153. this.getToday();
  154. },
  155. methods: {
  156. confirm(params) {
  157. this.weekDate = [];
  158. let pickerDate = params.year + "-" + params.month + "-" + params.day;
  159. let year = params.year;
  160. let month = parseInt(params.month);
  161. let day = parseInt(params.day);
  162. let mydate = new Date(year, month - 1, day);
  163. let weekday = mydate.getDay();
  164. this.weekDate1 = new Date(year, month - 1, day + 1 - weekday);
  165. this.getWeekDate();
  166. for (var m = 0; m < this.weekDate.length; m++) {
  167. if (pickerDate == this.weekDate[m].day) {
  168. this.activeClass = m;
  169. this.date = this.weekDate[m].day;
  170. }
  171. }
  172. this.getCourseList();
  173. },
  174. getCourseList() {
  175. this.courseList = [];
  176. uni.showLoading({
  177. title: "加载中",
  178. mask: true,
  179. })
  180. classScheduleApi.loadMySchedule({
  181. studentId: this.studentId,
  182. startDate: this.weekDate[0].day,
  183. endDate: this.weekDate[6].day
  184. }).then((response) => {
  185. uni.hideLoading();
  186. var list = response.data;
  187. for (var i = 0; i < list.length; i++) {
  188. if(this.date == list[i].courseDate) {
  189. this.courseList.push(list[i]);
  190. }
  191. for (var j = 0; j < this.weekDate.length; j++) {
  192. if(this.weekDate[j].day == list[i].courseDate) {
  193. this.weekDate[j].isDotShow = true;
  194. }
  195. }
  196. }
  197. }).catch(error => {
  198. uni.showToast({
  199. title: error,
  200. icon: "none"
  201. })
  202. })
  203. },
  204. getToday() {
  205. this.weekDate = [];
  206. let date = new Date(); //当前日期
  207. let year = date.getFullYear(); //当前年
  208. let month = date.getMonth() + 1; //当前月
  209. let day = date.getDate(); //当天
  210. let mydate = new Date(year, month - 1, day);
  211. let weekday = mydate.getDay();
  212. this.weekDate1 = new Date(year, month - 1, day + 1 - weekday);
  213. this.getWeekDate(true);
  214. },
  215. getWeekDate(bl) {
  216. let weekDate2 = new Date(this.weekDate1.getTime());
  217. for (var i = 0; i < 7; i++) {
  218. for (var j = 0; j < this.weekN.length; j++) {
  219. if (i == j) {
  220. var weekDate3=new Date(weekDate2.getTime()+i*24*60*60*1000);
  221. this.weekDate.push({
  222. week: this.weekN[j],
  223. day: this.getFormatDate(weekDate3),
  224. isDotShow: false
  225. })
  226. }
  227. }
  228. }
  229. if (bl) {
  230. let date = new Date(); //当前日期
  231. date = this.getFormatDate(date);
  232. for (var m = 0; m < this.weekDate.length; m++) {
  233. if (date == this.weekDate[m].day) {
  234. this.activeClass = m;
  235. this.date = this.weekDate[m].day;
  236. }
  237. }
  238. this.getCourseList();
  239. }
  240. },
  241. getFormatDate(date) {
  242. let myyear = date.getFullYear();
  243. let mymonth = date.getMonth() + 1;
  244. let myweekday = date.getDate();
  245. if (mymonth < 10) {
  246. mymonth = "0" + mymonth;
  247. }
  248. if (myweekday < 10) {
  249. myweekday = "0" + myweekday;
  250. }
  251. return (myyear + "-" + mymonth + "-" + myweekday);
  252. },
  253. beforeWeek() {
  254. this.weekDate = [];
  255. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() - 7));
  256. this.getWeekDate();
  257. for (var m = 0; m < this.weekDate.length; m++) {
  258. if (this.activeClass == m) {
  259. this.date = this.weekDate[m].day;
  260. }
  261. }
  262. this.getCourseList();
  263. },
  264. afterWeek() {
  265. this.weekDate = [];
  266. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() + 7));
  267. this.getWeekDate();
  268. for (var m = 0; m < this.weekDate.length; m++) {
  269. if (this.activeClass == m) {
  270. this.date = this.weekDate[m].day;
  271. }
  272. }
  273. this.getCourseList();
  274. },
  275. activeClassClick(item, index) {
  276. this.activeClass = index;
  277. for (var m = 0; m < this.weekDate.length; m++) {
  278. if (index == m) {
  279. this.date = this.weekDate[m].day;
  280. }
  281. }
  282. this.getCourseList();
  283. },
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. // 日期
  289. .date-box{
  290. position: fixed;
  291. top: 88rpx;
  292. left:0;
  293. right:0;
  294. }
  295. .date-picker {
  296. background-color: #fff;
  297. display: flex;
  298. justify-content: space-between;
  299. padding: 10px 12px 17px 12px;
  300. color: rgba(13, 186, 199, 1);
  301. .date {
  302. font-size: 16px;
  303. color: #333333;
  304. }
  305. }
  306. .date-item {
  307. background-color: #fff;
  308. display: flex;
  309. justify-content: space-around;
  310. padding: 0 12px 16px 12px;
  311. border-radius: 0px 0px 9px 9px;
  312. box-shadow: 0px 4px 4px 0px #CFD2D5;
  313. .item {
  314. line-height: 20px;
  315. border-radius: 8px;
  316. background-color: rgba(238, 238, 238, 1);
  317. color: #1C222A;
  318. text-align: center;
  319. width: 12%;
  320. padding: 12rpx 0;
  321. position: relative;
  322. .week {
  323. font-size: 12px;
  324. }
  325. .day {
  326. font-size: 16px;
  327. font-weight: bold;
  328. }
  329. }
  330. .checked {
  331. background-color: rgba(13, 186, 199, 1);
  332. color: #fff;
  333. }
  334. .dot {
  335. width: 6px;
  336. height: 6px;
  337. background-color: rgba(13, 186, 199, 1);
  338. border-radius: 999px;
  339. position: absolute;
  340. top: 8rpx;
  341. right: 8rpx;
  342. }
  343. .dot-checked {
  344. background-color: #fff;
  345. }
  346. }
  347. // 课表信息
  348. .main{
  349. margin-top: 256rpx;
  350. }
  351. .courses-learned{
  352. margin-top: 40rpx;
  353. padding: 0 32rpx;
  354. color: rgba(51, 51, 51, 1);
  355. font-size: 16px;
  356. font-weight: bold;
  357. }
  358. .class-box {
  359. margin: 24rpx 32rpx;
  360. padding: 24rpx 0 24rpx 24rpx;
  361. border-radius: 24rpx;
  362. background-color: rgba(255, 255, 255, 1);
  363. display: flex;
  364. .picture {
  365. width: 200rpx;
  366. height: 200rpx;
  367. border-radius: 4px;
  368. overflow: hidden;
  369. img {
  370. width: 100%;
  371. height: 100%;
  372. }
  373. }
  374. .infos {
  375. margin-left: 24rpx;
  376. display: flex;
  377. flex-direction: column;
  378. justify-content: space-between;
  379. flex: 1;
  380. .title {
  381. color: rgba(51, 51, 51, 1);
  382. font-size: 16px;
  383. font-weight: bold;
  384. }
  385. .tag {
  386. display: flex;
  387. .item {
  388. line-height: 40rpx;
  389. border-radius: 8rpx;
  390. background-color: rgba(241, 243, 244, 1);
  391. color: rgba(16, 16, 16, 1);
  392. text-align: center;
  393. margin-right: 12rpx;
  394. font-size: 24rpx;
  395. padding: 0 8rpx;
  396. }
  397. @media screen and (max-width: 310px) {
  398. .item {
  399. padding: 0 4rpx;
  400. margin-right: 8rpx;
  401. }
  402. }
  403. }
  404. .else {
  405. display: flex;
  406. justify-content: space-between;
  407. padding-right: 24rpx;
  408. .teacher {
  409. display: flex;
  410. align-items: center;
  411. .photo {
  412. width: 64rpx;
  413. height: 64rpx;
  414. border-radius: 50px;
  415. overflow: hidden;
  416. img {
  417. width: 100%;
  418. height: 100%;
  419. }
  420. }
  421. .name {
  422. color: rgba(16, 16, 16, 1);
  423. margin-left: 12px;
  424. }
  425. }
  426. .class-times {
  427. display: flex;
  428. align-items: center;
  429. .text {
  430. color: rgba(119, 119, 119, 1);
  431. font-size: 16px;
  432. }
  433. .num {
  434. line-height: 20px;
  435. border-radius: 4px;
  436. background-color: rgba(13, 186, 199, 1);
  437. color: rgba(255, 255, 255, 1);
  438. text-align: center;
  439. margin-left: 8rpx;
  440. padding: 0 4px;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. ::v-deep.u-slot-content {
  447. display: block;
  448. text-align: right !important;
  449. margin-right: 16px;
  450. color: #333333;
  451. }
  452. </style>