filterBar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="filter-bar-container" :style="vuex_skin">
  3. <u-sticky :offset-top="offsetTop" :bg-color="bgColor" h5-nav-height="0" @fixed="handleFixed" @unfixed="handleUnfixed">
  4. <view class="filter-bar" :style="{background: bgColor}">
  5. <view class="filter-item" v-for="(item, index) in filterList" :key="index" @click="handleExchangeTag(index)">
  6. <text :class="currentIndex == index ? 'activity' : ''">{{item.title}}</text>
  7. <view class="filter-icon" v-if="index == 2">
  8. <u-icon name="arrow-up-fill" :color="currentIndex == index && sort == 'asc' ? vuex_theme.bgColor : ''" size="14"></u-icon>
  9. <u-icon name="arrow-down-fill" :color="currentIndex == index && sort == 'desc' ? vuex_theme.bgColor : ''" size="14"></u-icon>
  10. </view>
  11. </view>
  12. </view>
  13. </u-sticky>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. currentIndex: 0
  20. },
  21. data() {
  22. return {
  23. filterList: [{
  24. title: '综合'
  25. },{
  26. title: '销量',
  27. },{
  28. title: '价格',
  29. }],
  30. sort: '', //升序: asc 降序: desc,
  31. offsetTop: 0,
  32. bgColor: '#f1f1f1',
  33. }
  34. },
  35. created() {
  36. // #ifdef MP-WEIXIN
  37. const sys = uni.getSystemInfoSync();
  38. this.offsetTop = ((sys.statusBarHeight + 48) * (750 / sys.windowWidth)); //将px换算成rpx
  39. // #endif
  40. },
  41. methods: {
  42. handleExchangeTag(index) {
  43. this.currentIndex = index;
  44. this.$emit('exchangeTag', index);
  45. if(this.currentIndex == 0 || this.currentIndex == 1){
  46. this.sort = '';
  47. return;
  48. }
  49. if (this.currentIndex == 2) {
  50. this.sort = this.sort != 'asc' ? 'asc' : 'desc';
  51. return;
  52. }
  53. },
  54. handleFixed(){
  55. this.bgColor = '#ffffff';
  56. },
  57. handleUnfixed(){
  58. this.bgColor = '#f1f1f1';
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss">
  64. .filter-bar-container{
  65. z-index: 999;
  66. .filter-bar{
  67. display: flex;
  68. padding: 20rpx 0;
  69. .filter-item{
  70. flex: 1;
  71. display: flex;
  72. justify-content: center;
  73. align-items: center;
  74. .filter-icon{
  75. display: flex;
  76. flex-direction: column;
  77. justify-content: center;
  78. margin-left: 5rpx;
  79. }
  80. }
  81. }
  82. }
  83. .activity{
  84. color: var(--bgColor);
  85. font-weight: bold;
  86. }
  87. </style>