student-confirm.tsx 2.9 KB

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