weeklyCalendar.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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, 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. console.log(setDate(date))
  103. this.startTime = getNowDateAndMonday(setDate(date))
  104. if (this.active === -1) {
  105. this.active = 0
  106. this.tableTime = this.startTime;
  107. }
  108. this.endTime = getNowDateAndSunday(setDate(date))
  109. },
  110. getCalendatList () {
  111. this.teacherIdList = this.$route.query.teacherId
  112. // 获取本周的周一和周日
  113. this.setStartTimeAndEndTime(this.week)
  114. superFindCourseSchedules({ teacherIdList: this.teacherIdList, rows: 9999, page: 1, startTime: this.startTime, endTime: this.endTime }).then(res => {
  115. if (res.code === 200) {
  116. this.dataList = res.data.rows
  117. // 过滤数据
  118. this.vipList = []
  119. this.teamList = []
  120. this.newList = []
  121. for (let i in this.dataList) {
  122. this.setCourseTime(this.dataList[i])
  123. if (this.dataList[i].groupType === 'VIP') {
  124. this.vipList.push(this.dataList[i])
  125. }
  126. if (this.dataList[i].groupType === 'MUSIC') {
  127. this.teamList.push(this.dataList[i])
  128. }
  129. if (this.dataList[i].groupType === 'PRACTICE') {
  130. this.newList.push(this.dataList[i])
  131. }
  132. }
  133. }
  134. })
  135. },
  136. setCourseTime (row) {
  137. let startMinutes = this.getMinutes(row.startClassTime.split(' ')[1])
  138. let endMinutes = this.getMinutes(row.endClassTime.split(' ')[1])
  139. let width = (endMinutes - startMinutes) * 1.8
  140. let left = startMinutes - 240 > 0 ? (startMinutes - 240) * 1.8 + 17 : 17
  141. let top = getWeekDay(row.classDate) === 1 ? 40 : (getWeekDay(row.classDate) * 60) - 16
  142. row.style = {
  143. 'width': width + 'px',
  144. 'top': top + 'px',
  145. 'left': left + 'px'
  146. }
  147. },
  148. getMinutes (str) {
  149. return parseInt(str.split(':')[0]) * 60 + parseInt(str.split(':')[1])
  150. },
  151. setWeekList () {
  152. this.weekList = []
  153. let startTime = new Date(this.startTime.replace(/-/g, "/"))
  154. startTime.setTime(startTime.getTime() - 1000 * 60 * 60 * 24)
  155. for (let i = 0; i < 7; i++) {
  156. startTime.setTime(startTime.getTime() + 1000 * 60 * 60 * 24)
  157. // startTime.setTime(startTime.getTime() - 1000 * 60 * 60 * 24)
  158. this.weekList.push({
  159. week: this.weekDay[i],
  160. dateStr: startTime.getMonth() + 1 + '月' + startTime.getDate() + '日',
  161. date: setDate(startTime)
  162. })
  163. }
  164. },
  165. setWeekDotList (item, index) {
  166. this.active = index;
  167. this.tableTime = item.date
  168. },
  169. changeWeek (val) {
  170. this.week = val;
  171. this.active = -1;
  172. this.getCalendatList()
  173. this.setWeekList()
  174. },
  175. },
  176. directives: {
  177. drag (el) {
  178. // 拖拽大图片移动
  179. let oDiv = el; //当前元素
  180. let self = this; //上下文
  181. oDiv.onmousedown = function (e) {
  182. //鼠标按下,计算当前元素距离可视区的距离
  183. let disX = e.clientX - oDiv.offsetLeft;
  184. let disY = e.clientY - oDiv.offsetTop;
  185. let wrapW = document.querySelector('.timer').offsetWidth
  186. let imgW = document.querySelector('.imgWrap').offsetWidth
  187. document.onmousemove = function (e) {
  188. //通过事件委托,计算移动的距离
  189. let l = e.clientX - disX;
  190. let t = e.clientY - disY;
  191. //移动当前元素
  192. if (l > 0) {
  193. l = 0;
  194. } else if (l < -(imgW - wrapW) + 2) {
  195. l = -(imgW - wrapW) + 2
  196. }
  197. oDiv.style.left = l + "px";
  198. // oDiv.style.top = t + "px";
  199. }
  200. document.onmouseup = function (e) {
  201. document.onmousemove = null;
  202. document.onmouseup = null;
  203. };
  204. return false;
  205. };
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .timeWrap {
  212. margin-top: 20px;
  213. display: flex;
  214. flex-direction: row;
  215. justify-content: flex-start;
  216. .timer {
  217. width: 1478px;
  218. overflow: auto;
  219. position: relative;
  220. .imgWrap {
  221. width: 2194px;
  222. position: relative;
  223. z-index: 1;
  224. img {
  225. width: 2194px;
  226. position: relative;
  227. z-index: 1;
  228. }
  229. .dot {
  230. -moz-user-select: none; /*火狐*/
  231. -webkit-user-select: none; /*webkit浏览器*/
  232. -ms-user-select: none; /*IE10*/
  233. user-select: none;
  234. cursor: pointer;
  235. position: absolute;
  236. min-width: 30px;
  237. height: 25px;
  238. color: #fff;
  239. font-size: 14px;
  240. line-height: 25px;
  241. padding-left: 5px;
  242. z-index: 10;
  243. top: 40px;
  244. right: 0;
  245. border-radius: 3px;
  246. }
  247. .vipDot {
  248. background: linear-gradient(
  249. to left,
  250. rgba(42, 174, 166, 0.75),
  251. rgba(42, 174, 166, 1)
  252. );
  253. }
  254. .newDot {
  255. background: linear-gradient(
  256. to left,
  257. rgba(52, 177, 246, 0.75),
  258. rgba(52, 177, 246, 1)
  259. );
  260. }
  261. .teamDot {
  262. background: linear-gradient(
  263. to left,
  264. rgba(90, 121, 246, 0.75),
  265. rgba(90, 121, 246, 1)
  266. );
  267. }
  268. }
  269. }
  270. .weekDotList {
  271. margin: 24px 10px 0 0;
  272. width: 70px;
  273. display: flex;
  274. flex-direction: column;
  275. background-color: #fff;
  276. .weekDot {
  277. cursor: pointer;
  278. -moz-user-select: none; /*火狐*/
  279. -webkit-user-select: none; /*webkit浏览器*/
  280. -ms-user-select: none; /*IE10*/
  281. user-select: none;
  282. width: 70px;
  283. height: 60px;
  284. background-color: #fff;
  285. color: #fff;
  286. padding: 10px 0 10px 10px;
  287. border-radius: 5px;
  288. color: #000;
  289. p {
  290. font-size: 12px;
  291. line-height: 20px;
  292. }
  293. .week {
  294. font-size: 12px;
  295. color: #999;
  296. }
  297. .date {
  298. font-size: 12px;
  299. color: #333;
  300. }
  301. }
  302. .weekDot.active {
  303. background-color: rgba(19, 129, 122, 1);
  304. color: #fff !important;
  305. border-radius: 5px;
  306. .week {
  307. font-size: 12px;
  308. color: #fff;
  309. }
  310. .date {
  311. font-size: 14px;
  312. color: #fff;
  313. }
  314. }
  315. }
  316. }
  317. </style>