鸿宇研学生前端代码
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.

181 lines
4.1 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page__view">
  3. <!-- 导航栏 -->
  4. <navbar :title="title" leftClick @leftClick="$utils.navigateBack" bgColor="transparent" color="#191919" />
  5. <!-- 搜索栏 -->
  6. <view :class="['flex', 'search', isFocusSearch ? 'is-focus' : '']" >
  7. <uv-search
  8. v-model="keyword"
  9. placeholder="输入关键词搜索"
  10. color="#181818"
  11. bgColor="transparent"
  12. :showAction="isFocusSearch"
  13. @custom="search"
  14. @search="search"
  15. @focus="isFocusSearch = true"
  16. @blur="isFocusSearch = false"
  17. >
  18. <template #prefix>
  19. <image class="search-icon" src="/static/image/icon-search-dark.png" mode="widthFix"></image>
  20. </template>
  21. </uv-search>
  22. </view>
  23. <view class="main">
  24. <sortBar v-model="sort" @change="onSortChange"></sortBar>
  25. <view v-if="list.length" class="content">
  26. <view v-for="item in list" :key="item.id">
  27. <productCard
  28. :data="item"
  29. size="small"
  30. ></productCard>
  31. </view>
  32. </view>
  33. <template v-else>
  34. <uv-empty mode="list"></uv-empty>
  35. </template>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import mixinsList from '@/mixins/list.js'
  41. import sortBar from '@/components/product/sortBar.vue'
  42. import productCard from '@/components/product/productCard.vue'
  43. export default {
  44. mixins: [mixinsList],
  45. components: {
  46. sortBar,
  47. productCard,
  48. },
  49. data() {
  50. return {
  51. title: '搜索结果',
  52. keyword: '',
  53. isFocusSearch: false,
  54. sort: 'comprehensive',
  55. queryParams: {
  56. pageNo: 1,
  57. pageSize: 10,
  58. title: '',
  59. },
  60. mixinsListApi: 'queryActivityList',
  61. }
  62. },
  63. onLoad({ search, title, isDiscount, isHot, isNew }) {
  64. if (search) {
  65. this.keyword = search
  66. this.queryParams.title = search
  67. }
  68. if (title) {
  69. this.title = title
  70. }
  71. if (isDiscount) {
  72. this.queryParams.isDiscount = isDiscount
  73. }
  74. if (isHot) {
  75. this.queryParams.isHot = isHot
  76. }
  77. if (isNew) {
  78. this.queryParams.isNew = isNew
  79. }
  80. this.getData()
  81. },
  82. methods: {
  83. search() {
  84. this.queryParams.pageNo = 1
  85. this.queryParams.pageSize = 10
  86. this.queryParams.title = this.keyword
  87. this.getData()
  88. },
  89. onSortChange(sort) {
  90. console.log('onSortChange', sort)
  91. this.getData()
  92. },
  93. beforeGetData() {
  94. console.log('beforeGetData')
  95. let params = {}
  96. switch(this.sort) {
  97. // 销量排序(saleOrder):0-从高到低 1-从低到高
  98. case 'sale-desc': // 销量排序 - 降序
  99. params.saleOrder = '0'
  100. break
  101. case 'sale-asc': // 销量排序 - 升序
  102. params.saleOrder = '1'
  103. break
  104. // 价格排序(priceOrder):0-从高到低 1-从低到高
  105. case 'price-desc': // 销量排序 - 降序
  106. params.priceOrder = '0'
  107. break
  108. case 'price-asc': // 销量排序 - 升序
  109. params.priceOrder = '1'
  110. break
  111. default:
  112. break
  113. }
  114. return params
  115. },
  116. },
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. .search {
  121. $h: 64rpx;
  122. $radius: 32rpx;
  123. $borderWidth: 4rpx;
  124. margin: 24rpx 32rpx 0 32rpx;
  125. width: calc(100% - 32rpx * 2);
  126. height: $h;
  127. position: relative;
  128. border-radius: $radius;
  129. &-icon {
  130. margin: 0 13rpx 0 26rpx;
  131. width: 30rpx;
  132. height: auto;
  133. }
  134. /deep/ .uv-search__content {
  135. padding: 12rpx 0;
  136. background: #FFFFFF !important;
  137. border-color: #CFEFFF !important;
  138. border: 4rpx solid transparent;
  139. }
  140. &.is-focus {
  141. /deep/ .uv-search__action {
  142. padding: 19rpx 24rpx;
  143. font-size: 26rpx;
  144. font-weight: 500;
  145. line-height: 1;
  146. color: #FFFFFF;
  147. background: #00A9FF;
  148. border-radius: 32rpx;
  149. }
  150. }
  151. }
  152. .main {
  153. margin-top: 24rpx;
  154. padding: 0 32rpx 100rpx 32rpx;
  155. }
  156. .content {
  157. margin-top: 24rpx;
  158. display: grid;
  159. grid-template-columns: repeat(2, 1fr);
  160. gap: 16rpx;
  161. }
  162. </style>