sh-filter.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="filter-box">
  3. <view class="cu-modal" style="z-index: -1;" :class="{ show: showSel }" @tap="hideModal"></view>
  4. <view class="navbar">
  5. <view class="sel-box u-flex-col" v-show="showSel">
  6. <view class="sel-item" @tap="onSel(0)" :class="{ 'sel-active': defaultOrder === 0 && filterIndex === 0 }">综合推荐</view>
  7. <view class="sel-item" @tap="onSel(1)" :class="{ 'sel-active': defaultOrder === 1 && filterIndex === 0 }">扩展自定义排序</view>
  8. </view>
  9. <view class="nav-item u-flex-col" :class="{ current: filterIndex === 0 }" @tap="tabClick(0)">
  10. <view class="title-box u-flex u-col-center">
  11. <text class="filter-title">{{ defaultOrder === 1 ? '自定义' : '综合推荐' }}</text>
  12. <view class="p-box"><text style="font-size: 22rpx;" :class="{ active: filterIndex === 0 }" class="u-iconfont uicon-arrow-up u-m-l-6"></text></view>
  13. </view>
  14. <view class="line" :class="{ 'line-active': filterIndex === 0 }"></view>
  15. </view>
  16. <view class="nav-item u-flex-col" :class="{ current: filterIndex === 1 }" @tap="tabClick(1)">
  17. <view class="title-box u-flex"><text class="filter-title">销量</text></view>
  18. <view class="line" :class="{ 'line-active': filterIndex === 1 }"></view>
  19. </view>
  20. <view class="nav-item u-flex-col" :class="{ current: filterIndex === 2 }" @tap="tabClick(2)">
  21. <view class="title-box u-flex">
  22. <text class="filter-title">价格</text>
  23. <view class="p-box u-flex-col u-m-l-6">
  24. <view
  25. class="u-iconfont uicon-arrow-up"
  26. :style="{ fontSize: '20rpx', lineHeight: '18rpx', color: priceOrder === 1 && filterIndex === 2 ? '#d5a65a' : '#333' }"
  27. ></view>
  28. <view
  29. class="u-iconfont uicon-arrow-down"
  30. :style="{ fontSize: '20rpx', lineHeight: '18rpx', color: priceOrder === 2 && filterIndex === 2 ? '#d5a65a' : '#333' }"
  31. ></view>
  32. </view>
  33. </view>
  34. <view class="line" :class="{ 'line-active': filterIndex === 2 }"></view>
  35. </view>
  36. <view class="nav-item u-flex-col" :class="{ current: filterIndex === 3 }" @tap="tabClick(3)">
  37. <view class="title-box"><text class="filter-title">新品优先</text></view>
  38. <view class="line" :class="{ 'line-active': filterIndex === 3 }"></view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. /**
  45. * 商品筛选组件
  46. *
  47. */
  48. import { mapState, mapActions, mapMutations } from 'vuex';
  49. export default {
  50. components: {},
  51. props: {},
  52. data() {
  53. return {
  54. filterIndex: 0,
  55. showSel: false, //综合选择
  56. defaultOrder: 0, //综合
  57. priceOrder: 0, //价格
  58. salesOrder: 0, //销量
  59. newProdcutOrder: 0 //新品优先
  60. };
  61. },
  62. computed: {
  63. filterData() {
  64. const data = {
  65. defaultOrder: this.defaultOrder,
  66. priceOrder: this.priceOrder,
  67. salesOrder: this.salesOrder,
  68. newProdcutOrder: this.newProdcutOrder
  69. };
  70. return data;
  71. }
  72. },
  73. onLoad() {},
  74. methods: {
  75. //筛选
  76. tabClick(index) {
  77. this.filterIndex = index;
  78. index === 0 ? (this.showSel = !this.showSel) : (this.showSel = false);
  79. index === 1 ? (this.salesOrder = 1) : (this.salesOrder = 0);
  80. index === 2 ? (this.priceOrder = this.priceOrder === 1 ? 2 : 1) : (this.priceOrder = 0);
  81. index === 3 ? (this.newProdcutOrder = 1) : (this.newProdcutOrder = 0);
  82. this.$emit('change', this.filterData);
  83. },
  84. onSel(dot) {
  85. this.defaultOrder = dot;
  86. this.$emit('change', this.filterData);
  87. this.showSel = false;
  88. },
  89. hideModal() {
  90. this.showSel = false;
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. .sel-box {
  97. position: absolute;
  98. width: 750rpx;
  99. height: 140rpx;
  100. background: rgba(246, 246, 246, 1);
  101. border-radius: 0px 0px 20rpx 20rpx;
  102. z-index: 999;
  103. left: 50%;
  104. transform: translateX(-50%);
  105. bottom: -138rpx;
  106. transition: all ease-out 0.2s;
  107. .sel-item {
  108. color: #333;
  109. padding: 20rpx 40rpx 0;
  110. font-size: 24rpx;
  111. font-weight: 500;
  112. }
  113. .sel-active {
  114. color: #d5a65a;
  115. font-size: 26rpx;
  116. font-weight: 600;
  117. }
  118. }
  119. .filter-box {
  120. width: 750rpx;
  121. }
  122. .navbar {
  123. display: flex;
  124. width: 750rpx;
  125. height: 95rpx;
  126. background: #fff;
  127. border-bottom: 1upx solid #e6e6e6;
  128. position: relative;
  129. z-index: 999;
  130. .nav-item {
  131. flex: 1;
  132. display: flex;
  133. justify-content: center;
  134. align-items: center;
  135. height: 100%;
  136. font-size: 30rpx;
  137. position: relative;
  138. .filter-title {
  139. font-size: 28rpx;
  140. color: #333;
  141. font-weight: 600;
  142. }
  143. .line {
  144. width: 110rpx;
  145. height: 4rpx;
  146. background: transparent;
  147. position: absolute;
  148. bottom: 0;
  149. z-index: 2;
  150. }
  151. .line-active {
  152. background: rgba(213, 166, 90, 1);
  153. }
  154. .p-box {
  155. display: flex;
  156. flex-direction: column;
  157. }
  158. }
  159. }
  160. .current {
  161. color: #d5a65a;
  162. }
  163. </style>