elective-preference-command.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <span v-if="!group.allowSelect">{{ group.disabledReason || '无法报名' }}</span>
  3. <span v-else-if="isRejected">已拒绝</span>
  4. <span v-else-if="group.selected" class="f-red btn-red" @click="handleCancel">已报名/重新报名</span>
  5. <span v-else-if="enableCommit" class="f-warning">不能报名</span>
  6. <span v-else class="btn-green" @click="handleCommit">报名</span>
  7. </template>
  8. <script>
  9. import ElectiveToolsMixin from './elective-tools-mixins'
  10. import { submitElectiveModels } from '@/api/webApi/elective/selected-subject'
  11. export default {
  12. mixins: [ElectiveToolsMixin],
  13. name: 'elective-preference-command',
  14. props: ['generation', 'group'],
  15. inject: {
  16. refreshData: {
  17. default: function() {
  18. }
  19. }
  20. },
  21. computed: {
  22. selectedList() {
  23. return this.generation.activeModel.selectedList
  24. },
  25. isRejected() {
  26. return this.selectedList.some(this.isGroupRejected)
  27. },
  28. enableCommit() {
  29. return this.selectedList.length >= this.generation.status.preferenceCount
  30. },
  31. preferenceCount() {
  32. return this.generation.status.preferenceCount
  33. }
  34. },
  35. methods: {
  36. async handleCommit() {
  37. if (this.enableCommit) {
  38. this.$message.error(this.preferenceCount == 1 ? `只能填报1个志愿` : `最多只能填报${this.preferenceCount}个志愿`)
  39. return
  40. }
  41. if (this.preferenceCount > 1) {
  42. // 多志愿在elective-preference-drag中有确认环节,这里直接操作即可
  43. this.group.selected = true
  44. this.selectedList.push(this.group)
  45. } else {
  46. let confirmTip = `确认填报 ${this.group.groupName}`
  47. let extraDesc = ''
  48. if (this.generation.current > this.generation.options.primary.value) {
  49. extraDesc = this.group.isRecommend ? '(推荐)' : '(非推荐)'
  50. }
  51. confirmTip += extraDesc
  52. await this.$confirm(confirmTip)
  53. this.group.selected = true
  54. this.selectedList.push(this.group)
  55. try {
  56. await submitElectiveModels({ models: this.selectedList.map(g => ({ groupId: g.groupId })) })
  57. this.$message.success('报名成功')
  58. } finally {
  59. this.refreshData()
  60. }
  61. }
  62. },
  63. async handleCancel() {
  64. if (this.preferenceCount > 1) {
  65. // 同上
  66. this.group.selected = false
  67. this.selectedList.remove(this.group)
  68. } else {
  69. await this.$confirm(`确认取消填报 ${this.group.groupName}`)
  70. this.group.selected = false
  71. this.selectedList.remove(this.group)
  72. try {
  73. await submitElectiveModels({ models: this.selectedList.map(g => ({ groupId: g.groupId })) })
  74. this.$message.success('报名取消成功,您可以重新填报')
  75. } finally {
  76. this.refreshData()
  77. }
  78. }
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. </style>