search.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="search-page">
  3. <!-- Navbar -->
  4. <Navbar title="搜索"></Navbar>
  5. <!-- Search Bar Area -->
  6. <view class="search-area">
  7. <view class="search-box">
  8. <image src="/pages-sell/static/search/icon-scan.png" class="search-icon-left" mode="aspectFit"></image>
  9. <input class="search-input" v-model="keyword" placeholder="书名 / 作者 / ISBN" confirm-type="search"
  10. @confirm="onSearch" :focus="true" />
  11. <view class="search-btn" @click="onSearch">
  12. <text>搜索</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- History -->
  17. <view class="section history-section" v-if="historyList.length">
  18. <view class="section-header">
  19. <text class="title">搜索历史</text>
  20. <image src="/pages-sell/static/search/icon-delete.png" class="icon-delete" mode="aspectFit"
  21. @click="clearHistory"></image>
  22. </view>
  23. <view class="tags-list">
  24. <view class="tag-item history-tag" v-for="(item, index) in historyList" :key="index"
  25. @click="doSearch(item)">
  26. {{ item }}
  27. </view>
  28. </view>
  29. </view>
  30. <!-- Hot Search -->
  31. <view class="section hot-section">
  32. <view class="section-header">
  33. <view class="left">
  34. <image src="/pages-sell/static/search/icon-fire.png" class="icon-fire" mode="aspectFit"></image>
  35. <text class="title">热门搜索</text>
  36. </view>
  37. <image
  38. :src="hotVisible ? '/pages-sell/static/search/icon-view.png' : '/pages-sell/static/search/icon-view.png'"
  39. class="icon-view" mode="aspectFit" @click="toggleHot" :style="{ opacity: hotVisible ? 1 : 0.5 }">
  40. </image>
  41. </view>
  42. <view class="tags-list" v-if="hotVisible">
  43. <view class="tag-item" v-for="(item, index) in hotList" :key="index"
  44. @click="doSearch(item.name)" :class="item.className">
  45. <image v-if="item.tag === 'NEW'" src="/pages-sell/static/search/icon-new.png" class="tag-icon-new"
  46. mode="heightFix"></image>
  47. <image v-if="item.tag === 'HOT'" src="/pages-sell/static/search/icon-fire.png" class="tag-icon-fire"
  48. mode="heightFix"></image>
  49. <text>{{ item.name }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- Red Packet Float -->
  54. <view class="red-packet-float" @click="openPacket">
  55. <view class="time-badge">
  56. <text>剩</text>
  57. <u-count-down :timestamp="timestamp" separator="colon" color="#DF1407" bg-color="transparent" font-size="18" separator-size="18" separator-color="#DF1407"></u-count-down>
  58. </view>
  59. <image src="/pages-sell/static/search/icon-red-packet.png" class="packet-img" mode="aspectFit"></image>
  60. </view>
  61. <!-- Surprise Packet Dialog -->
  62. <PacketDialog v-model="showPacketDialog"></PacketDialog>
  63. </view>
  64. </template>
  65. <script>
  66. import Navbar from '@/components/navbar/navbar.vue';
  67. import PacketDialog from '@/pages-sell/components/packet-dialog/index.vue';
  68. export default {
  69. components: {
  70. Navbar,
  71. PacketDialog
  72. },
  73. data() {
  74. return {
  75. keyword: '',
  76. historyList: ['本朝纲目', '千金方', '墨菲定律', '狂人日记', '鲁迅经典', '资治通鉴'],
  77. hotVisible: true,
  78. hotList: [
  79. { name: '毛概 2023', tag: 'NEW' },
  80. { name: '吸引力法则', tag: 'HOT' },
  81. { name: '神农本草经书', tag: '' }
  82. ],
  83. timestamp: 86400, // 24 hours countdown
  84. showPacketDialog: false
  85. }
  86. },
  87. methods: {
  88. onSearch() {
  89. if (!this.keyword.trim()) return;
  90. this.doSearch(this.keyword);
  91. },
  92. doSearch(key) {
  93. console.log('Search:', key);
  94. this.keyword = key;
  95. // Navigate to result page or show results
  96. uni.showToast({
  97. title: '搜索: ' + key,
  98. icon: 'none'
  99. });
  100. },
  101. clearHistory() {
  102. uni.showModal({
  103. title: '提示',
  104. content: '确定清空搜索历史吗?',
  105. success: (res) => {
  106. if (res.confirm) {
  107. this.historyList = [];
  108. }
  109. }
  110. });
  111. },
  112. toggleHot() {
  113. this.hotVisible = !this.hotVisible;
  114. },
  115. openPacket() {
  116. this.showPacketDialog = true;
  117. },
  118. closePacket() {
  119. this.showPacketDialog = false;
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .search-page {
  126. min-height: 100vh;
  127. background-color: #fff;
  128. font-family: 'Source Han Sans SC', sans-serif;
  129. }
  130. .search-area {
  131. padding: 30rpx 30rpx;
  132. }
  133. .search-box {
  134. display: flex;
  135. align-items: center;
  136. background-color: #F6F6F6;
  137. border-radius: 40rpx;
  138. height: 80rpx;
  139. padding: 0 10rpx 0 30rpx;
  140. .search-icon-left {
  141. width: 36rpx;
  142. height: 36rpx;
  143. margin-right: 20rpx;
  144. }
  145. .search-input {
  146. flex: 1;
  147. height: 100%;
  148. font-size: 28rpx;
  149. color: #333;
  150. }
  151. .search-btn {
  152. width: 120rpx;
  153. height: 60rpx;
  154. background: linear-gradient(0deg, #37C148 0%, #6ADD83 100%);
  155. border-radius: 48rpx; // 24px
  156. display: flex;
  157. align-items: center;
  158. justify-content: center;
  159. margin-left: 20rpx;
  160. text {
  161. color: #fff;
  162. font-size: 28rpx;
  163. font-weight: 500;
  164. }
  165. }
  166. }
  167. .section {
  168. padding: 30rpx;
  169. .section-header {
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. margin-bottom: 30rpx;
  174. .left {
  175. display: flex;
  176. align-items: center;
  177. }
  178. .title {
  179. font-size: 32rpx;
  180. font-weight: bold;
  181. color: #333;
  182. }
  183. .icon-delete,
  184. .icon-view {
  185. width: 32rpx;
  186. height: 32rpx;
  187. }
  188. .icon-fire {
  189. width: 36rpx;
  190. height: 36rpx;
  191. margin-right: 10rpx;
  192. }
  193. }
  194. .tags-list {
  195. display: flex;
  196. flex-wrap: wrap;
  197. .tag-item {
  198. background: #F8F7F0;
  199. border-radius: 30rpx;
  200. padding: 8rpx 30rpx;
  201. font-size: 26rpx;
  202. color: #666;
  203. margin-right: 20rpx;
  204. margin-bottom: 20rpx;
  205. display: flex;
  206. align-items: center;
  207. &.history-tag {
  208. background-color: #EBF8EE;
  209. }
  210. &.hot-item {
  211. background: #F5F3F9;
  212. }
  213. .tag-icon-new {
  214. height: 16rpx;
  215. margin-right: 8rpx;
  216. }
  217. .tag-icon-fire {
  218. width: 28rpx;
  219. height: 28rpx;
  220. margin-right: 8rpx;
  221. }
  222. }
  223. }
  224. }
  225. .red-packet-float {
  226. position: fixed;
  227. bottom: 200rpx;
  228. right: 40rpx;
  229. z-index: 100;
  230. display: flex;
  231. flex-direction: column;
  232. align-items: center;
  233. .time-badge {
  234. background: #FFE173;
  235. color: #DF1407;
  236. font-size: 18rpx;
  237. padding: 4rpx 10rpx;
  238. border-radius: 10rpx;
  239. position: absolute;
  240. top: -40rpx;
  241. right: -20rpx;
  242. white-space: nowrap;
  243. z-index: 2;
  244. display: flex;
  245. align-items: center;
  246. text {
  247. margin-right: 4rpx;
  248. }
  249. }
  250. .packet-img {
  251. width: 100rpx;
  252. height: 120rpx;
  253. }
  254. }
  255. </style>