search.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. uni.navigateTo({
  101. url: '/pages-sell/pages/search-result?keyword=' + key
  102. });
  103. },
  104. clearHistory() {
  105. uni.showModal({
  106. title: '提示',
  107. content: '确定清空搜索历史吗?',
  108. success: (res) => {
  109. if (res.confirm) {
  110. this.historyList = [];
  111. }
  112. }
  113. });
  114. },
  115. toggleHot() {
  116. this.hotVisible = !this.hotVisible;
  117. },
  118. openPacket() {
  119. this.showPacketDialog = true;
  120. },
  121. closePacket() {
  122. this.showPacketDialog = false;
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .search-page {
  129. min-height: 100vh;
  130. background-color: #fff;
  131. font-family: 'Source Han Sans SC', sans-serif;
  132. }
  133. .search-area {
  134. padding: 30rpx 30rpx;
  135. }
  136. .search-box {
  137. display: flex;
  138. align-items: center;
  139. background-color: #F6F6F6;
  140. border-radius: 40rpx;
  141. height: 80rpx;
  142. padding: 0 10rpx 0 30rpx;
  143. .search-icon-left {
  144. width: 36rpx;
  145. height: 36rpx;
  146. margin-right: 20rpx;
  147. }
  148. .search-input {
  149. flex: 1;
  150. height: 100%;
  151. font-size: 28rpx;
  152. color: #333;
  153. }
  154. .search-btn {
  155. width: 120rpx;
  156. height: 60rpx;
  157. background: linear-gradient(0deg, #37C148 0%, #6ADD83 100%);
  158. border-radius: 48rpx; // 24px
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. margin-left: 20rpx;
  163. text {
  164. color: #fff;
  165. font-size: 28rpx;
  166. font-weight: 500;
  167. }
  168. }
  169. }
  170. .section {
  171. padding: 30rpx;
  172. .section-header {
  173. display: flex;
  174. justify-content: space-between;
  175. align-items: center;
  176. margin-bottom: 30rpx;
  177. .left {
  178. display: flex;
  179. align-items: center;
  180. }
  181. .title {
  182. font-size: 32rpx;
  183. font-weight: bold;
  184. color: #333;
  185. }
  186. .icon-delete,
  187. .icon-view {
  188. width: 32rpx;
  189. height: 32rpx;
  190. }
  191. .icon-fire {
  192. width: 36rpx;
  193. height: 36rpx;
  194. margin-right: 10rpx;
  195. }
  196. }
  197. .tags-list {
  198. display: flex;
  199. flex-wrap: wrap;
  200. .tag-item {
  201. background: #F8F7F0;
  202. border-radius: 30rpx;
  203. padding: 8rpx 30rpx;
  204. font-size: 26rpx;
  205. color: #666;
  206. margin-right: 20rpx;
  207. margin-bottom: 20rpx;
  208. display: flex;
  209. align-items: center;
  210. &.history-tag {
  211. background-color: #EBF8EE;
  212. }
  213. &.hot-item {
  214. background: #F5F3F9;
  215. }
  216. .tag-icon-new {
  217. height: 16rpx;
  218. margin-right: 8rpx;
  219. }
  220. .tag-icon-fire {
  221. width: 28rpx;
  222. height: 28rpx;
  223. margin-right: 8rpx;
  224. }
  225. }
  226. }
  227. }
  228. .red-packet-float {
  229. position: fixed;
  230. bottom: 200rpx;
  231. right: 40rpx;
  232. z-index: 100;
  233. display: flex;
  234. flex-direction: column;
  235. align-items: center;
  236. .time-badge {
  237. background: #FFE173;
  238. color: #DF1407;
  239. font-size: 18rpx;
  240. padding: 4rpx 10rpx;
  241. border-radius: 10rpx;
  242. position: absolute;
  243. top: -40rpx;
  244. right: -20rpx;
  245. white-space: nowrap;
  246. z-index: 2;
  247. display: flex;
  248. align-items: center;
  249. text {
  250. margin-right: 4rpx;
  251. }
  252. }
  253. .packet-img {
  254. width: 100rpx;
  255. height: 120rpx;
  256. }
  257. }
  258. </style>