student-confirm.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import dayjs from 'dayjs'
  2. import { Button } from 'vant'
  3. import { defineComponent } from 'vue'
  4. import Student from '../../components/student'
  5. import styles from './student-confirm.module.less'
  6. export default defineComponent({
  7. name: 'studentConfirm',
  8. props: {
  9. courseInfo: {
  10. type: Object,
  11. default: {}
  12. },
  13. studentObject: {
  14. type: Object,
  15. default: {}
  16. },
  17. onSubmit: {
  18. type: Function,
  19. default: (item: any) => {}
  20. }
  21. },
  22. computed: {
  23. timer() {
  24. const item: any = this.courseInfo
  25. return (
  26. dayjs(item.startTime).format('YYYY/MM/DD HH:mm') +
  27. ' ~ ' +
  28. dayjs(item.endTime).format('HH:mm')
  29. )
  30. },
  31. addStudents() {
  32. const { addStudents } = this.studentObject
  33. return addStudents || []
  34. },
  35. removeStudents() {
  36. const { removeStudents } = this.studentObject
  37. return removeStudents || []
  38. },
  39. calcTimer() {
  40. const { addStudents, removeStudents } = this.studentObject
  41. const { singleCourseTime, studentCount } = this.courseInfo
  42. const suffix: number = addStudents.length - removeStudents.length
  43. console.log(suffix, singleCourseTime, this.courseInfo)
  44. const type = suffix >= 0 ? 'add' : 'remove'
  45. console.log(
  46. addStudents,
  47. removeStudents,
  48. 'addStudents',
  49. suffix,
  50. type,
  51. studentCount
  52. )
  53. // n * (n -1) * 分钟数 * 课次数
  54. // 总分钟数
  55. const allMinutes = studentCount * singleCourseTime
  56. //
  57. const reTime = Math.abs(
  58. Math.abs(suffix + studentCount) * singleCourseTime
  59. )
  60. return {
  61. type,
  62. mins: Math.abs(allMinutes - reTime)
  63. }
  64. }
  65. },
  66. render() {
  67. return (
  68. <div class={styles.studentConfirm}>
  69. <div class={[styles.confirmTitle, 'van-hairline--bottom']}>
  70. <p>您将为{this.courseInfo.groupName}</p>
  71. <p class={styles.timer}>{this.timer}</p>
  72. </div>
  73. <div class={styles.studentList}>
  74. {this.addStudents.length > 0 && (
  75. <>
  76. <p class={styles.addTitle}>
  77. 添加学员 <span>{this.addStudents.length}</span> 名
  78. </p>
  79. {this.addStudents.map((item: any) => (
  80. <Student border={false} item={item} />
  81. ))}
  82. </>
  83. )}
  84. {this.removeStudents.length > 0 && (
  85. <>
  86. <p class={styles.addTitle}>
  87. 移除学员 <span>{this.removeStudents.length}</span> 名
  88. </p>
  89. {this.removeStudents.map((item: any) => (
  90. <Student border={false} item={item} />
  91. ))}
  92. </>
  93. )}
  94. </div>
  95. <p class={styles.calc}>
  96. 调整后将{this.calcTimer.type === 'remove' ? '释放' : '冻结'}{' '}
  97. <span>{this.calcTimer.mins}</span> 分钟
  98. </p>
  99. <div class={styles.btnGroup}>
  100. <Button
  101. type="primary"
  102. round
  103. block
  104. onClick={() => {
  105. const { userIdList } = this.studentObject
  106. this.onSubmit(userIdList)
  107. }}
  108. >
  109. 确认调整
  110. </Button>
  111. </div>
  112. </div>
  113. )
  114. }
  115. })