elective-preference-command.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <span v-if="!group.allowSelect">{{ group.disabledReason || '无法报名' }}</span>
  3. <span v-else-if="group.selected" class="f-red btn-red" @click="handleCancel">取消报名</span>
  4. <span v-else-if="isRejected">已拒绝</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.activeModel.preferenceCount
  30. },
  31. preferenceCount() {
  32. return this.generation.activeModel.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. await this.$confirm(`确认填报 ${this.group.groupName}`)
  47. this.group.selected = true
  48. this.selectedList.push(this.group)
  49. try {
  50. await submitElectiveModels({ models: this.selectedList.map(g => g.groupId) })
  51. this.$message.success('报名成功')
  52. } finally {
  53. this.refreshData()
  54. }
  55. }
  56. },
  57. async handleCancel() {
  58. if (this.preferenceCount > 1) {
  59. // 同上
  60. this.group.selected = false
  61. this.selectedList.remove(this.group)
  62. } else {
  63. await this.$confirm(`确认取消填报 ${this.group.groupName}`)
  64. this.group.selected = false
  65. this.selectedList.remove(this.group)
  66. try {
  67. await submitElectiveModels({ models: this.selectedList.map(g => g.groupId) })
  68. this.$message.success('报名取消成功,您可以重新填报')
  69. } finally {
  70. this.refreshData()
  71. }
  72. }
  73. }
  74. }
  75. }
  76. </script>
  77. <style scoped>
  78. </style>