金诚优选前端代码
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.

238 lines
5.8 KiB

  1. <template>
  2. <view>
  3. <lf-nav title="搜索" :showIcon="true" @changeHeight="e => nav_height = e"></lf-nav>
  4. <view class="head">
  5. <u-search placeholder="请输入商品名或商户名"
  6. action-text="取消"
  7. v-model="value"
  8. @custom="customClick"
  9. @search="search">
  10. </u-search>
  11. </view>
  12. <view>
  13. <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="false" :current="tab_current" @change="tabChange"></u-tabs>
  14. </view>
  15. <swiper :current="tab_current" @change="swiperChange" :style="{height: autoHeight}">
  16. <swiper-item v-for="(tab_item, tab_index) in tab_list" :key="tab_index">
  17. <scroll-view :scroll-y="true" :style="{height: autoHeight}" @scrolltolower="scrolltolower">
  18. <view class="scroll-content" v-if="tab_index == 0">
  19. <lf-waterfall :list="goods_list" ref="searchWaterfall"></lf-waterfall>
  20. <lf-nocontent src="/static/images/empty.png" v-if="goods_list.length <= 0"></lf-nocontent>
  21. </view>
  22. <view class="scroll-content" v-else>
  23. <view class="shop-box"
  24. v-for="(item, index) in brand_list" :key="index"
  25. @click="$url('/pages/shop/shopdetail?id='+ item.id)">
  26. <image class="shop-img" :src="item.logo"></image>
  27. <view class="shop-info">
  28. <view class="lf-line-1">{{ item.name }}</view>
  29. <view>{{ item.category }}</view>
  30. </view>
  31. </view>
  32. <lf-nocontent src="/static/images/empty.png" v-if="brand_list.length <= 0"></lf-nocontent>
  33. </view>
  34. </scroll-view>
  35. </swiper-item>
  36. </swiper>
  37. </view>
  38. </template>
  39. <script>
  40. import lfWaterfall from '@/components/lf-waterfall-shopdetails/lf-waterfall.vue';
  41. export default {
  42. components: {
  43. lfWaterfall
  44. },
  45. data() {
  46. return {
  47. value: '',
  48. tab_current: 0,
  49. tab_list: [{
  50. name: '商品'
  51. },{
  52. name: '商户'
  53. }],
  54. scrollH: 0,
  55. nav_height: 0,
  56. goods_list: [],
  57. brand_list: [],
  58. page: 1,
  59. isPage: true
  60. }
  61. },
  62. computed: {
  63. autoHeight(){
  64. return `calc(${this.scrollH}px - ${this.nav_height}px - 124rpx - 86rpx)`;
  65. }
  66. },
  67. onLoad(options){
  68. let info = uni.getSystemInfoSync();
  69. this.scrollH = info.screenHeight;
  70. this.value = options.value || '';
  71. if(options.value){
  72. this.getSearchList(options.value);
  73. }
  74. },
  75. methods: {
  76. // 点击取消,返回上一个页面
  77. customClick(){
  78. this.$toBack();
  79. },
  80. // 开始搜索
  81. search(value){
  82. if(!value || !value.trim()) return this.$msg('搜索内容不能为空');
  83. // 重置页面请求值
  84. this.page = 1;
  85. this.isPage = true;
  86. this.$refs.searchWaterfall[0].clear();
  87. // 执行上一个页面的保存搜索历史
  88. let pages = getCurrentPages();
  89. let beforePage = pages[pages.length - 2]; // 上个页面
  90. if(beforePage){
  91. beforePage.$vm.updateHistory(value).then(() => {
  92. beforePage.$vm.setHistorySearch();
  93. })
  94. this.getSearchList(value);
  95. }else{
  96. this.$msg('页面路径出错,当前搜索值将不被记录搜索历史').then(() => {
  97. this.getSearchList(value);
  98. })
  99. }
  100. },
  101. // 获取搜索列表
  102. getSearchList(value){
  103. uni.showLoading({
  104. title: '正在搜索中'
  105. })
  106. this.$http.get({
  107. api: 'api/store/list',
  108. data: {
  109. keyword: value,
  110. page: this.page
  111. }
  112. }).then(res => {
  113. if(res.data.code == 200){
  114. let goods = res.data.data.goods;
  115. let brand = res.data.data.brand;
  116. let isPage = this.$isRight(goods.next_page_url);
  117. this.isPage = isPage;
  118. let list = goods.data.map(item => {
  119. return {
  120. id: item.id,
  121. original_price: item.min_market_price,
  122. picture: item.img,
  123. pictures: [item.img],
  124. price: item.min_price,
  125. sale: item.sale_count,
  126. title: item.name
  127. }
  128. })
  129. if(this.page == 1){
  130. this.goods_list = list;
  131. }else{
  132. this.goods_list.push(...list);
  133. }
  134. this.brand_list = brand;
  135. this.tab_list[1].name = `商户(${brand.length})`;
  136. this.tab_list[0].name = `商品(${this.goods_list.length})`;
  137. }else{
  138. this.$msg(res.data.message || '服务器错误,请稍后再试');
  139. }
  140. uni.hideLoading();
  141. }).catch(err => uni.hideLoading());
  142. },
  143. // 切换tab
  144. tabChange(event){
  145. this.tab_current = event;
  146. },
  147. // 切换swiper
  148. swiperChange(event){
  149. this.tab_current = event.detail.current;
  150. },
  151. // 商品scroll滚动到底部
  152. scrolltolower(){
  153. // 只做商品加载下一页,品牌不做
  154. if(this.tab_current == 0){
  155. if(this.isPage){
  156. this.page++;
  157. this.getSearchList(this.value);
  158. }else{
  159. this.$msg('没有更多啦~');
  160. }
  161. }else{
  162. this.$msg('没有更多啦~');
  163. }
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .head{
  170. padding: 30rpx 32rpx;
  171. }
  172. .scroll-content{
  173. padding: 30rpx 32rpx;
  174. }
  175. .shop-box{
  176. width: 100%;
  177. height: 100rpx;
  178. display: flex;
  179. &:nth-child(n+2){
  180. margin-top: 60rpx;
  181. }
  182. .shop-img{
  183. width: 100rpx;
  184. height: 100rpx;
  185. background-color: #EEEEEE;
  186. border-radius: 5rpx;
  187. margin-right: 15rpx;
  188. }
  189. .shop-info{
  190. width: 570rpx;
  191. height: 100rpx;
  192. display: flex;
  193. flex-direction: column;
  194. justify-content: space-between;
  195. &>view:nth-child(1){
  196. font-size: 36rpx;
  197. color: #222222;
  198. font-weight: bold;
  199. }
  200. &>view:nth-child(2){
  201. font-size: 24rpx;
  202. color: #777777;
  203. }
  204. }
  205. }
  206. // tabs 样式修改
  207. /deep/.u-scroll-box {
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  212. }
  213. /deep/.u-scroll-box .u-tab-bar {
  214. background-color: #15716E!important;
  215. width: 80rpx!important;
  216. position: absolute;
  217. left: 0;
  218. bottom: -12rpx;
  219. }
  220. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  221. background-color: #15716E!important;
  222. width: 56rpx!important;
  223. position: absolute;
  224. height: 5rpx!important;
  225. left: 8rpx;
  226. bottom: -4rpx;
  227. }
  228. /deep/ .u-tab-item {
  229. font-size: 28rpx!important;
  230. }
  231. </style>