productSearch.vue 11 KB

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