index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import Calendar from '@/business-components/calendar'
  2. import request from '@/helpers/request'
  3. import { state } from '@/state'
  4. import Arrange from '@/teacher/live-class/create-components/arrange'
  5. import dayjs from 'dayjs'
  6. import {
  7. computed,
  8. defineComponent,
  9. nextTick,
  10. onMounted,
  11. reactive,
  12. ref,
  13. watch
  14. } from 'vue'
  15. import styles from './index.module.less'
  16. import { params as classInfo } from '../class-info'
  17. import { Button, Cell, Dialog, Popup, Sticky, Tag, Toast } from 'vant'
  18. import { getWeekCh } from '@/helpers/utils'
  19. import { useRouter } from 'vue-router'
  20. import CourseSchedule from '../course-schedule'
  21. export default defineComponent({
  22. name: 'createClass',
  23. props: {
  24. active: {
  25. type: Number,
  26. default: 1
  27. },
  28. onBack: {
  29. type: Function,
  30. default: () => () => {}
  31. }
  32. },
  33. setup(props) {
  34. watch(
  35. () => props.active,
  36. val => {
  37. // console.log(val)
  38. if (val === 2) {
  39. getList()
  40. }
  41. }
  42. )
  43. //日期设置
  44. const data = reactive({
  45. calendarList: {},
  46. selectList: []
  47. })
  48. const getList = async (date?: Date) => {
  49. const tempDate = date || dayjs().add(1, 'day').toDate()
  50. let params = {
  51. day: dayjs(tempDate).format('DD'),
  52. month: dayjs(tempDate).format('MM'),
  53. year: dayjs(tempDate).format('YYYY')
  54. }
  55. try {
  56. let res = await request.post(
  57. '/api-teacher/courseSchedule/createLiveCourseCalendar',
  58. {
  59. data: {
  60. ...params,
  61. singleCourseMinutes: classInfo.singleClassTime,
  62. freeCourseMinutes: classInfo.freeCourseMinutes,
  63. teacherId: state.user.data?.userId
  64. }
  65. }
  66. )
  67. const result = res.data || []
  68. let tempObj = {}
  69. result.forEach((item: any) => {
  70. tempObj[item.date] = item
  71. })
  72. data.calendarList = tempObj
  73. } catch {}
  74. }
  75. const onSelectDay = (res: any) => {
  76. // 对数组进行排序
  77. res.sort((first: any, second: any) => {
  78. if (first.startTime > second.startTime) return 1
  79. if (first.startTime < second.startTime) return -1
  80. return 0
  81. })
  82. data.selectList = res
  83. }
  84. const showSelectList = computed(() => {
  85. // 显示时间
  86. let list = [...data.selectList]
  87. list.forEach((item: any) => {
  88. item.title =
  89. dayjs(item.startTime).format('YYYY-MM-DD') +
  90. ' ' +
  91. getWeekCh(dayjs(item.startTime).day()) +
  92. ' ' +
  93. item.start +
  94. '~' +
  95. item.end
  96. })
  97. return list
  98. })
  99. const selectType = computed(() => {
  100. // 循环次数是否足够
  101. return data.selectList.length < classInfo.classNum ? 'noEnough' : 'enough'
  102. })
  103. const onCloseTag = (item: any) => {
  104. // 删除课程
  105. Dialog.confirm({
  106. title: '提示',
  107. message: '您是否要删除该选择的课程?',
  108. confirmButtonColor: 'var(--van-primary)'
  109. }).then(() => {
  110. const index = data.selectList.findIndex(
  111. (course: any) => course.startTime === item.startTime
  112. )
  113. data.selectList.splice(index, 1)
  114. })
  115. }
  116. const selectStatus = ref(false)
  117. const onSubmit = async () => {
  118. if (data.selectList.length <= 0) {
  119. Toast('请选择课程时间')
  120. return
  121. }
  122. if (data.selectList.length < classInfo.classNum) {
  123. selectStatus.value = true
  124. return
  125. }
  126. // await this._lookCourse()
  127. confirmShow.value = true
  128. }
  129. const onComfirm = async () => {
  130. if (selectType.value === 'noEnough') {
  131. let times = [] as any
  132. data.selectList.forEach((item: any) => {
  133. times.push({
  134. startTime: item.startTime,
  135. endTime: item.endTime
  136. })
  137. })
  138. console.log(data.selectList)
  139. const res = await request.post(
  140. '/api-teacher/courseGroup/lockCourseToCache',
  141. {
  142. data: {
  143. courseNum: classInfo.classNum,
  144. courseType: 'PIANO_ROOM_CLASS',
  145. loop: 1,
  146. teacherId: state.user.data?.userId,
  147. timeList: [...times]
  148. }
  149. }
  150. )
  151. if (res.code === 200) {
  152. res.data.forEach((n: any) => {
  153. n.start = dayjs(n.startTime).format('HH:mm')
  154. n.end = dayjs(n.endTime).format('HH:mm')
  155. })
  156. data.selectList = res.data
  157. }
  158. } else {
  159. selectStatus.value = false
  160. nextTick(() => {
  161. confirmShow.value = true
  162. })
  163. }
  164. }
  165. const router = useRouter()
  166. const confirmShow = ref(false)
  167. // 排课
  168. const onCourseSchedule = async () => {
  169. const timeList = data.selectList
  170. const n = classInfo.studentIds.length + 1
  171. try {
  172. let { code, data } = await request.post(
  173. '/api-teacher/courseSchedule/arrangeCourse',
  174. {
  175. data: {
  176. classNum: classInfo.classNum, //课时数
  177. consumeTime: Math.ceil(
  178. n * classInfo.classNum * parseInt(classInfo.singleClassTime)
  179. ), //消耗时长
  180. courseName: classInfo.courseName, //课程名称
  181. singleClssTime: classInfo.singleClassTime, //单课时长
  182. studentIds: classInfo.studentIds.map(n => n.userId), //学员id集合
  183. subjectId: classInfo.subjectId, //声部id
  184. timeList
  185. }
  186. }
  187. )
  188. if (code === 200) {
  189. confirmShow.value = false
  190. setTimeout(() => {
  191. Toast({
  192. icon: 'success',
  193. message: '排课成功',
  194. duration: 1500,
  195. onClose: () => {
  196. router.back()
  197. }
  198. })
  199. }, 100)
  200. }
  201. } catch (error) {}
  202. }
  203. return () => {
  204. return (
  205. <div class={styles.createClass}>
  206. {props.active === 2 && (
  207. <Calendar
  208. maxDays={classInfo.classNum}
  209. list={data.calendarList}
  210. prevMonth={(date: Date) => getList(date)}
  211. nextMonth={(date: Date) => getList(date)}
  212. selectDay={onSelectDay}
  213. selectList={data.selectList}
  214. isSkipHolidays={classInfo.isSkipHolidays}
  215. />
  216. )}
  217. <Cell
  218. class={[styles.arrangeCell, 'mb12']}
  219. v-slots={{
  220. title: () => (
  221. <div class={styles.rTitle}>
  222. <span>已选择课程时间</span>
  223. </div>
  224. ),
  225. label: () => (
  226. <div class={styles.rTag}>
  227. {showSelectList.value.map((item: any) => (
  228. <>
  229. <Tag
  230. plain
  231. round
  232. closeable
  233. size="large"
  234. type="primary"
  235. class={styles.tag}
  236. onClose={() => onCloseTag(item)}
  237. >
  238. {item.title}
  239. </Tag>
  240. <br />
  241. </>
  242. ))}
  243. </div>
  244. )
  245. }}
  246. ></Cell>
  247. <Sticky offsetBottom={0} position="bottom">
  248. <div class={['btnGroup', 'btnMore']}>
  249. <Button
  250. block
  251. round
  252. type="primary"
  253. plain
  254. onClick={() => {
  255. props.onBack && props.onBack()
  256. // 重置选择的课次
  257. data.selectList = []
  258. }}
  259. >
  260. 上一步
  261. </Button>
  262. <Button block round type="primary" onClick={() => onSubmit()}>
  263. 下一步
  264. </Button>
  265. </div>
  266. </Sticky>
  267. {/* <Arrange /> */}
  268. <Popup show={selectStatus.value} class={styles.selectPopup}>
  269. <div class={styles.selectContainer}>
  270. <div class={styles.rTitle}>
  271. <span>提示</span>
  272. </div>
  273. <div class={styles.selectPopupContent}>
  274. <p class={styles.desc}>
  275. {selectType.value === 'noEnough'
  276. ? '您所选择的上课时间未达到您输入的课时数,系统根据已选时间将自动按周顺延排课。'
  277. : '您已选择以下上课时间段,时间段会暂时锁定,锁定期间学员不可购买该时间段课程。'}
  278. </p>
  279. {selectType.value === 'enough' && (
  280. <p class={styles.times}>
  281. {data.selectList.map((item: any) => (
  282. <span>
  283. {dayjs(item.startTime || new Date()).format(
  284. 'YYYY-MM-DD'
  285. )}{' '}
  286. {dayjs(item.startTime || new Date()).format('HH:mm')}~
  287. {dayjs(item.endTime || new Date()).format('HH:mm')}
  288. </span>
  289. ))}
  290. </p>
  291. )}
  292. </div>
  293. <div class={styles.selectBtn}>
  294. <Button
  295. class={styles.btn}
  296. type="primary"
  297. round
  298. block
  299. plain
  300. onClick={() => (selectStatus.value = false)}
  301. >
  302. {selectType.value === 'noEnough' ? '继续选择' : '重新选择'}
  303. </Button>
  304. <Button
  305. class={styles.btn}
  306. type="primary"
  307. round
  308. block
  309. onClick={() => onComfirm()}
  310. >
  311. 确认
  312. </Button>
  313. </div>
  314. </div>
  315. </Popup>
  316. {/* 确认排课 */}
  317. <Popup
  318. position="bottom"
  319. class={styles.coursePopup}
  320. v-model:show={confirmShow.value}
  321. closeable
  322. round
  323. >
  324. <CourseSchedule
  325. curriculum={data.selectList}
  326. onClose={() => {
  327. confirmShow.value = false
  328. }}
  329. onComfirm={() => {
  330. onCourseSchedule()
  331. }}
  332. />
  333. </Popup>
  334. </div>
  335. )
  336. }
  337. }
  338. })