navbar-search.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="slot">
  3. <view class="toph">
  4. <u-search
  5. :placeholder="placeholder"
  6. :value="value"
  7. height="70"
  8. @search="searchConfirm"
  9. @custom="searchConfirm"
  10. ></u-search>
  11. <view class="goodsSort">
  12. <view class="item" :class="{'active':!sortTypes.price_sc && !sortTypes.sales_sc}" @click="changeSort(1)">
  13. <text>综合</text>
  14. </view>
  15. <view class="item" :class="{'active':['asc','desc'].includes(sortTypes.price_sc)}" @click="changeSort(2)">
  16. <text>价格</text>
  17. <view :class="['sortIcon',sortTypes.price_sc]"></view>
  18. </view>
  19. <view class="item" :class="{'active':sortTypes.sales_sc=='desc'}" @click="changeSort(3)">
  20. <text>销量</text>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="siteBar"></view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. export default {
  30. name: 'navbar-search',
  31. props: {
  32. title: {
  33. type: String,
  34. default: '搜索'
  35. },
  36. value: {
  37. type: String,
  38. default: ''
  39. },
  40. // 占位内容
  41. placeholder: {
  42. type: String,
  43. default: '请输入'
  44. },
  45. },
  46. data() {
  47. return {
  48. // 导航栏高度
  49. navBarHeight: app.globalData.navBarHeight,
  50. statusBarHeight: app.globalData.statusBarHeight,
  51. menuRight: app.globalData.menuRight,
  52. menuBotton: app.globalData.menuBotton,
  53. menuHeight: app.globalData.menuHeight,
  54. menuTop: app.globalData.menuTop,
  55. menuWidth: app.globalData.menuWidth,
  56. // 背景色
  57. searchBgColor: this.$appTheme.appThemeSearchBgColor,
  58. // 排序类型
  59. sortTypes:{
  60. price_sc:'',//desc 降序,asc升序
  61. sales_sc:'',//desc 降序,asc升序
  62. },
  63. /* // priceSort: [{
  64. // label: '默认排序',
  65. // value: 1,
  66. // },
  67. // {
  68. // label: '距离优先',
  69. // value: 2,
  70. // },
  71. // {
  72. // label: '价格优先',
  73. // value: 3,
  74. // }
  75. // ],
  76. // saleSort: [{
  77. // label: '去冰',
  78. // value: 1,
  79. // },
  80. // {
  81. // label: '加冰',
  82. // value: 2,
  83. // },
  84. // ], */
  85. };
  86. },
  87. methods: {
  88. // 搜索
  89. searchConfirm(e) {
  90. this.$emit('confirm', e);
  91. },
  92. changeSort(e){
  93. switch (e){
  94. case 1:
  95. // 综合
  96. this.sortTypes = {
  97. price_sc:'',
  98. sales_sc:'',
  99. }
  100. break;
  101. case 2:
  102. // 价格
  103. this.sortTypes.price_sc = this.sortTypes.price_sc=='desc'?'asc':'desc';
  104. this.sortTypes.sales_sc = '';
  105. break;
  106. case 3:
  107. // 销量
  108. this.sortTypes.sales_sc = 'desc';
  109. this.sortTypes.price_sc = '';
  110. break;
  111. default:
  112. break;
  113. }
  114. // this.sortType = e;
  115. this.$emit('sortType', this.sortTypes);
  116. }
  117. }
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .siteBar{
  122. height: 140rpx;
  123. }
  124. .toph {
  125. width: 100%;
  126. position: fixed;
  127. top: 0;
  128. left: 0;
  129. z-index: 899;
  130. overflow: hidden;
  131. background-color: $app-theme-bg-color;
  132. box-sizing: border-box;
  133. padding: 0 30rpx;
  134. }
  135. .goodsSort{
  136. display: flex;
  137. align-items: center;
  138. justify-content: space-between;
  139. padding: 0 30rpx;
  140. height: 80rpx;
  141. box-sizing: content-box;
  142. border-bottom: 1rpx solid $app-theme-border-color;
  143. .item{
  144. position: relative;
  145. text-align: center;
  146. display: flex;
  147. align-items: center;
  148. justify-content: space-between;
  149. color: $app-theme-text-gray-color;
  150. text{
  151. font-size: 30rpx;
  152. }
  153. .sortIcon{
  154. width: 18rpx;
  155. height: 30rpx;
  156. background-image: url('../../static/icon/sort.png');
  157. background-position: 0 0;
  158. background-size: auto 100%;
  159. margin-left: 10rpx;
  160. &.asc{
  161. background-position: 42rpx 0;
  162. }
  163. &.desc{
  164. background-position:20rpx 0;
  165. }
  166. }
  167. &.active{
  168. color: $app-theme-color;
  169. }
  170. &.priceAsc{
  171. }
  172. }
  173. }
  174. </style>