weeklyCalendar.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="m-container">
  3. <el-date-picker v-model="week"
  4. type="week"
  5. format="yyyy-MM 第 WW 周"
  6. placeholder="选择周"
  7. @change="changeWeek"
  8. :picker-options="{
  9. firstDayOfWeek:1
  10. }">
  11. </el-date-picker>
  12. <div class="timeWrap">
  13. <div class="weekDotList">
  14. <div class="weekDot"
  15. @click="setWeekDotList(item,index)"
  16. :class="index==active?'active':''"
  17. v-for="(item,index) in weekList"
  18. :key='index'>
  19. <p class="week">{{item.week}}</p>
  20. <p class="date">{{item.dateStr}}</p>
  21. </div>
  22. </div>
  23. <div class="timer">
  24. <div class="imgWrap"
  25. v-drag>
  26. <img :src="timerImg">
  27. <div v-for="(item,index) in newList"
  28. :key="index+'new'">
  29. <el-popover placement="top"
  30. trigger="hover">
  31. <p>课程名称:{{item.name}}</p>
  32. <p>上课时间:{{item.startClassTime.split(' ')[1].substring(0,5)+'~'+item.endClassTime.split(' ')[1].substring(0,5)}}</p>
  33. <div slot="reference"
  34. :style="item.style"
  35. class="newDot dot">网</div>
  36. </el-popover>
  37. </div>
  38. <div v-for="(item,index) in vipList"
  39. :key="index+'vip'">
  40. <el-popover placement="top"
  41. trigger="hover">
  42. <p>课程名称:{{item.name}}</p>
  43. <p>上课时间:{{item.startClassTime.split(' ')[1].substring(0,5)+'~'+item.endClassTime.split(' ')[1].substring(0,5)}}</p>
  44. <div slot="reference"
  45. :style="item.style"
  46. class="vipDot dot">vip</div>
  47. </el-popover>
  48. </div>
  49. <div v-for="(item,index) in teamList"
  50. :key="index+'team'">
  51. <el-popover placement="top"
  52. trigger="hover">
  53. <p>课程名称:{{item.name}}</p>
  54. <p>上课时间:{{item.startClassTime.split(' ')[1].substring(0,5)+'~'+item.endClassTime.split(' ')[1].substring(0,5)}}</p>
  55. <div slot="reference"
  56. :style="item.style"
  57. class="teamDot dot">乐</div>
  58. </el-popover>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <resetList :startTimes="tableTime"
  64. @getCalendatList='getCalendatList' />
  65. </div>
  66. </template>
  67. <script>
  68. import { superFindCourseSchedules } from "@/api/buildTeam";
  69. import { setDate, getCurrentMonthFirst, getCurrentMonthLast, getNowDateAndSunday, getNowDateAndMonday, getWeekDay } from "@/utils/date"
  70. import resetList from './resetComponent'
  71. export default {
  72. components: { resetList },
  73. data () {
  74. return {
  75. timerImg: require('@/views/teacherManager/teacherDetail/components/weekUitl/weekTimer.png'),
  76. active: -1,
  77. week: new Date(),
  78. weekList: [],
  79. startTime: '',
  80. endTime: '',
  81. vipList: [],
  82. teamList: [],
  83. newList: [],
  84. weekDay: [
  85. "周一",
  86. "周二",
  87. "周三",
  88. "周四",
  89. "周五",
  90. "周六",
  91. "周日",
  92. ],
  93. tableTime: ''
  94. }
  95. },
  96. mounted () {
  97. this.getCalendatList()
  98. this.setWeekList()
  99. },
  100. methods: {
  101. setStartTimeAndEndTime (date) {
  102. this.startTime = getNowDateAndMonday(setDate(date))
  103. if (this.active === -1) {
  104. this.active = 0
  105. this.tableTime = this.startTime;
  106. }
  107. this.endTime = getNowDateAndSunday(setDate(date))
  108. },
  109. getCalendatList () {
  110. this.teacherIdList = this.$route.query.teacherId
  111. // 获取本周的周一和周日
  112. this.setStartTimeAndEndTime(this.week)
  113. superFindCourseSchedules({ teacherIdList: this.teacherIdList, rows: 9999, page: 1, startTime: this.startTime, endTime: this.endTime }).then(res => {
  114. if (res.code === 200) {
  115. this.dataList = res.data.rows
  116. // 过滤数据
  117. this.vipList = []
  118. this.teamList = []
  119. this.newList = []
  120. for (let i in this.dataList) {
  121. this.setCourseTime(this.dataList[i])
  122. if (this.dataList[i].groupType === 'VIP') {
  123. this.vipList.push(this.dataList[i])
  124. }
  125. if (this.dataList[i].groupType === 'MUSIC') {
  126. this.teamList.push(this.dataList[i])
  127. }
  128. if (this.dataList[i].groupType === 'PRACTICE') {
  129. this.newList.push(this.dataList[i])
  130. }
  131. }
  132. }
  133. })
  134. },
  135. setCourseTime (row) {
  136. let startMinutes = this.getMinutes(row.startClassTime.split(' ')[1])
  137. let endMinutes = this.getMinutes(row.endClassTime.split(' ')[1])
  138. let width = (endMinutes - startMinutes) * 1.8
  139. let left = startMinutes - 240 > 0 ? (startMinutes - 240) * 1.8 + 17 : 17
  140. let top = getWeekDay(row.classDate) === 1 ? 40 : (getWeekDay(row.classDate) * 60) - 16
  141. row.style = {
  142. 'width': width + 'px',
  143. 'top': top + 'px',
  144. 'left': left + 'px'
  145. }
  146. },
  147. getMinutes (str) {
  148. return parseInt(str.split(':')[0]) * 60 + parseInt(str.split(':')[1])
  149. },
  150. setWeekList () {
  151. this.weekList = []
  152. let startTime = new Date(this.startTime.replace(/-/g, "/"))
  153. startTime.setTime(startTime.getTime() - 1000 * 60 * 60 * 24)
  154. for (let i = 0; i < 7; i++) {
  155. startTime.setTime(startTime.getTime() + 1000 * 60 * 60 * 24)
  156. // startTime.setTime(startTime.getTime() - 1000 * 60 * 60 * 24)
  157. this.weekList.push({
  158. week: this.weekDay[i],
  159. dateStr: startTime.getMonth() + 1 + '月' + startTime.getDate() + '日',
  160. date: setDate(startTime)
  161. })
  162. }
  163. },
  164. setWeekDotList (item, index) {
  165. this.active = index;
  166. this.tableTime = item.date
  167. },
  168. changeWeek (val) {
  169. this.week = val;
  170. this.active = -1;
  171. this.getCalendatList()
  172. this.setWeekList()
  173. },
  174. },
  175. directives: {
  176. drag (el) {
  177. let oDiv = el; //当前元素
  178. let self = this; //上下文
  179. //禁止选择网页上的文字
  180. // document.onselectstart = function () {
  181. // return false;
  182. // };
  183. oDiv.onmousedown = function (e) {
  184. //鼠标按下,计算当前元素距离可视区的距离
  185. let disX = e.clientX - oDiv.offsetLeft;
  186. let disY = e.clientY - oDiv.offsetTop;
  187. let wrapW = document.querySelector('.timer').offsetWidth
  188. let imgW = document.querySelector('.imgWrap').offsetWidth
  189. document.onmousemove = function (e) {
  190. //通过事件委托,计算移动的距离
  191. let l = e.clientX - disX;
  192. let t = e.clientY - disY;
  193. //移动当前元素
  194. if (l > 0) {
  195. l = 0;
  196. } else if (l < -(imgW - wrapW) + 2) {
  197. l = -(imgW - wrapW) + 2
  198. }
  199. oDiv.style.left = l + "px";
  200. // oDiv.style.top = t + "px";
  201. }
  202. document.onmouseup = function (e) {
  203. document.onmousemove = null;
  204. document.onmouseup = null;
  205. };
  206. //return false不加的话可能导致黏连,就是拖到一个地方时div粘在鼠标上不下来,相当于onmouseup失效
  207. return false;
  208. };
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .timeWrap {
  215. margin-top: 20px;
  216. display: flex;
  217. flex-direction: row;
  218. justify-content: flex-start;
  219. .timer {
  220. width: 1478px;
  221. overflow: auto;
  222. position: relative;
  223. .imgWrap {
  224. width: 2194px;
  225. position: relative;
  226. z-index: 1;
  227. img {
  228. width: 2194px;
  229. position: relative;
  230. z-index: 1;
  231. }
  232. .dot {
  233. -moz-user-select: none; /*火狐*/
  234. -webkit-user-select: none; /*webkit浏览器*/
  235. -ms-user-select: none; /*IE10*/
  236. user-select: none;
  237. cursor: pointer;
  238. position: absolute;
  239. min-width: 30px;
  240. height: 25px;
  241. color: #fff;
  242. font-size: 14px;
  243. line-height: 25px;
  244. padding-left: 5px;
  245. z-index: 10;
  246. top: 40px;
  247. right: 0;
  248. border-radius: 3px;
  249. }
  250. .vipDot {
  251. background: linear-gradient(
  252. to left,
  253. rgba(42, 174, 166, 0.75),
  254. rgba(42, 174, 166, 1)
  255. );
  256. }
  257. .newDot {
  258. background: linear-gradient(
  259. to left,
  260. rgba(52, 177, 246, 0.75),
  261. rgba(52, 177, 246, 1)
  262. );
  263. }
  264. .teamDot {
  265. background: linear-gradient(
  266. to left,
  267. rgba(90, 121, 246, 0.75),
  268. rgba(90, 121, 246, 1)
  269. );
  270. }
  271. }
  272. }
  273. .weekDotList {
  274. margin: 24px 10px 0 0;
  275. width: 70px;
  276. display: flex;
  277. flex-direction: column;
  278. background-color: #fff;
  279. .weekDot {
  280. cursor: pointer;
  281. -moz-user-select: none; /*火狐*/
  282. -webkit-user-select: none; /*webkit浏览器*/
  283. -ms-user-select: none; /*IE10*/
  284. user-select: none;
  285. width: 70px;
  286. height: 60px;
  287. background-color: #fff;
  288. color: #fff;
  289. padding: 10px 0 10px 10px;
  290. border-radius: 5px;
  291. color: #000;
  292. p {
  293. font-size: 12px;
  294. line-height: 20px;
  295. }
  296. .week {
  297. font-size: 12px;
  298. color: #999;
  299. }
  300. .date {
  301. font-size: 12px;
  302. color: #333;
  303. }
  304. }
  305. .weekDot.active {
  306. background-color: rgba(19, 129, 122, 1);
  307. color: #fff !important;
  308. border-radius: 5px;
  309. .week {
  310. font-size: 12px;
  311. color: #fff;
  312. }
  313. .date {
  314. font-size: 14px;
  315. color: #fff;
  316. }
  317. }
  318. }
  319. }
  320. </style>