classSchedule.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view>
  3. <u-navbar back-text="课程表">
  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="dot" :class="activeClass == index ? 'dot-checked' : ''">
  24. </view>
  25. <view class="week ">
  26. {{item.week}}
  27. </view>
  28. <view class="day ">
  29. {{item.day}}
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 课表信息 -->
  34. <view class="class-box">
  35. <view class="picture">
  36. <img src="../../../assets/img/classschedule.png" alt="">
  37. </view>
  38. <view class="infos">
  39. <view class="title">
  40. 中国舞十级班
  41. </view>
  42. <view class="tag">
  43. <view class="item">
  44. 二楼舞蹈一教室
  45. </view>
  46. <view class="item">
  47. 08:30-10:00
  48. </view>
  49. </view>
  50. <view class="else">
  51. <view class="teacher">
  52. <view class="photo">
  53. <img src="../../../assets/img/teachercard.png" alt="">
  54. </view>
  55. <view class="name">
  56. 陈老师
  57. </view>
  58. </view>
  59. <view class="class-times">
  60. <view class="text">
  61. 课次
  62. </view>
  63. <view class="num">
  64. 22
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. date: '',
  77. weekDate: [],
  78. weekN: ["一", "二", "三", "四", "五", "六", "日"],
  79. activeClass: 0,
  80. weekDate1: '',
  81. }
  82. },
  83. onReady() {
  84. this.getToday();
  85. },
  86. methods: {
  87. getToday() {
  88. this.weekDate = [];
  89. let date = new Date(); //当前日期
  90. let year = date.getFullYear(); //当前年
  91. let month = date.getMonth() + 1; //当前月
  92. let day = date.getDate(); //当天
  93. let mydate = new Date(year, month - 1, day);
  94. let weekday = mydate.getDay();
  95. this.weekDate1 = new Date(year, month - 1, day + 1 - weekday);
  96. this.getWeekDate(true);
  97. },
  98. getWeekDate(bl) {
  99. let weekDate2 = new Date(this.weekDate1.getTime());
  100. for (var i = 0; i < 7; i++) {
  101. for (var j = 0; j < this.weekN.length; j++) {
  102. if (i == j) {
  103. this.weekDate.push({
  104. week: this.weekN[j],
  105. day: this.getFormatDate(new Date(weekDate2.setDate(this.weekDate1.getDate() + i)))
  106. })
  107. }
  108. }
  109. }
  110. if (bl) {
  111. let date = new Date(); //当前日期
  112. date = this.getFormatDate(date);
  113. for (var m = 0; m < this.weekDate.length; m++) {
  114. if (date == this.weekDate[m].day) {
  115. this.activeClass = m;
  116. this.date = this.weekDate[m].day;
  117. }
  118. }
  119. }
  120. },
  121. getFormatDate(date) {
  122. let myyear = date.getFullYear();
  123. let mymonth = date.getMonth() + 1;
  124. let myweekday = date.getDate();
  125. if (mymonth < 10) {
  126. mymonth = "0" + mymonth;
  127. }
  128. if (myweekday < 10) {
  129. myweekday = "0" + myweekday;
  130. }
  131. return (myyear + "-" + mymonth + "-" + myweekday);
  132. },
  133. beforeWeek() {
  134. console.log(this.activeClass)
  135. this.weekDate = [];
  136. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() - 7));
  137. this.getWeekDate();
  138. for (var m = 0; m < this.weekDate.length; m++) {
  139. if (this.activeClass == m) {
  140. this.date = this.weekDate[m].day;
  141. }
  142. }
  143. },
  144. afterWeek() {
  145. this.weekDate = [];
  146. this.weekDate1 = new Date(this.weekDate1.setDate(this.weekDate1.getDate() + 7));
  147. this.getWeekDate();
  148. for (var m = 0; m < this.weekDate.length; m++) {
  149. if (this.activeClass == m) {
  150. this.date = this.weekDate[m].day;
  151. }
  152. }
  153. },
  154. activeClassClick(item, index) {
  155. this.activeClass = index;
  156. for (var m = 0; m < this.weekDate.length; m++) {
  157. if (index == m) {
  158. this.date = this.weekDate[m].day;
  159. }
  160. }
  161. },
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. // 日期
  167. .date-picker {
  168. background-color: #fff;
  169. display: flex;
  170. justify-content: space-between;
  171. padding: 10px 12px 17px 12px;
  172. color: rgba(13, 186, 199, 1);
  173. .date {
  174. font-size: 16px;
  175. color: #333333;
  176. }
  177. }
  178. .date-item {
  179. background-color: #fff;
  180. display: flex;
  181. justify-content: space-around;
  182. padding: 0 12px 16px 12px;
  183. border-radius: 0px 0px 9px 9px;
  184. box-shadow: 0px 4px 4px 0px #CFD2D5;
  185. .item {
  186. line-height: 20px;
  187. border-radius: 8px;
  188. background-color: rgba(238, 238, 238, 1);
  189. color: #1C222A;
  190. text-align: center;
  191. width: 12%;
  192. padding: 12rpx 0;
  193. position: relative;
  194. .week {
  195. font-size: 12px;
  196. }
  197. .day {
  198. font-size: 16px;
  199. font-weight: bold;
  200. }
  201. }
  202. .checked {
  203. background-color: rgba(13, 186, 199, 1);
  204. color: #fff;
  205. }
  206. .dot {
  207. width: 6px;
  208. height: 6px;
  209. background-color: rgba(13, 186, 199, 1);
  210. border-radius: 999px;
  211. position: absolute;
  212. top: 8rpx;
  213. right: 8rpx;
  214. }
  215. .dot-checked {
  216. background-color: #fff;
  217. }
  218. }
  219. // 课表信息
  220. .class-box {
  221. margin: 12px 16px;
  222. padding: 24rpx 0 24rpx 24rpx;
  223. border-radius: 24rpx;
  224. background-color: rgba(255, 255, 255, 1);
  225. display: flex;
  226. .picture {
  227. width: 200rpx;
  228. height: 200rpx;
  229. border-radius: 4px;
  230. overflow: hidden;
  231. img {
  232. width: 100%;
  233. height: 100%;
  234. }
  235. }
  236. .infos {
  237. margin-left: 24rpx;
  238. display: flex;
  239. flex-direction: column;
  240. justify-content: space-between;
  241. flex: 1;
  242. .title {
  243. color: rgba(51, 51, 51, 1);
  244. font-size: 16px;
  245. font-weight: bold;
  246. }
  247. .tag {
  248. display: flex;
  249. .item {
  250. line-height: 40rpx;
  251. border-radius: 8rpx;
  252. background-color: rgba(241, 243, 244, 1);
  253. color: rgba(16, 16, 16, 1);
  254. text-align: center;
  255. margin-right: 12rpx;
  256. font-size: 24rpx;
  257. padding: 0 8rpx;
  258. }
  259. @media screen and (max-width: 310px) {
  260. .item {
  261. padding: 0 4rpx;
  262. margin-right: 8rpx;
  263. }
  264. }
  265. }
  266. .else {
  267. display: flex;
  268. justify-content: space-between;
  269. padding-right: 24rpx;
  270. .teacher {
  271. display: flex;
  272. align-items: center;
  273. .photo {
  274. width: 64rpx;
  275. height: 64rpx;
  276. border-radius: 50px;
  277. overflow: hidden;
  278. img {
  279. width: 100%;
  280. height: 100%;
  281. }
  282. }
  283. .name {
  284. color: rgba(16, 16, 16, 1);
  285. margin-left: 12px;
  286. }
  287. }
  288. .class-times {
  289. display: flex;
  290. align-items: center;
  291. .text {
  292. color: rgba(119, 119, 119, 1);
  293. font-size: 16px;
  294. }
  295. .num {
  296. line-height: 20px;
  297. border-radius: 4px;
  298. background-color: rgba(13, 186, 199, 1);
  299. color: rgba(255, 255, 255, 1);
  300. text-align: center;
  301. margin-left: 8rpx;
  302. padding: 0 4px;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. /deep/.u-slot-content {
  309. display: block;
  310. text-align: right !important;
  311. margin-right: 16px;
  312. color: #333333;
  313. }
  314. </style>