sort-nav.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <view class="sort-nav flex bg-white">
  3. <view :class="'tag flex-2 flex row-center ' + (comprehensive ? 'primary' : '')" @tap="onNormal">综合</view>
  4. <view class="tag flex-2 flex row-center" @tap="onPriceSort">
  5. <text :class="value.priceSort ? 'primary' : ''">价格</text>
  6. <view class="arrow-icon flex-col col-center row-center">
  7. <u-icon name="arrow-up-fill" :color="value.priceSort == 'asc' ? colorConfig.primary : colorConfig.normal"></u-icon>
  8. <u-icon name="arrow-down-fill" :color="value.priceSort == 'desc' ? colorConfig.primary : colorConfig.normal"></u-icon>
  9. </view>
  10. </view>
  11. <view class="tag flex-2 flex row-center" @tap="onSaleSort">
  12. <text :class="value.saleSort ? 'primary' : ''">销量</text>
  13. <view class="arrow-icon flex-col col-center row-center">
  14. <u-icon name="arrow-up-fill" :color="value.saleSort == 'asc' ? colorConfig.primary : colorConfig.normal"></u-icon>
  15. <u-icon name="arrow-down-fill" :color="value.saleSort == 'desc' ? colorConfig.primary : colorConfig.normal"></u-icon>
  16. </view>
  17. </view>
  18. <view v-if="showType" class="tag flex-1 flex row-center" @tap="changeType">
  19. <image class="icon-sm"
  20. :src="value.goodsType === 'one' ? '/static/images/icon_double.png' : '/static/images/icon_one.png'">
  21. </image>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import {trottle} from '@/utils/tools'
  27. export default {
  28. name: "sort-nav",
  29. props: {
  30. value: {
  31. type: Object,
  32. default: () => ({
  33. priceSort: '',
  34. saleSort: '',
  35. goodsType: 'one'
  36. })
  37. },
  38. showType: {
  39. type: Boolean,
  40. default: true
  41. }
  42. },
  43. data() {
  44. return {
  45. };
  46. },
  47. created() {
  48. this.onNormal = trottle(this.onNormal, 500, this);
  49. this.onPriceSort = trottle(this.onPriceSort, 500, this);
  50. this.onSaleSort = trottle(this.onSaleSort, 500, this);
  51. },
  52. computed: {
  53. comprehensive() {
  54. const {
  55. priceSort,
  56. saleSort
  57. } = this.value
  58. if (priceSort == '' && saleSort == '') {
  59. return true;
  60. }
  61. return false;
  62. }
  63. },
  64. methods: {
  65. onNormal() {
  66. this.value.priceSort = ''
  67. this.value.saleSort = ''
  68. const obj = {
  69. priceSort: '',
  70. saleSort: ''
  71. }
  72. this.onInput(obj)
  73. },
  74. onInput(obj) {
  75. this.$emit('input', Object.assign(this.value, obj))
  76. },
  77. onPriceSort() {
  78. let {
  79. priceSort
  80. } = this.value
  81. const obj = {}
  82. obj.priceSort = priceSort == 'asc' ? 'desc' : 'asc'
  83. obj.saleSort = ''
  84. this.onInput(obj)
  85. },
  86. onSaleSort() {
  87. let {
  88. saleSort
  89. } = this.value
  90. const obj = {}
  91. obj.saleSort = saleSort == 'asc' ? 'desc' : 'asc'
  92. obj.priceSort = ''
  93. this.onInput(obj)
  94. },
  95. changeType() {
  96. const {goodsType} = this.value
  97. const obj = {}
  98. obj.goodsType = goodsType === 'one' ? 'double' : 'one'
  99. this.onInput(obj)
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .sort-nav {
  106. height: 80rpx;
  107. .tag {
  108. height: 100%;
  109. }
  110. .arrow-icon {
  111. transform: scale(0.36);
  112. }
  113. }
  114. </style>