鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

  1. <template>
  2. <view class="flex sort" :style="style">
  3. <view :class="['flex', 'sort-item', sort == 'comprehensive' ? 'is-active' : '']" @click="onClickSort('comprehensive')">综合</view>
  4. <view :class="['flex', 'sort-item', ['sale-asc', 'sale-desc'].includes(sort) ? 'is-active' : '']" @click="onClickSort('sale')">
  5. <view>销量</view>
  6. <view class="sort-item-icon">
  7. <uv-icon v-if="sort == 'sale-asc'" name="arrow-up-fill" color="#00A9FF" size="16rpx" :bold="true"></uv-icon>
  8. <uv-icon v-else-if="sort == 'sale-desc'" name="arrow-down-fill" color="#00A9FF" size="16rpx" :bold="true"></uv-icon>
  9. <image v-else style="width: 8rpx; height: auto;" src="/static/image/icon-sort.png" mode="widthFix"></image>
  10. </view>
  11. </view>
  12. <view :class="['flex', 'sort-item', ['price-asc', 'price-desc'].includes(sort) ? 'is-active' : '']" @click="onClickSort('price')">
  13. <view>价格</view>
  14. <view class="sort-item-icon">
  15. <uv-icon v-if="sort == 'price-asc'" name="arrow-up-fill" color="#00A9FF" size="16rpx" :bold="true"></uv-icon>
  16. <uv-icon v-else-if="sort == 'price-desc'" name="arrow-down-fill" color="#00A9FF" size="16rpx" :bold="true"></uv-icon>
  17. <image v-else style="width: 8rpx; height: auto;" src="/static/image/icon-sort.png" mode="widthFix"></image>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. value: {
  26. type: String,
  27. default: 'comprehensive'
  28. },
  29. style: {
  30. type: String,
  31. default: ''
  32. }
  33. },
  34. computed: {
  35. sort: {
  36. set(val) {
  37. this.$emit('input', val)
  38. },
  39. get() {
  40. return this.value
  41. }
  42. }
  43. },
  44. methods: {
  45. onClickSort(key) {
  46. let sort = 'comprehensive'
  47. switch(key) {
  48. case 'comprehensive':
  49. sort = 'comprehensive'
  50. break;
  51. case 'sale':
  52. if (this.sort == 'sale-desc') {
  53. sort = 'sale-asc'
  54. } else {
  55. sort = 'sale-desc'
  56. }
  57. break;
  58. case 'price':
  59. if (this.sort == 'price-desc') {
  60. sort = 'price-asc'
  61. } else {
  62. sort = 'price-desc'
  63. }
  64. break;
  65. default:
  66. break;
  67. }
  68. this.sort = sort
  69. this.$emit('change', sort)
  70. },
  71. },
  72. }
  73. </script>
  74. <style scoped lang="scss">
  75. .sort {
  76. width: 100%;
  77. justify-content: space-between;
  78. &-item {
  79. padding: 12rpx 32rpx;
  80. font-size: 28rpx;
  81. line-height: 1.5;
  82. color: #191919;
  83. column-gap: 4rpx;
  84. &.is-active {
  85. font-weight: 600;
  86. color: #00A9FF;
  87. }
  88. &-icon {
  89. width: 32rpx;
  90. display: inline-flex;
  91. align-items: center;
  92. justify-content: center;
  93. }
  94. }
  95. }
  96. </style>