productSearch.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="content">
  3. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  4. <!-- 搜索框 -->
  5. <view class="search-cont">
  6. <image @click="goBack" class="w64 h64" src="/static/images/back_black.png"></image>
  7. <view class="inner">
  8. <input v-model="searchValue" type="text" value="" placeholder="城口腊肉/香肠" confirm-type="搜索"
  9. @confirm="handleSearch" @input="handleInput" :focus='setFocus'
  10. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  11. <image @click="clearInput" v-if="searchValue" class="w32 h32"
  12. src="/static/images/search_close_gray.png">
  13. </image>
  14. <view class="line"></view>
  15. <view class="search" @click="handleSearch">搜索</view>
  16. </view>
  17. </view>
  18. <!-- 搜索历史 -->
  19. <!-- <view class="title-box">
  20. <text class="title">历史搜索</text>
  21. <image src="../../static/images/del.png" mode="" @click="clearHistory"></image>
  22. </view>
  23. <view class="data-list">
  24. <view class="item" v-for="(item,index) in searchHistory" :key="index" @click="doSearch(item)">
  25. {{ item }}
  26. </view>
  27. </view> -->
  28. <!-- 热门搜索 -->
  29. <view class="title-box">
  30. <text class="title">热门搜索</text>
  31. <image class="w32 h32" src="/static/images/delete_icon.png"></image>
  32. </view>
  33. <view class="popular-list">
  34. <view class="item" v-for="(item,index) in topSearch" :key="index" @click="doSearch(item)">
  35. {{ item }}
  36. </view>
  37. </view>
  38. <!-- 推荐搜索 -->
  39. <view class="title-box">
  40. <text class="title">大家都在搜</text>
  41. <image class="w32 h32" src="/static/images/refresh_icon.png"></image>
  42. </view>
  43. <view class="data-list">
  44. <view class="item" v-for="(item,index) in topSearch" :key="index" @click="doSearch(item)">
  45. <text> {{ item }}</text>
  46. <image class="w40 h40 ml8" src="/static/images/hot.png"></image>
  47. </view>
  48. </view>
  49. <scroll-view class="card-group" scroll-x="true" show-scrollbar="false" enhanced="true" enable-flex="true">
  50. <!-- 今日热卖榜 -->
  51. <view class="card border1">
  52. <image class="card-bg" src="/static/images/hot_selling.png"></image>
  53. <view class="card-title">
  54. <image class="w40 h40 ml8" src="/static/images/hot.png"></image>
  55. <text class="title1">今日热卖榜</text>
  56. </view>
  57. <view class="product-list">
  58. <view class="product-item">
  59. <view class="left">
  60. <image class="photo" src="/static/images/img.png"></image>
  61. <view class="lable">1</view>
  62. </view>
  63. <view class="right">
  64. <view class="title">乌灵胶囊81粒养心安神失乌灵胶囊81粒养心安神失眠乌灵胶囊81粒养心安神失眠眠健...</view>
  65. <view class="txt">肌肉酸疼、扭伤拉伤</view>
  66. <view class="num-box">
  67. <view class="price"><text class="symbol">¥</text><text class="bold">89</text>.48</view>
  68. <view class="sale">已售 5485</view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 30天新品热销榜单 -->
  75. <view class="card ml24 border2">
  76. <image class="card-bg" src="/static/images/new_hot.png"></image>
  77. <view class="card-title">
  78. <image class="w40 h40 ml8" src="/static/images/new_product.png"></image>
  79. <text class="title1">30天新品热销榜单</text>
  80. </view>
  81. <view class="product-list">
  82. <view class="product-item">
  83. <view class="left">
  84. <image class="photo" src="/static/images/img.png"></image>
  85. <view class="lable">1</view>
  86. </view>
  87. <view class="right">
  88. <view class="title">乌灵胶囊81粒养心安神失乌灵胶囊81粒养心安神失眠乌灵胶囊81粒养心安神失眠眠健...</view>
  89. <view class="txt">肌肉酸疼、扭伤拉伤</view>
  90. <view class="num-box">
  91. <view class="price"><text class="symbol">¥</text><text class="bold">89</text>.48</view>
  92. <view class="sale">已售 5485</view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </scroll-view>
  99. </view>
  100. </template>
  101. <script>
  102. export default {
  103. data() {
  104. return {
  105. searchValue: '',
  106. // 状态栏的高度
  107. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  108. setFocus: false,
  109. // 历史搜索
  110. searchHistory: [],
  111. // 推荐搜索
  112. topSearch: []
  113. };
  114. },
  115. onShow() {
  116. this.setFocus = true
  117. this.searchHistory = this.utils.getHisSearch();
  118. var config = uni.getStorageSync('config');
  119. if (config != null && config != undefined && config != "") {
  120. this.topSearch = JSON.parse(config).hotSearch.split(',');
  121. }
  122. },
  123. onHide() {
  124. // 页面隐藏时重置聚焦状态
  125. this.setFocus = false;
  126. },
  127. methods: {
  128. goBack() {
  129. uni.navigateBack({
  130. delta: 1 // 返回的页面数,1表示返回上一页
  131. });
  132. },
  133. // 处理输入
  134. handleInput(e) {
  135. this.searchValue = e.detail.value;
  136. },
  137. // 清除输入内容
  138. clearInput() {
  139. this.searchValue = '';
  140. this.setFocus = true; // 清除后重新聚焦
  141. },
  142. // 清空历史搜索数据
  143. clearHistory() {
  144. this.utils.clearHisSearch();
  145. this.searchHistory = this.utils.getHisSearch();
  146. },
  147. doSearch(item) {
  148. uni.navigateTo({
  149. url: './productList?key=' + item
  150. })
  151. },
  152. handleSearch() {
  153. if (!this.searchValue.trim()) {
  154. uni.showToast({
  155. title: '请输入搜索内容',
  156. icon: 'none'
  157. });
  158. return;
  159. }
  160. // 保存搜索历史
  161. this.utils.addHisSearch(this.searchValue);
  162. // 跳转到搜索结果页
  163. uni.navigateTo({
  164. url: './productList?key=' + encodeURIComponent(this.searchValue)
  165. });
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. page {
  172. background-color: #ffffff;
  173. }
  174. .content {
  175. .search-cont {
  176. display: flex;
  177. padding: 16rpx 30rpx;
  178. background-color: #FFFFFF;
  179. .inner {
  180. box-sizing: border-box;
  181. width: 436rpx;
  182. height: 64rpx;
  183. background: #F5F7FA;
  184. border-radius: 36rpx;
  185. display: flex;
  186. align-items: center;
  187. padding: 0 24rpx;
  188. image {
  189. padding: 16rpx;
  190. /* 增加点击区域 */
  191. margin: -16rpx;
  192. /* 负边距抵消padding对布局的影响 */
  193. box-sizing: content-box;
  194. }
  195. .search {
  196. font-weight: 500;
  197. font-size: 28rpx;
  198. color: #333333;
  199. }
  200. .line {
  201. width: 2rpx;
  202. height: 24rpx;
  203. background: #999999;
  204. margin: 0 26rpx;
  205. }
  206. input {
  207. height: 60rpx;
  208. line-height: 60rpx;
  209. flex: 1;
  210. }
  211. }
  212. }
  213. .title-box {
  214. padding: 30rpx;
  215. display: flex;
  216. align-items: center;
  217. justify-content: space-between;
  218. .title {
  219. font-weight: 600;
  220. font-size: 32rpx;
  221. color: #000000;
  222. }
  223. image {
  224. width: 30rpx;
  225. height: 30rpx;
  226. }
  227. }
  228. .data-list {
  229. padding: 0rpx 10rpx 30rpx;
  230. display: grid;
  231. grid-template-columns: repeat(2, 1fr);
  232. /* 两列布局 */
  233. grid-gap: 20rpx;
  234. .item {
  235. padding: 0 30rpx;
  236. height: 56rpx;
  237. line-height: 56rpx;
  238. font-size: 26rpx;
  239. font-family: PingFang SC;
  240. font-weight: 500;
  241. color: #4D4D4D;
  242. border-radius: 28rpx;
  243. margin: 0;
  244. display: flex;
  245. align-items: center;
  246. text-align: center;
  247. }
  248. }
  249. .popular-list {
  250. padding: 0rpx 10rpx 30rpx;
  251. display: flex;
  252. flex-wrap: wrap;
  253. .item {
  254. padding: 0 40rpx;
  255. height: 56rpx;
  256. line-height: 56rpx;
  257. font-size: 26rpx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #4D4D4D;
  261. background: #F5F7FA;
  262. border-radius: 28rpx;
  263. margin: 0 20rpx 20rpx 0;
  264. }
  265. }
  266. .card-group {
  267. display: flex;
  268. padding: 0 24rpx;
  269. box-sizing: border-box;
  270. .card {
  271. width: 600rpx;
  272. padding: 26rpx 32rpx 0;
  273. background: #FFFFFF;
  274. border-radius: 24rpx 24rpx 24rpx 24rpx;
  275. position: relative;
  276. z-index: 0;
  277. .card-bg {
  278. width: 100%;
  279. height: 96rpx;
  280. position: absolute;
  281. top: 0;
  282. left: 0;
  283. border-radius: 24rpx 24rpx 0 0;
  284. z-index: -1;
  285. }
  286. .card-title {
  287. display: flex;
  288. align-items: center;
  289. font-weight: 600;
  290. font-size: 32rpx;
  291. margin-bottom: 34rpx;
  292. .title1 {
  293. color: #FF4400;
  294. }
  295. .title2 {
  296. color: #D46C0D;
  297. }
  298. }
  299. .product-list {
  300. .product-item {
  301. display: flex;
  302. align-items: center;
  303. margin-bottom: 40rpx;
  304. .left {
  305. margin-right: 22rpx;
  306. width: 120rpx;
  307. height: 120rpx;
  308. border-radius: 8rpx 8rpx 8rpx 8rpx;
  309. overflow: hidden;
  310. position: relative;
  311. .photo {
  312. width: 100%;
  313. height: 100%;
  314. }
  315. .lable {
  316. position: absolute;
  317. left: 0;
  318. top: 0;
  319. width: 32rpx;
  320. height: 32rpx;
  321. text-align: center;
  322. line-height: 32rpx;
  323. background: linear-gradient(135deg, #C1C5CD 0%, #A5AAB5 100%);
  324. border-radius: 8rpx 0rpx 8rpx 0rpx;
  325. font-family: Roboto, Roboto;
  326. font-weight: 500;
  327. font-size: 24rpx;
  328. color: #FFFFFF;
  329. }
  330. }
  331. .right {
  332. flex: 1;
  333. min-width: 0;
  334. .title {
  335. font-weight: 500;
  336. font-size: 28rpx;
  337. color: #333333;
  338. overflow: hidden;
  339. /* 隐藏溢出内容 */
  340. text-overflow: ellipsis;
  341. /* 显示省略号 */
  342. white-space: nowrap;
  343. /* 不换行 */
  344. }
  345. .txt {
  346. font-size: 22rpx;
  347. color: #999999;
  348. margin: 4rpx 0 20rpx;
  349. }
  350. .num-box {
  351. display: flex;
  352. justify-content: space-between;
  353. align-items: flex-end;
  354. .price {
  355. font-family: Roboto, Roboto;
  356. font-weight: 600;
  357. font-size: 26rpx;
  358. color: #FA341E;
  359. .symbol {
  360. font-size: 20rpx;
  361. }
  362. .bold {
  363. font-size: 36rpx;
  364. }
  365. }
  366. .sale {
  367. font-size: 21rpx;
  368. color: #999999;
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. .border1 {
  376. border: 1rpx solid rgba(241, 89, 38, 0.5);
  377. }
  378. .border2 {
  379. border: 1rpx solid rgba(244, 160, 7, 0.5);
  380. }
  381. }
  382. }
  383. </style>