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

244 lines
6.1 KiB

4 years ago
4 years ago
4 years ago
  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.status){
  114. // TODO 搜索接口已改,需重新对接
  115. if(this.$isRight(res.data.data)){
  116. let goods = res.data.data.goods;
  117. let brand = res.data.data.brand;
  118. let isPage = this.$isRight(goods.next_page_url);
  119. this.isPage = isPage;
  120. let list = goods.data.map(item => {
  121. return {
  122. id: item.id,
  123. original_price: item.min_market_price,
  124. picture: item.img,
  125. pictures: [item.img],
  126. price: item.min_price,
  127. sale: item.sale_count,
  128. title: item.name
  129. }
  130. })
  131. if(this.page == 1){
  132. this.goods_list = list;
  133. }else{
  134. this.goods_list.push(...list);
  135. }
  136. console.log("this.goods_list", this.goods_list)
  137. this.brand_list = brand;
  138. this.tab_list[1].name = `商户(${brand.length})`;
  139. this.tab_list[0].name = `商品(${this.goods_list.length})`;
  140. }else{
  141. this.$msg('该关键词没有数据哦~')
  142. }
  143. }else{
  144. this.$msg(res.data.message || '服务器错误,请稍后再试');
  145. }
  146. uni.hideLoading();
  147. }).catch(err => uni.hideLoading());
  148. },
  149. // 切换tab
  150. tabChange(event){
  151. this.tab_current = event;
  152. },
  153. // 切换swiper
  154. swiperChange(event){
  155. this.tab_current = event.detail.current;
  156. },
  157. // 商品scroll滚动到底部
  158. scrolltolower(){
  159. // 只做商品加载下一页,品牌不做
  160. if(this.tab_current == 0){
  161. if(this.isPage){
  162. this.page++;
  163. this.getSearchList(this.value);
  164. }else{
  165. this.$msg('没有更多啦~');
  166. }
  167. }else{
  168. this.$msg('没有更多啦~');
  169. }
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="scss" scoped>
  175. .head{
  176. padding: 30rpx 32rpx;
  177. }
  178. .scroll-content{
  179. padding: 30rpx 32rpx;
  180. }
  181. .shop-box{
  182. width: 100%;
  183. height: 100rpx;
  184. display: flex;
  185. &:nth-child(n+2){
  186. margin-top: 60rpx;
  187. }
  188. .shop-img{
  189. width: 100rpx;
  190. height: 100rpx;
  191. background-color: #EEEEEE;
  192. border-radius: 5rpx;
  193. margin-right: 15rpx;
  194. }
  195. .shop-info{
  196. width: 570rpx;
  197. height: 100rpx;
  198. display: flex;
  199. flex-direction: column;
  200. justify-content: space-between;
  201. &>view:nth-child(1){
  202. font-size: 36rpx;
  203. color: #222222;
  204. font-weight: bold;
  205. }
  206. &>view:nth-child(2){
  207. font-size: 24rpx;
  208. color: #777777;
  209. }
  210. }
  211. }
  212. // tabs 样式修改
  213. /deep/.u-scroll-box {
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  218. }
  219. /deep/.u-scroll-box .u-tab-bar {
  220. background-color: #15716E!important;
  221. width: 80rpx!important;
  222. position: absolute;
  223. left: 0;
  224. bottom: -12rpx;
  225. }
  226. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  227. background-color: #15716E!important;
  228. width: 56rpx!important;
  229. position: absolute;
  230. height: 5rpx!important;
  231. left: 8rpx;
  232. bottom: -4rpx;
  233. }
  234. /deep/ .u-tab-item {
  235. font-size: 28rpx!important;
  236. }
  237. </style>