college-item.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="p-20 bg-white fx-row fx-bet-sta gap-20">
  3. <uv-image v-if="!hiddenLogo&&!reverse" :src="item.logo" width="64" height="64" mode="aspectFit"/>
  4. <view class="flex-1 fx-col gap-10">
  5. <view v-if="showName||showStar" class="fx-row fx-bet-cen gap-20">
  6. <uv-text v-if="showName" type="main" bold :text="item.name"/>
  7. <uv-tags v-if="showStar" v-bind="starBinding" :text="item.star"/>
  8. </view>
  9. <view v-if="bxTags.length" class="fx-row flex-wrap gap-8">
  10. <uv-tags v-for="t in bxTags" :text="t" v-bind="getHighlightBindings(t)" @click="handleTagClick(t)"/>
  11. </view>
  12. <slot v-if="!hiddenAddress" name="address">
  13. <uv-text type="tips" prefix-icon="empty-address" :lines="addressLines" :icon-style="{color: '#999999'}"
  14. size="12" :text="item.address"/>
  15. </slot>
  16. </view>
  17. <uv-image v-if="!hiddenLogo&&reverse" :src="item.logo" width="64" height="64" mode="aspectFit"/>
  18. <slot name="right"/>
  19. </view>
  20. </template>
  21. <script setup>
  22. import {computed} from 'vue';
  23. import _ from 'lodash';
  24. import {createPropDefine} from "@/utils";
  25. import {useUserStore} from "@/hooks/useUserStore";
  26. const props = defineProps({
  27. item: createPropDefine({}, Object),
  28. hiddenLogo: createPropDefine(false, Boolean),
  29. hiddenName: createPropDefine(false, Boolean),
  30. hiddenStar: createPropDefine(false, Boolean),
  31. hiddenAddress: createPropDefine(false, Boolean),
  32. addressLines: createPropDefine(2, Number),
  33. reverse: createPropDefine(false, Boolean)
  34. })
  35. const emits = defineEmits(['tag'])
  36. const {isCultural} = useUserStore()
  37. const showName = computed(() => !props.hiddenName)
  38. const showStar = computed(() => !props.hiddenStar && props.item.star)
  39. const tagAttrs = {
  40. type: 'info',
  41. plain: true,
  42. size: 'tiny',
  43. 'class': 'pointer-events-none'
  44. }
  45. const highlights = ['双高']
  46. const starBinding = {
  47. ...tagAttrs,
  48. type: 'warning'
  49. }
  50. const tagHighlight = {
  51. ...tagAttrs,
  52. type: 'primary',
  53. plainFill: true
  54. }
  55. const bxTags = computed(() => {
  56. const {bxLevel, bxType} = props.item
  57. const tags = bxLevel ? bxLevel.split(',') : []
  58. if (bxType) {
  59. _.pull(tags, '双高')
  60. tags.push(bxType)
  61. }
  62. return tags
  63. })
  64. const isSpecialTag = (tag) => {
  65. return !isCultural.value && tag == props.item.bxType
  66. }
  67. const isHighlight = (tag) => {
  68. return highlights.includes(tag) || isSpecialTag(tag)
  69. }
  70. const getHighlightBindings = (tag) => {
  71. const attrs = isHighlight(tag) ? tagHighlight : tagAttrs
  72. return isSpecialTag(tag) ? {...attrs, icon: 'question-circle', reverse: true, 'class': ''} : attrs
  73. }
  74. const handleTagClick = (tag) => {
  75. if (isSpecialTag(tag)) emits('tag')
  76. }
  77. </script>
  78. <style scoped>
  79. </style>