index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="h-120 flex-between-center px-20">
  4. <view class="h-72 bg--w111-f5f5f5 rd-36rpx px-32 flex-1 flex-y-center relative">
  5. <text class="iconfont icon-ic_search text--w111-999"></text>
  6. <input type="text" confirm-type="search" placeholder="请输入要查询的内容" @confirm="inputConfirm" @input="setValue"
  7. class="fs-28 w-438 text--w111-333 pl-18 line1" v-model="searchValue" />
  8. <text class="iconfont icon-ic_close1 fs-28 text--w111-999 z-10" v-show="searchValue"
  9. @tap="clearSearchVal"></text>
  10. </view>
  11. <view class="fs-28 text--w111-333 ml-32" @tap='searchBut'>搜索</view>
  12. </view>
  13. <view class="px-20" v-if="history.length">
  14. <view class="flex-between-center mt-16 mb-24">
  15. <view class="fs-28 lh-40rpx fw-500 text--w111-333">历史搜索</view>
  16. <text class="iconfont icon-ic_delete fs-28 text--w111-999" @tap="clear"></text>
  17. </view>
  18. <view class="flex flex-wrap">
  19. <text class="flex-center h-56 line1 rd-28rpx bg--w111-f5f5f5 px-24 fs-24 text--w111-666 mr-24 mb-16"
  20. v-for="(item,index) in isShowMore ? history : history.slice(0,7)" :key="index"
  21. @tap='setHotSearchValue(item.keyword)' v-if="item.keyword">{{item.keyword}}</text>
  22. <view class="w-56 h-56 rd-28rpx bg--w111-f5f5f5 flex-center text--w111-666"
  23. v-if="history.length > 7" @tap="isShowMore = !isShowMore">
  24. <text class="iconfont fs-24" :class="isShowMore ? 'icon-ic_uparrow' : 'icon-ic_downarrow'"></text>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="px-20">
  29. <view class="flex-between-center mt-40 mb-24">
  30. <view class="fs-28 lh-40rpx fw-500 text--w111-333">热门搜索</view>
  31. <text class="iconfont icon-ic_Refresh fs-28 text--w111-999" :class="isSpin ? 'spin' : ''" @tap="refresh"></text>
  32. </view>
  33. <view class="flex flex-wrap">
  34. <view class="flex-center search_item h-56 rd-28rpx px-24 fs-24 mr-24 mb-16"
  35. v-for="(item,index) in hotSearchList" :key="index"
  36. :style="{'color':item.color,'background-color':item.bg_color,border: item.border_color ? '1px solid ' + item.border_color : 'none'}"
  37. @tap='setHotSearchValue(item.name)'>
  38. <view class="flex-y-center">
  39. <image v-if="item.icon" :src="item.icon" class="w-24 h-24 rd-4rpx mr-8"></image>
  40. <text>{{item.name}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view>
  46. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-730 mt-32 pl-20" show-scrollbar="false">
  47. <view class="inline-block mr-20" v-if="salesRecommendList.length">
  48. <view class="w-454 rd-24rpx gradient_bg pt-22 pb-8">
  49. <view class="fs-28 font-red lh-40rpx fw-600 pl-24 mb-18 flex-y-center"
  50. @tap="goRank(1)">
  51. <image src="@/static/img/sales_icon.png" class="w-40 h-40"></image>
  52. <text class="pl-8">销量</text>
  53. </view>
  54. <view class="mx-8 rd-24rpx bg--w111-fff h-748 p-20">
  55. <view class="flex-y-center" v-if="salesRecommendList[0]" @tap="goDetail(salesRecommendList[0])">
  56. <view class="relative w-108 h-108">
  57. <image :src="salesRecommendList[0].image" class="w-108 h-108 rd-16rpx"></image>
  58. <view class="rank-count rank-count1 fs-24 text--w111-fff flex-center">1</view>
  59. </view>
  60. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  61. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{salesRecommendList[0].store_name}}</view>
  62. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{salesRecommendList[0].store_info}}</view>
  63. </view>
  64. </view>
  65. <view class="flex-y-center mt-16" v-if="salesRecommendList[1]" @tap="goDetail(salesRecommendList[1])">
  66. <view class="relative w-108 h-108">
  67. <image :src="salesRecommendList[1].image" class="w-108 h-108 rd-16rpx"></image>
  68. <view class="rank-count rank-count2 fs-24 text--w111-fff flex-center">2</view>
  69. </view>
  70. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  71. <view class="flex-between-center">
  72. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{salesRecommendList[1].store_name}}</view>
  73. </view>
  74. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{salesRecommendList[1].store_info}}</view>
  75. </view>
  76. </view>
  77. <view class="flex-y-center mt-16 mb-34" v-if="salesRecommendList[2]" @tap="goDetail(salesRecommendList[2])">
  78. <view class="relative w-108 h-108">
  79. <image :src="salesRecommendList[2].image" class="w-108 h-108 rd-16rpx"></image>
  80. <view class="rank-count rank-count3 fs-24 text--w111-fff flex-center">3</view>
  81. </view>
  82. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  83. <view class="flex-between-center">
  84. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{salesRecommendList[2].store_name}}</view>
  85. </view>
  86. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{salesRecommendList[2].store_info}}</view>
  87. </view>
  88. </view>
  89. <view class="flex-between-center scroll_cell" v-for="(item,index) in salesRecommendList.slice(3)" :key="index" @tap="goDetail(item)">
  90. <view class="flex-y-center">
  91. <text class="inline-block w-30 h-32 lh-32rpx text--w111-fff text-center fs-24 rank_4">{{index + 4}}</text>
  92. <text class="fs-26 text--w111-333 ml-20 w-360 line1">{{item.store_name}}</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="inline-block mr-20" v-if="scoreRecommendList.length">
  99. <view class="w-454 rd-24rpx gradient_bg pt-22 pb-8">
  100. <view class="fs-28 font-red lh-40rpx fw-600 pl-24 mb-18 flex-y-center"
  101. @tap="goRank(2)">
  102. <image src="@/static/img/sales_icon.png" class="w-40 h-40"></image>
  103. <text class="pl-8">评分</text>
  104. </view>
  105. <view class="mx-8 rd-24rpx bg--w111-fff h-748 p-20">
  106. <view class="flex-y-center" v-if="scoreRecommendList[0]" @tap="goDetail(scoreRecommendList[0])">
  107. <view class="relative w-108 h-108">
  108. <image :src="scoreRecommendList[0].image" class="w-108 h-108 rd-16rpx"></image>
  109. <view class="rank-count rank-count1 fs-24 text--w111-fff flex-center">1</view>
  110. </view>
  111. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  112. <view class="flex-between-center">
  113. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{scoreRecommendList[0].store_name}}</view>
  114. </view>
  115. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{scoreRecommendList[0].store_info}}</view>
  116. </view>
  117. </view>
  118. <view class="flex-y-center mt-16" v-if="scoreRecommendList[1]" @tap="goDetail(scoreRecommendList[1])">
  119. <view class="relative w-108 h-108">
  120. <image :src="scoreRecommendList[1].image" class="w-108 h-108 rd-16rpx"></image>
  121. <view class="rank-count rank-count2 fs-24 text--w111-fff flex-center">2</view>
  122. </view>
  123. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  124. <view class="flex-between-center">
  125. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{scoreRecommendList[1].store_name}}</view>
  126. </view>
  127. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{scoreRecommendList[1].store_info}}</view>
  128. </view>
  129. </view>
  130. <view class="flex-y-center mt-16 mb-34" v-if="scoreRecommendList[2]" @tap="goDetail(scoreRecommendList[2])">
  131. <view class="relative w-108 h-108">
  132. <image :src="scoreRecommendList[2].image" class="w-108 h-108 rd-16rpx"></image>
  133. <view class="rank-count rank-count3 fs-24 text--w111-fff flex-center">3</view>
  134. </view>
  135. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  136. <view class="flex-between-center">
  137. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{scoreRecommendList[2].store_name}}</view>
  138. </view>
  139. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{scoreRecommendList[2].store_info}}</view>
  140. </view>
  141. </view>
  142. <view class="flex-between-center scroll_cell" v-for="(item,index) in scoreRecommendList.slice(3)" :key="index" @tap="goDetail(item)">
  143. <view class="flex-y-center">
  144. <text class="inline-block w-30 h-32 lh-32rpx text--w111-fff text-center fs-24 rank_4">{{index + 4}}</text>
  145. <text class="fs-26 text--w111-333 ml-20 w-360 line1">{{item.store_name}}</text>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. <view class="inline-block mr-20" v-if="collectRecommendList.length">
  152. <view class="w-454 rd-24rpx gradient_bg pt-22 pb-8">
  153. <view class="fs-28 font-red lh-40rpx fw-600 pl-24 mb-18 flex-y-center"
  154. @tap="goRank(3)">
  155. <image src="@/static/img/sales_icon.png" class="w-40 h-40"></image>
  156. <text class="pl-8">收藏</text>
  157. </view>
  158. <view class="mx-8 rd-24rpx bg--w111-fff h-748 p-20">
  159. <view class="flex-y-center" v-if="collectRecommendList[0]" @tap="goDetail(collectRecommendList[0])">
  160. <view class="relative w-108 h-108">
  161. <image :src="collectRecommendList[0].image" class="w-108 h-108 rd-16rpx"></image>
  162. <view class="rank-count rank-count1 fs-24 text--w111-fff flex-center">1</view>
  163. </view>
  164. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  165. <view class="flex-between-center">
  166. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{collectRecommendList[0].store_name}}</view>
  167. </view>
  168. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{collectRecommendList[0].store_info}}</view>
  169. </view>
  170. </view>
  171. <view class="flex-y-center mt-16" v-if="collectRecommendList[1]" @tap="goDetail(collectRecommendList[1])">
  172. <view class="relative w-108 h-108">
  173. <image :src="collectRecommendList[1].image" class="w-108 h-108 rd-16rpx"></image>
  174. <view class="rank-count rank-count2 fs-24 text--w111-fff flex-center">2</view>
  175. </view>
  176. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  177. <view class="flex-between-center">
  178. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{collectRecommendList[1].store_name}}</view>
  179. </view>
  180. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{collectRecommendList[1].store_info}}</view>
  181. </view>
  182. </view>
  183. <view class="flex-y-center mt-16 mb-34" v-if="collectRecommendList[2]" @tap="goDetail(collectRecommendList[2])">
  184. <view class="relative w-108 h-108">
  185. <image :src="collectRecommendList[2].image" class="w-108 h-108 rd-16rpx"></image>
  186. <view class="rank-count rank-count3 fs-24 text--w111-fff flex-center">3</view>
  187. </view>
  188. <view class="flex-1 h-108 flex-col flex-x-center ml-16">
  189. <view class="flex-between-center">
  190. <view class="w-260 fs-26 text--w111-333 lh-40rpx line1">{{collectRecommendList[2].store_name}}</view>
  191. </view>
  192. <view class="w-260 fs-22 text--w111-999 lh-30rpx mt-8 line1">{{collectRecommendList[2].store_info}}</view>
  193. </view>
  194. </view>
  195. <view class="flex-between-center scroll_cell" v-for="(item,index) in collectRecommendList.slice(3)" :key="index" @tap="goDetail(item)">
  196. <view class="flex-y-center">
  197. <text class="inline-block w-30 h-32 lh-32rpx text--w111-fff text-center fs-24 rank_4">{{index + 4}}</text>
  198. <text class="fs-26 text--w111-333 ml-20 w-360 line1">{{item.store_name}}</text>
  199. </view>
  200. </view>
  201. </view>
  202. </view>
  203. </view>
  204. </scroll-view>
  205. </view>
  206. <scroll-view scroll-y="true" class="fuzzy_modal" :style="{height:fuzzyHeight + 'px',top: 60 + 'px'}"
  207. v-if="newPartyList.length" @touchmove.stop.prevent="moveStop">
  208. <view class="cell" v-for="(item,index) in newPartyList" :key="index"
  209. @tap="setCommentSearch(item.id)">
  210. <view class="keyword line1" v-html="item.keyword"></view>
  211. </view>
  212. </scroll-view>
  213. </view>
  214. </template>
  215. <script>
  216. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  217. import home from '@/components/home/index.vue'
  218. import {
  219. getSearchKeyword,
  220. getSearchRecommendApi,
  221. getHotWordApi
  222. } from '@/api/store.js';
  223. import { searchList, clearSearch } from '@/api/api.js';
  224. import recommend from '@/components/recommend';
  225. import colors from "@/mixins/color";
  226. import { goShopDetail } from '@/libs/order.js';
  227. import { HTTP_REQUEST_URL } from '@/config/app.js';
  228. import { Debounce } from '@/utils/validate.js'
  229. export default {
  230. components: {
  231. recommend,
  232. home
  233. },
  234. mixins: [colors],
  235. data() {
  236. return {
  237. hostProduct: [],
  238. searchValue: '',
  239. focus: true,
  240. bastList: [],
  241. hotSearchList: [],
  242. isSpin:false,
  243. first: 0,
  244. limit: 8,
  245. page: 1,
  246. loading: false,
  247. loadend: false,
  248. loadTitle: '加载更多',
  249. hotPage: 1,
  250. isScroll: true,
  251. history: [],
  252. imgHost: HTTP_REQUEST_URL,
  253. salesRecommendList:[],
  254. scoreRecommendList:[],
  255. collectRecommendList:[],
  256. sysHeight:sysHeight,
  257. newPartyList: [], //模糊搜索关键词列表
  258. isShowMore: false
  259. };
  260. },
  261. computed: {
  262. fuzzyHeight() {
  263. let screenHeight = uni.getSystemInfoSync().screenHeight;
  264. return screenHeight - this.sysHeight - 56;
  265. }
  266. },
  267. onLoad(e) {
  268. this.searchValue = e.searchVal || '';
  269. this.getSearchHotKeywords();
  270. this.getSearchRecommend();
  271. setTimeout(()=>{
  272. this.newPartySearch();
  273. },1000)
  274. },
  275. onShow: function(e) {
  276. uni.removeStorageSync('form_type_cart');
  277. this.searchList();
  278. },
  279. methods: {
  280. refresh(){
  281. this.isSpin = true;
  282. this.getSearchHotKeywords();
  283. },
  284. // 获取搜索热词
  285. getSearchHotKeywords(){
  286. getHotWordApi().then(res=>{
  287. this.hotSearchList = res.data;
  288. setTimeout(_=>{
  289. this.isSpin = false;
  290. },1000)
  291. })
  292. },
  293. searchList() {
  294. searchList({
  295. page: 1,
  296. limit: 10
  297. }).then(res => {
  298. this.history = res.data;
  299. });
  300. },
  301. clear() {
  302. let that = this;
  303. clearSearch().then(res => {
  304. uni.showToast({
  305. title: res.msg,
  306. success() {
  307. that.history = [];
  308. }
  309. });
  310. });
  311. },
  312. inputConfirm: function(event) {
  313. if (event.detail.value) {
  314. uni.hideKeyboard();
  315. this.setHotSearchValue(event.detail.value);
  316. }
  317. },
  318. setValue: Debounce(function(e){
  319. this.newPartySearch();
  320. }),
  321. newPartySearch: function() {
  322. getSearchKeyword({keyword:this.searchValue}).then(res => {
  323. this.newPartyList = res.data.list;
  324. this.newPartyList.map((item) => {
  325. this.$set(item,'keyword',this.brightKeyword(item.store_name,res.data.keyword));
  326. });
  327. });
  328. },
  329. brightKeyword(val,keyword) {
  330. if (val.indexOf(keyword) > -1) {
  331. val = `<p class="line1">${val}</p>`
  332. return val.replace(keyword, `<span style="color: #C9771E;">${keyword}</span>`);
  333. } else {
  334. return val;
  335. }
  336. },
  337. setCommentSearch(id) {
  338. uni.navigateTo({
  339. url:'/pages/goods/goods_list/index?productId=' + id
  340. })
  341. },
  342. setHotSearchValue: function(event) {
  343. this.$set(this, 'searchValue', event);
  344. this.focus = false;
  345. this.searchBut();
  346. },
  347. searchBut: function() {
  348. let that = this;
  349. that.focus = false;
  350. if (that.searchValue.length > 0) {
  351. this.newPartyList = [];
  352. uni.navigateTo({
  353. url:'/pages/goods/goods_list/index?searchValue=' + that.searchValue
  354. })
  355. } else {
  356. return this.$util.Tips({
  357. title: '请输入要搜索的商品',
  358. icon: 'none',
  359. duration: 1000,
  360. mask: true,
  361. });
  362. }
  363. },
  364. getSearchRecommend(){
  365. getSearchRecommendApi(1).then(res=>{
  366. this.salesRecommendList = res.data;
  367. })
  368. getSearchRecommendApi(2).then(res=>{
  369. this.scoreRecommendList= res.data;
  370. })
  371. getSearchRecommendApi(3).then(res=>{
  372. this.collectRecommendList= res.data;
  373. })
  374. },
  375. // 去详情页
  376. goDetail(item) {
  377. goShopDetail(item, this.uid).catch(res => {
  378. uni.navigateTo({
  379. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  380. });
  381. });
  382. },
  383. goRank(type){
  384. uni.navigateTo({
  385. url:`/pages/columnGoods/rank/index?type=${type}`
  386. })
  387. },
  388. clearSearchVal(){
  389. this.searchValue = '';
  390. this.newPartyList = [];
  391. }
  392. }
  393. }
  394. </script>
  395. <style>
  396. page {
  397. background-color: #fff;
  398. }
  399. </style>
  400. <style lang="scss" scoped>
  401. .font-red{
  402. color: #e93323;
  403. }
  404. .gradient_bg {
  405. background: linear-gradient(172deg, rgba(255, 250, 218, 0.15) 0%, #fceae9 100%), linear-gradient(112deg, #fadfdf 0%, rgba(252, 234, 233, 0) 100%);
  406. }
  407. .max-200{
  408. max-width: 200rpx;
  409. }
  410. .pb-8{
  411. padding-bottom:8rpx;
  412. }
  413. .w-40{
  414. width: 40rpx;
  415. }
  416. .h-40{
  417. height:40rpx;
  418. }
  419. .search_item{
  420. color: #666;
  421. background-color: #f5f5f5;
  422. }
  423. .rank-count{
  424. width:30rpx;
  425. height:32rpx;
  426. position: absolute;
  427. top:0;
  428. left:0;
  429. background-size: cover;
  430. }
  431. .rank-count1{
  432. background-image:url('@/static/img/rank1_icon.png');
  433. }
  434. .rank-count2{
  435. background-image:url('@/static/img/rank2_icon.png');
  436. }
  437. .rank-count3{
  438. background-image:url('@/static/img/rank3_icon.png');
  439. }
  440. .rank_4{
  441. background-image:url('../static/rank4_icon.png');
  442. background-size:100%;
  443. }
  444. .scroll_cell ~ .scroll_cell{
  445. margin-top: 32rpx;
  446. }
  447. .fuzzy_modal {
  448. background-color: #FFF;
  449. position: fixed;
  450. width: 100%;
  451. left: 0;
  452. box-sizing: border-box;
  453. .cell {
  454. width: 100%;
  455. height: 88rpx;
  456. border-bottom: 0.5px solid #f5f5f5;
  457. .keyword {
  458. height: 88rpx;
  459. line-height: 88rpx;
  460. font-size: 28rpx;
  461. font-family: PingFangSC-Regular, PingFang SC;
  462. font-weight: 400;
  463. color: #1B1B1B;
  464. padding-left: 32rpx;
  465. flex: 1;
  466. }
  467. }
  468. }
  469. .spin{
  470. animation-name: spin;
  471. animation-duration: 1s;
  472. animation-timing-function: linear;
  473. animation-iteration-count: infinite;
  474. transform-origin: center center;
  475. display: inline-block;
  476. }
  477. @keyframes spin{
  478. from{
  479. transform: rotate(0deg);
  480. }
  481. to{
  482. transform: rotate(360deg);
  483. }
  484. }
  485. .icon-ic_close1{
  486. position: absolute;
  487. right: 20rpx;
  488. top: 50%;
  489. transform: translateY(-50%);
  490. }
  491. </style>