search.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="search">
  3. <view class="search_head flexs">
  4. <view class="search_head_ipt flexs">
  5. <image src="https://chaomd.liuniu946.com/image/home/sousuo@2x.png" mode=""></image>
  6. <input type="text" @confirm="search" v-model="keyword" placeholder="关键词搜索" placeholder-style="color:#999999" />
  7. </view>
  8. <view class="search_head_cancel center" @click="cancelKeyword">取消</view>
  9. </view>
  10. <view class="search_box">
  11. <view class="search_main" v-if="isSearch">
  12. <view class="search_main_name">搜索历史</view>
  13. <view class="search_main_ul flexs">
  14. <view class="search_main_li center" v-for="(item,index) in searchList" :key="index" @click="selectKeyword(item)">{{ item }}</view>
  15. <view class="search_main_li center" v-if="searchList.length == 0">搜索暂无数据</view>
  16. </view>
  17. </view>
  18. <view class="home_recommend_ul flex" v-else>
  19. <view class="home_recommend_li" v-for="(item,index) in shopList" :key="index" @click="goMessage(item,0)">
  20. <view class="home_recommend_li_img">
  21. <view class="home_recommend_li_img_top flex">
  22. <view class="home_recommend_li_img_box">
  23. <image :src="item.image" mode="aspectFill"></image>
  24. </view>
  25. <view class="home_recommend_li_img_right" v-if="item.right.length != 0">
  26. <image :src="items" mode="aspectFill" v-for="(items,index) in item.right" :key="index"></image>
  27. </view>
  28. </view>
  29. <view class="home_recommend_li_img_bot">
  30. <image :src="items" mode="aspectFill" v-for="(items,index) in item.bot" :key="index"></image>
  31. </view>
  32. </view>
  33. <view class="home_recommend_li_main">
  34. <view class="home_recommend_li_price">价值:¥{{ item.price_min }}~¥{{ item.price_max }}</view>
  35. <view class="home_recommend_li_name">{{ item.box_name }}</view>
  36. <view class="home_recommend_li_glod flex">
  37. <text>{{ item.coin_price }}金币</text>
  38. <text>共{{ item.goods_num }}款商品</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. page:1,
  51. pages:0,
  52. isSearch:true,
  53. keyword:'',
  54. shopList:[],//
  55. searchList:[],//
  56. };
  57. },
  58. methods:{
  59. //去详情
  60. goMessage (item,type) {
  61. uni.navigateTo({url:'/pages/index/details?id=' + item.box_id + '&type=' + type})
  62. },
  63. //关键词搜索
  64. selectKeyword (item) {
  65. this.page = 1
  66. this.isSearch = false
  67. this.keyword = item
  68. this.getBoxListByCategory()
  69. },
  70. //取消搜索
  71. cancelKeyword () {
  72. uni.navigateBack()
  73. // this.keyword = ''
  74. // this.isSearch = true
  75. },
  76. //搜索
  77. search () {
  78. this.page = 1
  79. this.shopList = []
  80. this.isSearch = false
  81. if (!this.keyword) return
  82. this.getBoxListByCategory()
  83. },
  84. getBoxListByCategory () {
  85. this.$api.search({page:this.page,pagesize:'10',search:this.keyword,msg:'数据加载中'}).then(res=>{
  86. if (res.code === 1) {
  87. res.data.data.forEach(item=>{
  88. item.image = item.goods_images[0]
  89. item.right = []
  90. item.bot = []
  91. item.goods_images.forEach((em,index)=>{
  92. if (index > 0 && index < 3) {
  93. item.right.push(em)
  94. }
  95. if (index > 2) {
  96. item.bot.push(em)
  97. }
  98. })
  99. })
  100. this.getSearch()
  101. this.shopList = this.page == 1 ? res.data.data : [...rhis.shopList,...res.data.data],
  102. this.pages = res.data.last_page
  103. console.log(res.data);
  104. }
  105. })
  106. },
  107. //获取搜索历史
  108. getSearch () {
  109. this.$api.searchHistory().then(res=>{
  110. if (res.code === 1) {
  111. this.searchList = res.data.history
  112. }
  113. })
  114. }
  115. },
  116. onLoad() {
  117. this.getSearch()
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. .search_head {
  123. width: 100%;
  124. height: 88rpx;
  125. position: sticky;
  126. top: 0;
  127. left: 0;
  128. margin-bottom: 30rpx;
  129. z-index: 20;
  130. padding-left: 20rpx;
  131. background: #FFFFFF;
  132. .search_head_ipt {
  133. width: 610rpx;
  134. height: 58rpx;
  135. padding: 0 20rpx;
  136. background: #FAFAFA;
  137. border-radius: 29rpx;
  138. image {
  139. width: 44rpx;
  140. height: 44rpx;
  141. margin-right: 20rpx;
  142. }
  143. input {
  144. font-size: 28rpx;
  145. flex: 1;
  146. }
  147. }
  148. .search_head_cancel {
  149. flex: 1;
  150. color: #2F9EFD;
  151. font-size: 30rpx;
  152. height: 58rpx;
  153. }
  154. }
  155. .search_box {
  156. padding: 0 30rpx;
  157. }
  158. .search_main {
  159. padding: 0rpx 30rpx;
  160. background: #FFFFFF;
  161. border-radius: 22rpx;
  162. .search_main_name {
  163. padding: 30rpx 0;
  164. font-size: 32rpx;
  165. font-weight: bold;
  166. }
  167. .search_main_ul {
  168. overflow: hidden;
  169. flex-wrap: wrap;
  170. .search_main_li {
  171. height: 60rpx;
  172. color: #999999;
  173. font-size: 28rpx;
  174. padding: 0 33rpx;
  175. margin: 0 30rpx 30rpx 0;
  176. background: #FAFAFA;
  177. border-radius: 30rpx;
  178. }
  179. }
  180. }
  181. .home_recommend_ul {
  182. flex-wrap: wrap;
  183. // padding: 0 28rpx;
  184. .home_recommend_li {
  185. width: 332rpx;
  186. padding: 20rpx;
  187. margin-bottom: 30rpx;
  188. background: #FFFFFF;
  189. box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(153, 153, 153, 0.1);
  190. border-radius: 10rpx;
  191. .home_recommend_li_img {
  192. height: 295rpx;
  193. .home_recommend_li_img_top {
  194. align-items: flex-start;
  195. }
  196. .home_recommend_li_img_bot {
  197. display: flex;
  198. margin-top: 20rpx;
  199. justify-content: flex-end;
  200. image {
  201. width: 85rpx;
  202. height: 85rpx;
  203. margin-left: 20rpx;
  204. &:first-child {
  205. margin-left: 0;
  206. }
  207. border-radius: 6rpx;
  208. }
  209. }
  210. .home_recommend_li_img_box {
  211. image {
  212. width: 190rpx;
  213. height: 190rpx;
  214. border-radius: 6rpx;
  215. }
  216. }
  217. .home_recommend_li_img_right {
  218. image {
  219. width: 85rpx;
  220. height: 85rpx;
  221. border-radius: 6rpx;
  222. &:first-child {
  223. margin-bottom: 20rpx;
  224. }
  225. }
  226. }
  227. }
  228. .home_recommend_li_price {
  229. // width: 280rpx;
  230. height: 40rpx;
  231. color: #FFFFFF;
  232. margin: 20rpx 0;
  233. font-size: 26rpx;
  234. line-height: 40rpx;
  235. padding-left: 18rpx;
  236. background: #F6AF32;
  237. border-radius: 20rpx;
  238. }
  239. .home_recommend_li_name {
  240. font-size: 28rpx;
  241. display: -webkit-box;
  242. -webkit-box-orient: vertical;
  243. -webkit-line-clamp: 2;
  244. overflow: hidden;
  245. height: 76rpx;
  246. }
  247. .home_recommend_li_glod {
  248. margin-top: 30rpx;
  249. text {
  250. color: #CF271B;
  251. font-size: 26tpx;
  252. &:last-child {
  253. color: #666666;
  254. font-size: 24rpx;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. </style>