SearchResult.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view :class="['qn-page-' + theme]">
  3. <view class="search-input clearfix">
  4. <view class="input-box float_left">
  5. <u-search
  6. @click="goPage('/pagesT/search/index', 'redirectTo')"
  7. placeholder="请输入关键字"
  8. :input-style="input_style"
  9. :search-icon-color="primaryColor"
  10. v-model="keyword"
  11. :show-action="false"
  12. shape="square"
  13. :clearabled="true"
  14. bg-color="#f4f4f4"
  15. disabled
  16. ></u-search>
  17. </view>
  18. <view class="float_right type-view" @click="changeStyle"><text class="ibonfont" :class="[is_list ? 'ibonfenlei1' : 'ibonfenlei2']"></text></view>
  19. </view>
  20. <view class="goods-ul">
  21. <scroll-view @scrolltolower="lower" scroll-y class="search_list">
  22. <Aempty text="没有商品哦~~" src="https://onlineimg.qianniao.vip/search.png" v-if="!goods_list.length"></Aempty>
  23. <block v-if="goods_list.length > 0">
  24. <u-waterfall v-model="goods_list" ref="uWaterfall" v-if="!is_list">
  25. <template v-slot:left="{ leftList }">
  26. <block v-for="(item, index) in leftList" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem></block>
  27. </template>
  28. <template v-slot:right="{ rightList }">
  29. <block v-for="(item, index) in rightList" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem></block>
  30. </template>
  31. </u-waterfall>
  32. <view v-else :class="[is_list ? 'goods-li' : 'goods-li-inline']" v-for="(item, index) in goods_list" :key="index">
  33. <GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem>
  34. </view>
  35. </block>
  36. <u-loadmore margin-top="20" v-if="goods_list.length" :status="load_status" />
  37. </scroll-view>
  38. </view>
  39. <CartFloat />
  40. <AddCardModel :selAddress="now_sel_address" @close="is_add_show = false" :isShow="is_add_show" @change="cardModelPopChange" :goodsId="goods_id" />
  41. </view>
  42. </template>
  43. <script>
  44. import AddCardModel from '@/components/AddCardModel';
  45. import GoodsItem from '@/components/GoodsItem.vue';
  46. import CartFloat from '../components/CartFloat.vue';
  47. export default {
  48. components: {
  49. AddCardModel,
  50. GoodsItem,
  51. CartFloat
  52. },
  53. data() {
  54. return {
  55. now_sel_address: {},
  56. show_sku: false,
  57. is_list: true,
  58. keyword: '',
  59. goods_list: [],
  60. page: 1,
  61. pageSize: 10,
  62. pageTotal: 0,
  63. goods_id: 0,
  64. load_status: 'loadmore',
  65. is_add_show: false
  66. };
  67. },
  68. onLoad(options) {
  69. // 接收传值
  70. if (options.key) {
  71. this.keyword = options.key;
  72. } else {
  73. const scene = decodeURIComponent(options.scene);
  74. this.keyword = scene;
  75. }
  76. this.searchGoods();
  77. // #ifdef MP-WEIXIN
  78. // 小程序的原生菜单中显示分享按钮
  79. uni.showShareMenu({
  80. withShareTicket: false,
  81. menus: ['shareAppMessage', 'shareTimeline']
  82. });
  83. // #endif
  84. },
  85. methods: {
  86. // 加入购物车弹窗
  87. addCard(id) {
  88. this.goods_id = id;
  89. this.is_add_show = true;
  90. },
  91. cardModelPopChange(obj) {
  92. if (!obj.show) {
  93. this.is_add_show = false;
  94. }
  95. },
  96. // 切换商品列表展示样式
  97. changeStyle() {
  98. this.is_list = !this.is_list;
  99. },
  100. lower(e) {
  101. if (this.pageTotal / this.pageSize > this.page) {
  102. this.page += 1;
  103. this.searchGoods();
  104. }
  105. },
  106. // 商品搜索
  107. searchGoods() {
  108. this.load_status = 'loading';
  109. this.$u.api
  110. .getGoodsByCategory({
  111. keyword: this.keyword,
  112. categoryId: '',
  113. page: this.page,
  114. pageSize: this.pageSize
  115. })
  116. .then(res => {
  117. if (this.page === 1) {
  118. this.goods_list = res.data;
  119. } else {
  120. this.goods_list = this.goods_list.concat(res.data);
  121. }
  122. this.pageTotal = res.pageTotal;
  123. this.load_status = this.$_utils.loadStatus(this.page, this.pageSize, this.pageTotal);
  124. });
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss">
  130. .search-input {
  131. background-color: #ffffff;
  132. padding: 22upx;
  133. .input-box {
  134. width: 620rpx;
  135. }
  136. .type-view {
  137. width: 80rpx;
  138. text-align: center;
  139. line-height: 64upx;
  140. height: 64upx;
  141. .ibonfont {
  142. font-size: 36upx;
  143. color: #909399;
  144. }
  145. }
  146. }
  147. // 搜索页
  148. .search_list {
  149. height: calc(100vh - 108rpx);
  150. .goods-li {
  151. margin: 24rpx 32rpx;
  152. }
  153. .goods-li-inline {
  154. display: inline-block;
  155. }
  156. }
  157. </style>