student-confirm.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // n * (n -1) * 分钟数 * 课次数
  46. // 总分钟数
  47. const allMinutes = (studentCount + 1) * studentCount * singleCourseTime
  48. //
  49. const reTime = Math.abs(
  50. (Math.abs(suffix) + 1) * suffix * singleCourseTime
  51. )
  52. return {
  53. type,
  54. mins: Math.abs(allMinutes - reTime)
  55. }
  56. }
  57. },
  58. render() {
  59. return (
  60. <div class={styles.studentConfirm}>
  61. <div class={[styles.confirmTitle, 'van-hairline--bottom']}>
  62. <p>您将为{this.courseInfo.groupName}</p>
  63. <p class={styles.timer}>{this.timer}</p>
  64. </div>
  65. <div class={styles.studentList}>
  66. {this.addStudents.length > 0 && (
  67. <>
  68. <p class={styles.addTitle}>
  69. 添加学员 <span>{this.addStudents.length}</span> 名
  70. </p>
  71. {this.addStudents.map((item: any) => (
  72. <Student border={false} item={item} />
  73. ))}
  74. </>
  75. )}
  76. {this.removeStudents.length > 0 && (
  77. <>
  78. <p class={styles.addTitle}>
  79. 移除学员 <span>{this.removeStudents.length}</span> 名
  80. </p>
  81. {this.removeStudents.map((item: any) => (
  82. <Student border={false} item={item} />
  83. ))}
  84. </>
  85. )}
  86. </div>
  87. <p class={styles.calc}>
  88. 调整后将{this.calcTimer.type === 'remove' ? '释放' : '冻结'}{' '}
  89. <span>{this.calcTimer.mins}</span> 分钟
  90. </p>
  91. <div class={styles.btnGroup}>
  92. <Button
  93. type="primary"
  94. round
  95. block
  96. onClick={() => {
  97. const { userIdList } = this.studentObject
  98. this.onSubmit(userIdList)
  99. }}
  100. >
  101. 确认调整
  102. </Button>
  103. </div>
  104. </div>
  105. )
  106. }
  107. })