score-batch-popup.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <uv-popup ref="popup" mode="bottom" round="16" closeable @change="handleChange">
  3. <view class="fx-row fx-cen-cen h-[50px]">
  4. <view class="text-lg font-bold text-main">修改分数/批次</view>
  5. </view>
  6. <score-form ref="form" :model="modelCopy"/>
  7. <view class="px-20">
  8. <uv-line margin="5px 0 0 0"/>
  9. <uv-cell title="选择批次:" is-link title-style="font-size: 14px; color: #333333;" @click="openBatchList">
  10. <template #value>
  11. <view v-if="batchCopy.batch" class="fx-row items-center text-lg">
  12. {{ batchCopy.name }}
  13. <uv-tags v-if="batchCopy.recommand" text="重点推荐" size="tiny" type="error" shape="circle"
  14. class="ml-5 pointer-events-none"/>
  15. </view>
  16. </template>
  17. </uv-cell>
  18. </view>
  19. <view class="px-40 h-[60px] fx-row fx-cen-cen">
  20. <uv-button class="!flex-1" shape="circle" type="primary" text="确认修改" @click="handleConfirm"/>
  21. </view>
  22. </uv-popup>
  23. <uv-action-sheet ref="actionSheet" :actions="formatList" @select="handleBatchSelection"/>
  24. </template>
  25. <script setup>
  26. import {ref, computed, watch} from 'vue';
  27. import _ from 'lodash';
  28. import ScoreForm from "@/pages/voluntary/index/components/score-form.vue";
  29. import {useInjectVoluntaryForm} from "@/pages/voluntary/hooks/useVoluntaryFormInjection";
  30. import {useInjectVoluntaryCart} from "@/pages/voluntary/hooks/useVoluntaryCartInjection";
  31. import {toast} from "@/uni_modules/uv-ui-tools/libs/function";
  32. import {confirmAsync} from "@/utils/uni-helper";
  33. const emits = defineEmits(['change'])
  34. const popup = ref(null)
  35. const form = ref(null)
  36. const show = ref(false)
  37. const actionSheet = ref(null)
  38. const modelCopy = ref({})
  39. const batchCopy = ref({})
  40. const listCopy = ref([])
  41. const {model, batch, batchList, getBatchList} = useInjectVoluntaryForm()
  42. const {selectedList} = useInjectVoluntaryCart()
  43. const formatList = computed(() => {
  44. return listCopy.value.map(i => ({...i, subname: i.recommand ? '重点推荐' : ''}))
  45. })
  46. const openBatchList = () => {
  47. actionSheet.value.open()
  48. }
  49. const handleBatchSelection = (item) => {
  50. batchCopy.value = item
  51. }
  52. const reloadBatchListDebounce = _.debounce(async (score) => {
  53. // score for debounce validation
  54. if (score != modelCopy.value.score) return
  55. const list = await getBatchList(modelCopy.value)
  56. if (score != modelCopy.value.score) return
  57. listCopy.value = list
  58. // validate current batch
  59. const fired = list.find(b => b.batch == batchCopy.value.batch) || {}
  60. batchCopy.value = fired
  61. }, 800)
  62. const handleConfirm = async () => {
  63. await form.value.validate()
  64. if (!batchCopy.value?.batch) return toast('请选择批次')
  65. // wait user confirm
  66. const change = batch.value.batch != batchCopy.value.batch ||
  67. model.value.score != modelCopy.value.score ||
  68. model.value.seatInput != modelCopy.value.seatInput
  69. if (change && selectedList.value.length) await confirmAsync('修改将清空当前志愿表')
  70. // apply to real models
  71. _.assign(model.value, modelCopy.value)
  72. batch.value = batchCopy.value
  73. batchList.value = listCopy.value
  74. // popup hidden
  75. close()
  76. }
  77. const open = () => {
  78. // make copy from real models
  79. modelCopy.value = _.clone(model.value)
  80. batchCopy.value = batch.value
  81. listCopy.value = [...batchList.value]
  82. popup.value.open()
  83. }
  84. const close = () => {
  85. popup.value.close()
  86. }
  87. const handleChange = (e) => show.value = e.show
  88. watch(() => modelCopy.value.score, (score) => {
  89. if (!score) return
  90. reloadBatchListDebounce(score)
  91. })
  92. defineExpose({open, close, show})
  93. // export default {
  94. // name: "score-batch-popup",
  95. // components: {ScoreStep},
  96. // props: {
  97. // show: {
  98. // type: Boolean,
  99. // default: false
  100. // },
  101. // form: {
  102. // type: Object,
  103. // default: () => {
  104. // }
  105. // },
  106. // batch: {
  107. // type: Number | String,
  108. // default: ''
  109. // },
  110. // batchList: {
  111. // type: Array,
  112. // default: () => []
  113. // }
  114. // },
  115. // data() {
  116. // return {
  117. // openBatchList: false
  118. // }
  119. // },
  120. // computed: {
  121. // firedBatch() {
  122. // return this.batchList.find(b => this.batch == b.batch)
  123. // },
  124. // formatBatchList() {
  125. // return this.batchList.map(b => ({
  126. // ...b,
  127. // subname: b.recommand ? '重点推荐' : ''
  128. // }))
  129. // }
  130. // },
  131. // methods: {
  132. // handleBatchSelection(item) {
  133. // this.$emit('update:batch', item.batch)
  134. // },
  135. // async validate() {
  136. // await this.$refs.score.validate()
  137. // if (!this.firedBatch) {
  138. // const error = '请选择批次'
  139. // this.$message.error(error)
  140. // return Promise.reject(error)
  141. // }
  142. // },
  143. // async handleConfirm() {
  144. // await this.validate()
  145. // this.$emit('confirm')
  146. // }
  147. // }
  148. // }
  149. </script>
  150. <style scoped lang="scss">
  151. ::v-deep(.uv-cell) {
  152. .uv-cell__body {
  153. padding: 10px 5px;
  154. }
  155. }
  156. </style>