search.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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" @click="doSearch(item.name)"
  44. :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"
  58. font-size="18" separator-size="18" separator-color="#DF1407"></u-count-down>
  59. </view>
  60. <image src="/pages-sell/static/search/icon-red-packet.png" class="packet-img" mode="aspectFit"></image>
  61. </view>
  62. <!-- Surprise Packet Dialog -->
  63. <PacketDialog v-model="showPacketDialog"></PacketDialog>
  64. </view>
  65. </template>
  66. <script>
  67. import Navbar from '@/components/navbar/navbar.vue';
  68. import PacketDialog from '@/pages-sell/components/packet-dialog/index.vue';
  69. export default {
  70. components: {
  71. Navbar,
  72. PacketDialog
  73. },
  74. data() {
  75. return {
  76. keyword: '',
  77. historyList: [],
  78. hotVisible: true,
  79. hotList: [],
  80. timestamp: 86400, // 24 hours countdown
  81. showPacketDialog: false
  82. }
  83. },
  84. onShow() {
  85. this.getHistoryData();
  86. this.getHotData();
  87. },
  88. methods: {
  89. getHistoryData() {
  90. this.$u.api.getSearchHistoryAjax().then(res => {
  91. this.historyList = res.data || [];
  92. })
  93. },
  94. getHotData() {
  95. this.$u.api.getHotSearchListAjax().then(res => {
  96. this.hotList = res.data.map((v, index) => ({
  97. name: v,
  98. className: index % 2 == 0 ? 'hot-tag' : 'history-tag'
  99. })) || [];
  100. })
  101. },
  102. onSearch() {
  103. if (!this.keyword.trim()) return;
  104. this.doSearch(this.keyword);
  105. },
  106. doSearch(key) {
  107. console.log('Search:', key);
  108. this.keyword = key;
  109. // Navigate to result page or show results
  110. uni.showToast({
  111. title: '搜索: ' + key,
  112. icon: 'none'
  113. });
  114. uni.navigateTo({
  115. url: '/pages-sell/pages/search-result?keyword=' + key
  116. });
  117. },
  118. clearHistory() {
  119. uni.showModal({
  120. title: '提示',
  121. content: '确定清空搜索历史吗?',
  122. success: (res) => {
  123. if (res.confirm) {
  124. this.historyList = [];
  125. }
  126. }
  127. });
  128. },
  129. toggleHot() {
  130. this.hotVisible = !this.hotVisible;
  131. },
  132. openPacket() {
  133. this.showPacketDialog = true;
  134. },
  135. closePacket() {
  136. this.showPacketDialog = false;
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .search-page {
  143. min-height: 100vh;
  144. background-color: #fff;
  145. font-family: 'Source Han Sans SC', sans-serif;
  146. }
  147. .search-area {
  148. padding: 30rpx 30rpx;
  149. }
  150. .search-box {
  151. display: flex;
  152. align-items: center;
  153. background-color: #F6F6F6;
  154. border-radius: 40rpx;
  155. height: 80rpx;
  156. padding: 0 10rpx 0 30rpx;
  157. .search-icon-left {
  158. width: 36rpx;
  159. height: 36rpx;
  160. margin-right: 20rpx;
  161. }
  162. .search-input {
  163. flex: 1;
  164. height: 100%;
  165. font-size: 28rpx;
  166. color: #333;
  167. }
  168. .search-btn {
  169. width: 120rpx;
  170. height: 60rpx;
  171. background: linear-gradient(0deg, #37C148 0%, #6ADD83 100%);
  172. border-radius: 48rpx; // 24px
  173. display: flex;
  174. align-items: center;
  175. justify-content: center;
  176. margin-left: 20rpx;
  177. text {
  178. color: #fff;
  179. font-size: 28rpx;
  180. font-weight: 500;
  181. }
  182. }
  183. }
  184. .section {
  185. padding: 30rpx;
  186. .section-header {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. margin-bottom: 30rpx;
  191. .left {
  192. display: flex;
  193. align-items: center;
  194. }
  195. .title {
  196. font-size: 32rpx;
  197. font-weight: bold;
  198. color: #333;
  199. }
  200. .icon-delete,
  201. .icon-view {
  202. width: 32rpx;
  203. height: 32rpx;
  204. }
  205. .icon-fire {
  206. width: 36rpx;
  207. height: 36rpx;
  208. margin-right: 10rpx;
  209. }
  210. }
  211. .tags-list {
  212. display: flex;
  213. flex-wrap: wrap;
  214. .tag-item {
  215. background: #F8F7F0;
  216. border-radius: 30rpx;
  217. padding: 8rpx 30rpx;
  218. font-size: 26rpx;
  219. color: #666;
  220. margin-right: 20rpx;
  221. margin-bottom: 20rpx;
  222. display: flex;
  223. align-items: center;
  224. &.history-tag {
  225. background-color: #EBF8EE;
  226. }
  227. &.hot-item {
  228. background: #F5F3F9;
  229. }
  230. .tag-icon-new {
  231. height: 16rpx;
  232. margin-right: 8rpx;
  233. }
  234. .tag-icon-fire {
  235. width: 28rpx;
  236. height: 28rpx;
  237. margin-right: 8rpx;
  238. }
  239. }
  240. }
  241. }
  242. .red-packet-float {
  243. position: fixed;
  244. bottom: 200rpx;
  245. right: 40rpx;
  246. z-index: 100;
  247. display: flex;
  248. flex-direction: column;
  249. align-items: center;
  250. .time-badge {
  251. background: #FFE173;
  252. color: #DF1407;
  253. font-size: 18rpx;
  254. padding: 4rpx 10rpx;
  255. border-radius: 10rpx;
  256. position: absolute;
  257. top: -40rpx;
  258. right: -20rpx;
  259. white-space: nowrap;
  260. z-index: 2;
  261. display: flex;
  262. align-items: center;
  263. text {
  264. margin-right: 4rpx;
  265. }
  266. }
  267. .packet-img {
  268. width: 100rpx;
  269. height: 120rpx;
  270. }
  271. }
  272. </style>