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

260 lines
6.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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 v-if="tab_index == 0">
  19. <shop-list :list="goods_list" ref="searchWaterfall"></shop-list>
  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 shopList from '@/components/shopList/shopList.vue';
  41. export default {
  42. components: {
  43. shopList
  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.getSearchGoodsList(options.value);
  73. this.getSearchBrandList(options.value);
  74. }
  75. },
  76. methods: {
  77. // 点击取消,返回上一个页面
  78. customClick(){
  79. this.$toBack();
  80. },
  81. // 开始搜索
  82. search(value){
  83. if(!value || !value.trim()) return this.$msg('搜索内容不能为空');
  84. // 重置页面请求值
  85. this.page = 1;
  86. this.isPage = true;
  87. // this.$refs.searchWaterfall[0].clear();
  88. // 执行上一个页面的保存搜索历史
  89. let pages = getCurrentPages();
  90. let beforePage = pages[pages.length - 2]; // 上个页面
  91. if(beforePage){
  92. beforePage.$vm.updateHistory(value).then(() => {
  93. beforePage.$vm.setHistorySearch();
  94. })
  95. this.getSearchGoodsList(value);
  96. this.getSearchBrandList(value);
  97. }else{
  98. this.$msg('页面路径出错,当前搜索值将不被记录搜索历史').then(() => {
  99. this.getSearchGoodsList(value);
  100. this.getSearchBrandList(value);
  101. })
  102. }
  103. },
  104. // 获取搜索商品列表
  105. getSearchGoodsList(value){
  106. uni.showLoading({
  107. title: '正在搜索中'
  108. })
  109. this.$http.get({
  110. api: 'api/store/list',
  111. data: {
  112. keyword: value,
  113. page: this.page
  114. }
  115. }).then(res => {
  116. uni.hideLoading();
  117. if(res.data.status){
  118. let goods = res.data.data || [];
  119. let pagination = res.data.meta.pagination;
  120. let isPage = pagination.current_page != pagination.total_pages;
  121. this.isPage = isPage;
  122. if(goods.length <= 0){
  123. this.tab_list[0].name = `商品(0)`;
  124. return;
  125. }
  126. let list = goods.map(item => {
  127. return {
  128. id: item.id,
  129. original_price: item.market_price,
  130. picture: item.img,
  131. pictures: [item.img],
  132. price: item.sell_price,
  133. sale: item.sale_count,
  134. title: item.name
  135. }
  136. })
  137. if(this.page == 1){
  138. this.goods_list = list;
  139. }else{
  140. this.goods_list.push(...list);
  141. }
  142. console.log(this.goods_list)
  143. this.tab_list[0].name = `商品(${this.goods_list.length})`;
  144. }else{
  145. this.$msg(res.data.message || '服务器错误,请稍后再试');
  146. }
  147. }).catch(err => uni.hideLoading());
  148. },
  149. // 获取搜索品牌列表
  150. getSearchBrandList(value){
  151. this.$http.get({
  152. api: 'api/brand',
  153. data: {
  154. name: value
  155. }
  156. }).then(res => {
  157. if(res.data.status){
  158. let list = res.data.data.list || [];
  159. this.brand_list = list;
  160. this.tab_list[1].name = `商户(${list.length})`;
  161. }else{
  162. this.$msg(res.data.message || '服务器错误,请稍后再试');
  163. }
  164. })
  165. },
  166. // 切换tab
  167. tabChange(event){
  168. this.tab_current = event;
  169. },
  170. // 切换swiper
  171. swiperChange(event){
  172. this.tab_current = event.detail.current;
  173. },
  174. // 商品scroll滚动到底部
  175. scrolltolower(){
  176. // 只做商品加载下一页,品牌不做
  177. if(this.tab_current == 0){
  178. if(this.isPage){
  179. this.page++;
  180. this.getSearchGoodsList(this.value);
  181. }else{
  182. this.$msg('没有更多啦~');
  183. }
  184. }else{
  185. this.$msg('没有更多啦~');
  186. }
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .head{
  193. padding: 30rpx 32rpx;
  194. }
  195. .scroll-content{
  196. padding: 30rpx 32rpx;
  197. }
  198. .shop-box{
  199. width: 100%;
  200. height: 100rpx;
  201. display: flex;
  202. &:nth-child(n+2){
  203. margin-top: 60rpx;
  204. }
  205. .shop-img{
  206. width: 100rpx;
  207. height: 100rpx;
  208. // background-color: #EEEEEE;
  209. border-radius: 5rpx;
  210. margin-right: 15rpx;
  211. }
  212. .shop-info{
  213. width: 570rpx;
  214. height: 100rpx;
  215. display: flex;
  216. flex-direction: column;
  217. justify-content: space-between;
  218. &>view:nth-child(1){
  219. font-size: 36rpx;
  220. color: #222222;
  221. font-weight: bold;
  222. }
  223. &>view:nth-child(2){
  224. font-size: 24rpx;
  225. color: #777777;
  226. }
  227. }
  228. }
  229. // tabs 样式修改
  230. /deep/.u-scroll-box {
  231. display: flex;
  232. justify-content: center;
  233. align-items: center;
  234. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  235. }
  236. /deep/.u-scroll-box .u-tab-bar {
  237. background-color: #15716E!important;
  238. width: 80rpx!important;
  239. position: absolute;
  240. left: 0;
  241. bottom: -12rpx;
  242. }
  243. /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar {
  244. background-color: #15716E!important;
  245. width: 56rpx!important;
  246. position: absolute;
  247. height: 5rpx!important;
  248. left: 8rpx;
  249. bottom: -4rpx;
  250. }
  251. /deep/ .u-tab-item {
  252. font-size: 28rpx!important;
  253. }
  254. </style>