search.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <view class="search-page">
  3. <view class="search-box">
  4. <input class="search" type="text" placeholder="搜索" v-model="query.queryName" />
  5. <image class="icon" src="@/static/search.png" mode=""></image>
  6. <button class="btn" type="default" @click="handleSearch">搜索</button>
  7. </view>
  8. <view class="content" v-show="!list.length">
  9. <view class="title-box">
  10. <view class="title">
  11. 历史搜索
  12. </view>
  13. <u-icon name="trash" color="#999" size="42" @click="delSearchHistory"></u-icon>
  14. </view>
  15. <view class="tab-box">
  16. <view class="tab" v-for="(item,index) in tabList" :key="index" @click="handleHistory(item)">
  17. {{item}}
  18. </view>
  19. </view>
  20. </view>
  21. <view class="content" v-show="list.length">
  22. <!-- <view class="tab-group">
  23. <view class="tab" :class="[tab == 1?'active':'']" @click="handleTab(1)">
  24. 店铺
  25. </view>
  26. <view class="tab" :class="[tab == 2?'active':'']" @click="handleTab(2)">
  27. 商品
  28. </view>
  29. </view>
  30. <zs-list mt="0" @load="loadMore" :status="status">
  31. <view :class="[tab == 1?'item':'goods-item']" v-for="(item,index) in list" :key="index">
  32. <template v-if="tab == 1">
  33. <zs-img :src="item.logoPath" width="164rpx" height="164rpx" radius="full"
  34. @click.native="goDetail(item)"></zs-img>
  35. <view class="info">
  36. <view class="title">
  37. {{item.shopVo.shopName}}
  38. </view>
  39. <view class="address">
  40. <image class="position" src="../../static/position.png" mode=""></image>
  41. 距离你{{(item.shopVo.distance/1000).toFixed(2)}}km ·{{item.district}}
  42. </view>
  43. <view class="activity" :class="!item.activityContent?'white':''">
  44. {{item.activityContent || '-'}}
  45. </view>
  46. </view>
  47. </template>
  48. <template v-else>
  49. <zs-img :src="item.goodsImg" width="310rpx" height="310rpx" raduis="full" mode="" ></zs-img>
  50. <view class="goods-name">
  51. {{item.goodsName}}
  52. </view>
  53. <view class="type">
  54. {{goodsTypeObj[item.goodsCode]}}
  55. </view>
  56. <view class="price">
  57. ¥{{item.buyPrice}}
  58. </view>
  59. </template>
  60. </view>
  61. </zs-list> -->
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. getSearchHistory,
  68. saveSearchHistory,
  69. delSearchHistory
  70. } from '@/api/common.js';
  71. import {
  72. search
  73. } from '@/api/shop.js';
  74. export default {
  75. data() {
  76. return {
  77. status: 'more',
  78. result: false,
  79. tab: 1,
  80. tabList: [],
  81. list: [],
  82. query: {
  83. pageCurrent: 1,
  84. pageSize: 10,
  85. 'location.lat': 0,
  86. 'location.lon': 0,
  87. queryName: ''
  88. }
  89. }
  90. },
  91. methods: {
  92. handleHistory(val){
  93. this.query.queryName = val
  94. this.handleSearch()
  95. },
  96. goDetail(item) {
  97. uni.setStorageSync('shopInfo', JSON.stringify(item))
  98. uni.navigateTo({
  99. url: '/detail/shopDetail/shopDetail'
  100. })
  101. },
  102. handleTab(val) {
  103. this.tab = val
  104. this.query.pageCurrent = 1
  105. this.list = []
  106. },
  107. handleSearch() {
  108. this.status = 'more'
  109. this.query.pageCurrent = 1
  110. this.list = []
  111. this.saveSearchHistory()
  112. uni.navigateTo({
  113. url:'./searchResult?search='+this.query.queryName
  114. })
  115. // this.search()
  116. },
  117. getSearchHistory() {
  118. getSearchHistory().then(res => {
  119. if (res.state == 'Success') {
  120. this.tabList = res.content
  121. }
  122. })
  123. },
  124. saveSearchHistory() {
  125. saveSearchHistory({
  126. key: this.query.queryName
  127. }).then(res => {
  128. if (res.state == 'Success') {
  129. this.getSearchHistory()
  130. }
  131. })
  132. },
  133. delSearchHistory() {
  134. delSearchHistory().then(res => {
  135. if (res.state == 'Success') {
  136. this.getSearchHistory()
  137. }
  138. })
  139. },
  140. search() {
  141. if(this.status == 'noMore') return
  142. this.status = 'loading'
  143. search(this.query).then(res => {
  144. if (res.state == 'Success') {
  145. this.saveSearchHistory()
  146. this.list = this.list.concat(res.content.records)
  147. if(res.content.total>=this.list.length){
  148. this.status = 'noMore'
  149. }else{
  150. this.status = 'more'
  151. this.query.pageCurrent++
  152. }
  153. }
  154. })
  155. },
  156. loadMore() {
  157. if(this.query.queryName){
  158. this.search()
  159. }
  160. }
  161. },
  162. onLoad(options) {
  163. let location = JSON.parse(uni.getStorageSync('location'))
  164. this.query['location.lat'] = location.latitude
  165. this.query['location.lon'] = location.longitude
  166. this.getSearchHistory()
  167. },
  168. created() {}
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .search-page {
  173. .search-box {
  174. height: 72rpx;
  175. width: 686rpx;
  176. border-radius: 40rpx 40rpx 40rpx 40rpx;
  177. background: #F6F6F6;
  178. position: relative;
  179. margin: 30rpx auto;
  180. .icon {
  181. width: 37rpx;
  182. height: 37rpx;
  183. position: absolute;
  184. top: 50%;
  185. left: 36rpx;
  186. transform: translateY(-50%);
  187. }
  188. .search {
  189. line-height: 72rpx;
  190. height: 72rpx;
  191. padding-left: 100rpx;
  192. padding-right: 150rpx;
  193. }
  194. .btn {
  195. position: absolute;
  196. top: 8rpx;
  197. right: 10rpx;
  198. width: 128rpx;
  199. height: 56rpx;
  200. line-height: 56rpx;
  201. background: $uni-color-primary;
  202. color: #fff;
  203. font-size: 28rpx;
  204. border-radius: 32rpx;
  205. padding: 0;
  206. }
  207. }
  208. .content{
  209. padding: 0 30rpx;
  210. }
  211. .title-box {
  212. display: flex;
  213. align-items: center;
  214. justify-content: space-between;
  215. .title {
  216. font-weight: bold;
  217. color: #222222;
  218. font-size: 32rpx;
  219. }
  220. }
  221. .tab-box {
  222. display: flex;
  223. flex-wrap: wrap;
  224. align-items: center;
  225. padding: 24rpx 0;
  226. .tab {
  227. padding: 0 20rpx;
  228. line-height: 44rpx;
  229. border-radius: 22rpx;
  230. background: #F6F6F6;
  231. color: #999999;
  232. font-size: 24rpx;
  233. max-width: 700rpx;
  234. white-space: nowrap;
  235. overflow: hidden;
  236. text-overflow: ellipsis;
  237. margin-bottom: 20rpx;
  238. margin-right: 20rpx;
  239. }
  240. }
  241. .tab-group{
  242. display: flex;
  243. align-items: center;
  244. border-bottom: 1rpx solid #F0F0F0;
  245. margin-top: -30rpx;
  246. .tab{
  247. flex: 1;
  248. height: 80rpx;
  249. line-height: 80rpx;
  250. text-align: center;
  251. font-size: 28rpx;
  252. color: #222222;
  253. }
  254. .tab.active{
  255. position: relative;
  256. &::before{
  257. content: '';
  258. position: absolute;
  259. bottom: 0;
  260. left: 50%;
  261. width: 40rpx;
  262. height: 8rpx;
  263. transform: translateX(-50%);
  264. border-radius: 2rpx;
  265. background: $uni-color-primary;
  266. }
  267. }
  268. }
  269. .zs-list {
  270. padding: 0 30rpx;
  271. .item {
  272. display: flex;
  273. padding: 20rpx 30rpx;
  274. background: #fff;
  275. border-radius: 16rpx;
  276. margin: 20rpx 30rpx 0;
  277. .icon{
  278. border-radius: 8px;
  279. }
  280. .info{
  281. flex: 1;
  282. padding-left: 20rpx;
  283. display: flex;
  284. flex-direction: column;
  285. justify-content: space-between;
  286. position: relative;
  287. .title{
  288. font-size: 28rpx;
  289. font-weight: bold;
  290. width: 340rpx;
  291. white-space: nowrap;
  292. overflow: hidden;
  293. text-overflow: ellipsis;
  294. margin-top: 10rpx;
  295. }
  296. .address{
  297. color: #bebebe;
  298. display: flex;
  299. align-items: center;
  300. font-size: 24rpx;
  301. .u-icon{
  302. align-self: flex-start;
  303. }
  304. .position {
  305. width: 25rpx;
  306. height: 29rpx;
  307. margin-right: 8rpx;
  308. }
  309. }
  310. .activity.white{
  311. color: #fff;
  312. }
  313. .activity{
  314. font-size: 24rpx;
  315. color: #E77F57;
  316. line-height: 42rpx;
  317. }
  318. }
  319. }
  320. .goods-item{
  321. padding: 12rpx;
  322. background: #FFFFFF;
  323. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  324. border-radius: 16rpx;
  325. width: 334rpx;
  326. box-sizing: border-box;
  327. margin-top: 20rpx;
  328. .goods-name{
  329. font-weight: bold;
  330. color: #222222;
  331. font-size: 24rpx;
  332. margin: 16rpx 0;
  333. overflow: hidden;
  334. width: 100%;
  335. text-overflow: ellipsis;
  336. display: -webkit-box;
  337. -moz-box-orient: vertical;
  338. -webkit-line-clamp: 2;
  339. }
  340. .type{
  341. color: #AAAAAA;
  342. font-size: 20rpx;
  343. }
  344. .price{
  345. font-weight: bold;
  346. color: #FF4C3A;
  347. font-size: 28rpx;
  348. margin-top: 16rpx;
  349. }
  350. }
  351. }
  352. }
  353. </style>