recommend-score-range.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <slider-range v-if="sliderAvailable" :min="scoreLimit.availableRange[0]" :max="scoreLimit.availableRange[1]"
  3. :value="scoreRange" :activeColor="$u.color.primary" @change="confirmScoreRange"></slider-range>
  4. <view v-else class="fx-1">
  5. <u-divider text="无最佳推荐分数范围" :text-size="13" :custom-style="{margin: '0'}"/>
  6. </view>
  7. </template>
  8. <script>
  9. import SliderRange from '@/components/primewind-sliderrange/components/primewind-sliderrange/index.vue'
  10. export default {
  11. name: 'RecommendScoreRange',
  12. components: {
  13. SliderRange
  14. },
  15. inject: ['fetchScoreBatchRange', 'fetchVoluntaryData'],
  16. props: {
  17. formSubject: {
  18. type: Object,
  19. default: () => ({})
  20. }
  21. },
  22. data() {
  23. return {
  24. scoreRange: [0, 100],
  25. }
  26. },
  27. computed: {
  28. voluntaryData() {
  29. // noinspection JSUnresolvedFunction
  30. return this.fetchVoluntaryData()
  31. },
  32. scoreBatchRange() {
  33. // noinspection JSUnresolvedFunction
  34. return this.fetchScoreBatchRange()
  35. },
  36. scoreLimit() {
  37. const emptyDefault = {
  38. defaultRange: [],
  39. availableRange: []
  40. }
  41. if (!this.scoreBatchRange[0] || !this.scoreBatchRange[1]) return emptyDefault
  42. const min = this.scoreBatchRange[0] * 1
  43. const max = this.voluntaryData.maxScore * 1 // requirements change: no need to limit top score
  44. const current = this.formSubject.score * 1
  45. const expectMax = current + 20
  46. const expectMin = current - 30
  47. const defaultRange = [Math.max(expectMin, min), Math.min(expectMax, max)]
  48. const availableMax = expectMax + 10
  49. const availableMin = expectMin - 20
  50. const availableRange = [Math.max(availableMin, min), Math.min(availableMax, max)]
  51. return {
  52. defaultRange,
  53. availableRange
  54. }
  55. },
  56. sliderAvailable() {
  57. return this.scoreLimit.defaultRange[1] > this.scoreLimit.defaultRange[0]
  58. }
  59. },
  60. watch: {
  61. scoreLimit: {
  62. handler() {
  63. console.log('calculate score limit', this.scoreLimit)
  64. this.resetScoreRange()
  65. },
  66. immediate: true
  67. },
  68. },
  69. methods: {
  70. resetScoreRange() {
  71. if (this.scoreLimit.defaultRange.length != 2) return
  72. this.scoreRange = this.scoreLimit.defaultRange
  73. },
  74. confirmScoreRange(e) {
  75. // NOTE: ext.debounce do not support arguments in uni-app, but it works fine in pc.
  76. this.$u.debounce(() => {
  77. if (this.scoreRange.toString() === e.toString()) return
  78. this.scoreRange = e
  79. this.$emit('change', e)
  80. }, 1000)
  81. }
  82. }
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. .slider-range ::v-deep {
  87. padding-top: 0;
  88. .slider-range-inner {
  89. height: 24px !important;
  90. }
  91. .slider-handle-block {
  92. width: 32px !important;
  93. border-radius: 10px;
  94. background-color: $uni-color-primary !important;
  95. }
  96. .range-tip {
  97. color: #FFFFFF;
  98. top: 20px;
  99. z-index: 99;
  100. pointer-events: none;
  101. }
  102. }
  103. </style>