search.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search placeholder="热门搜索" v-model="searchValue" :showAction="true" @search="search" actionText="取消" @custom="custom" @change="change"></u-search>
  5. </view>
  6. <view v-if="is_search == 0">
  7. <view class="hflex acenter jbetween">
  8. <view class="title">搜索历史</view>
  9. <u-icon name="trash" color="#555555" size="16" @click="deleHis"></u-icon>
  10. </view>
  11. <view class="list hflex acenter fwrap">
  12. <block v-for="(item,index) in history" :key="index">
  13. <view class="item" @click="search(item)">{{item}}</view>
  14. </block>
  15. </view>
  16. <view class="">
  17. <view class="title">热门搜索</view>
  18. </view>
  19. <view class="list hflex acenter fwrap">
  20. <block v-for="(item,index) in hotList" :key="index">
  21. <view class="item hflex acenter" @click="search(item.name)">
  22. <view>{{item.name}}</view>
  23. <view class="hot" v-if="item.is_hot == 1">热</view>
  24. </view>
  25. </block>
  26. </view>
  27. </view>
  28. <view v-else class="bg">
  29. <view class="list2 hflex acenter fwrap">
  30. <block v-for="(item,index) in searchList" :key="index">
  31. <view class="list_item" @click="toDetail(item.id)">
  32. <image :src="item.cover" mode="aspectFill" class="item_img"></image>
  33. <view style="box-sizing: border-box;padding: 12rpx 10rpx 0;">
  34. <view class="item_name">{{item.name}}</view>
  35. <!-- <view class="hflex acenter " style="padding-top: 12rpx;">
  36. <view class="item_type">{{item.material}}</view>
  37. <view class="item_type">{{item.parts}}</view>
  38. </view> -->
  39. <view class="item_price">¥{{item.price_selling}}</view>
  40. </view>
  41. </view>
  42. </block>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import $api from '@/static/js/api.js'
  49. var that = ''
  50. export default {
  51. data() {
  52. return {
  53. searchValue: '',
  54. history: [],
  55. hotList: [
  56. ],
  57. is_search: 0,
  58. searchList: [
  59. ],
  60. page: 1,
  61. limit: 10,
  62. total: 10
  63. }
  64. },
  65. onLoad(options) {
  66. that = this
  67. if(options.value) {
  68. that.searchValue = options.value
  69. that.search(that.searchValue)
  70. that.change(that.searchValue)
  71. }
  72. that.history = uni.getStorageSync('historySC')
  73. if(!that.history) {
  74. that.history = []
  75. }
  76. that.getHotList()
  77. },
  78. methods: {
  79. getHotList() {
  80. $api.req({
  81. url: '/data/api.Goods/hotsearch'
  82. }, function(res) {
  83. if(res.code == 1) {
  84. that.hotList = res.data
  85. }
  86. })
  87. },
  88. search(e) {
  89. that.page = 1
  90. that.searchList = []
  91. console.log(e);
  92. var is_some = 0
  93. that.searchValue = e
  94. if (that.history.length > 0) {
  95. for(var i=0;i<that.history.length;i++) {
  96. if(that.history[i] == that.searchValue) {
  97. is_some = 1;
  98. }
  99. }
  100. if(is_some == 0) {
  101. that.history.unshift(that.searchValue)
  102. }
  103. } else {
  104. that.history.push(that.searchValue)
  105. }
  106. if(that.history.length > 9) {
  107. that.history.pop()
  108. }
  109. uni.setStorageSync("historySC",that.history)
  110. that.is_search = 1
  111. that.getList()
  112. },
  113. toDetail(id) {
  114. $api.jump('/page_shop/pages/good/detail?id=' + id)
  115. },
  116. getList() {
  117. $api.req({
  118. url: '/data/api.Goods/getGoods',
  119. data: {
  120. name: that.searchValue,
  121. page: that.page
  122. }
  123. }, function(res) {
  124. if(res.code == 1) {
  125. if(that.page == 1) {
  126. that.searchList = res.data.list
  127. } else {
  128. that.searchList = that.searchList.concat(res.data.list)
  129. }
  130. that.total = res.data.page.total
  131. that.limit = res.data.page.limit
  132. }
  133. })
  134. },
  135. change(e) {
  136. if(e == '') {
  137. that.is_search = 0
  138. }
  139. },
  140. custom() {
  141. $api.jump(-1)
  142. },
  143. deleHis() {
  144. uni.removeStorageSync('historySC')
  145. that.history = []
  146. },
  147. onReachBottom() {
  148. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  149. $api.info("没有更多了")
  150. } else {
  151. that.page++
  152. that.getList()
  153. }
  154. }
  155. },
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .content {
  160. padding: 0 30rpx;
  161. position: relative;
  162. .top {
  163. width: 100%;
  164. background: #fff;
  165. padding: 16rpx 30rpx 8rpx;
  166. box-sizing: border-box;
  167. // margin-top: ;
  168. }
  169. .title {
  170. font-size: 30rpx;
  171. font-weight: 500;
  172. color: #222222;
  173. line-height: 42rpx;
  174. padding: 24rpx 0;
  175. }
  176. .list {
  177. .item {
  178. width: auto;
  179. background: #F2F2F2;
  180. border-radius: 12px;
  181. box-sizing: border-box;
  182. padding: 8rpx 20rpx;
  183. font-size: 24rpx;
  184. font-weight: 400;
  185. color: #555555;
  186. margin: 0 24rpx 28rpx 0;
  187. .hot {
  188. width: 28rpx;
  189. height: 28rpx;
  190. margin-left: 12rpx;
  191. background-color: #ff5c37;
  192. border-radius: 20%;
  193. font-size: 18rpx;
  194. color: #fff;
  195. text-align: center;
  196. line-height: 28rpx;
  197. }
  198. }
  199. }
  200. .bg{
  201. position: absolute;
  202. left: 0;
  203. top: 97rpx;
  204. min-height: calc(100vh - 97rpx);
  205. width: 100%;
  206. background: #F4F4F4;
  207. box-sizing: border-box;
  208. padding: 20rpx 30rpx;
  209. }
  210. .list2 {
  211. .list_item {
  212. width: 334rpx;
  213. background: #FFFFFF;
  214. border-radius: 20rpx;
  215. box-sizing: border-box;
  216. padding: 0 0 22rpx;
  217. margin: 0 22rpx 20rpx 0;
  218. .item_img {
  219. width: 334rpx;
  220. height: 280rpx;
  221. border-radius: 20rpx 20rpx 0px 0px;
  222. }
  223. .item_name {
  224. width: 100%;
  225. text-overflow: ellipsis;
  226. overflow: hidden;
  227. display: -webkit-box;
  228. -webkit-box-orient: vertical;
  229. box-orient: vertical;
  230. line-clamp: 2;
  231. -webkit-line-clamp: 2;
  232. font-size: 28rpx;
  233. font-weight: 400;
  234. color: #222222;
  235. line-height: 40rpx;
  236. }
  237. .item_type {
  238. height: 28rpx;
  239. background: #F5F5F5;
  240. border-radius: 4rpx;
  241. font-size: 20rpx;
  242. font-weight: 400;
  243. color: #999999;
  244. line-height: 28rpx;
  245. padding: 0 14rpx;
  246. margin-right: 12rpx;
  247. }
  248. .item_price {
  249. padding-top: 12rpx;
  250. font-size: 28rpx;
  251. font-weight: bold;
  252. color: #FF4747;
  253. line-height: 32rpx;
  254. }
  255. }
  256. .list_item:nth-child(2n+2) {
  257. margin: 0 0 20rpx;
  258. }
  259. }
  260. }
  261. </style>