search.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view :style="{ paddingTop: statusBarHeight + 'px' }">
  3. <view class="flex-items pad-t-20">
  4. <view class="mar-r-20">
  5. <uni-icons @tap="back" type="left" color="#545454" size="30"></uni-icons>
  6. </view>
  7. <view class="search-box">
  8. <input confirm-type="search" class="search-input" focus type="text" placeholder="请输入搜索内容"
  9. v-model="historySearch.name" />
  10. <uni-icons @tap="clear" v-if="historySearch.name" type="closeempty" color="#545454" size="20"
  11. class="mar-r-20"></uni-icons>
  12. <button class="search-button" @click="onSearchClick">搜索</button>
  13. </view>
  14. </view>
  15. <view class="flex-items-between pad-32">
  16. <view class="font28 font-bold">
  17. 历史搜索
  18. </view>
  19. <uni-icons @tap="delSearch" type="trash" size="26"></uni-icons>
  20. </view>
  21. <view class="pad-lr-32">
  22. <view class="search-container">
  23. <view v-for="(item, index) in historySearchList" :key="index" class="search-item">
  24. <view class="searchBg mar-b-16" @tap="onHistorySearch(item.name)">
  25. {{ item.name }}
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. delHistorySearch,
  35. submitHistorySearch,
  36. getHistorySearchList
  37. } from '../../config/api.js';
  38. import {
  39. MAIN_COLOR
  40. } from '../../common/config.js'
  41. export default {
  42. data() {
  43. return {
  44. bgColor: 'transparent',
  45. statusBarHeight: 0, // 状态栏高度
  46. historySearch: {
  47. name: "",
  48. type: ""
  49. },
  50. historySearchList: [],
  51. }
  52. },
  53. onLoad(op) {
  54. console.log(op.searchKey)
  55. this.historySearch.type = op.type
  56. if (op.searchKey) {
  57. console.log(op.searchKey)
  58. this.historySearch.name = op.searchKey
  59. }
  60. // 获取设备信息,包括状态栏高度
  61. const systemInfo = uni.getSystemInfoSync();
  62. this.statusBarHeight = systemInfo.statusBarHeight;
  63. this.getSearch();
  64. },
  65. methods: {
  66. clear() {
  67. this.historySearch.name = ""
  68. },
  69. onHistorySearch(name) {
  70. this.historySearch.name = name
  71. if (this.historySearch.type == 2) {
  72. this.$route('/pages/order/list?serachKey=' + this.historySearch.name)
  73. }
  74. if (this.historySearch.type == 1) {
  75. this.$route('/pages/shop/product-type-list?serachKey=' + this.historySearch.name)
  76. }
  77. },
  78. back() {
  79. uni.navigateBack({
  80. delta: 1
  81. })
  82. },
  83. getSearch() {
  84. getHistorySearchList({
  85. type: this.historySearch.type
  86. }).then((res) => {
  87. this.historySearchList = res.data
  88. })
  89. },
  90. delSearch() {
  91. delHistorySearch().then((res) => {
  92. this.getSearch()
  93. })
  94. },
  95. onSearchClick() {
  96. console.log(this.historySearch.type)
  97. // 执行搜索操作
  98. submitHistorySearch(this.historySearch)
  99. if (this.historySearch.type == 2) {
  100. this.$route('/pages/order/list?serachKey=' + this.historySearch.name)
  101. }
  102. if (this.historySearch.type == 1) {
  103. this.$route('/pages/shop/product-type-list?serachKey=' + this.historySearch.name)
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style>
  110. .search-container {
  111. display: flex;
  112. flex-wrap: wrap;
  113. }
  114. .search-item {
  115. margin-right: 10rpx;
  116. margin-bottom: 10rpx;
  117. }
  118. .searchBg {
  119. background-color: #d8d8d8;
  120. padding: 8rpx 12rpx;
  121. border-radius: 10rpx;
  122. font-size: 14px;
  123. color: #333;
  124. }
  125. .search-box {
  126. display: flex;
  127. align-items: center;
  128. border-radius: 20rpx;
  129. background-color: #f0f0f0;
  130. padding: 10rpx 20rpx;
  131. width: 100%;
  132. /* Ensure it takes full width */
  133. }
  134. .search-input {
  135. flex: 1;
  136. border: none;
  137. outline: none;
  138. font-size: 14px;
  139. color: #999;
  140. background-color: #f0f0f0;
  141. border-radius: 20rpx;
  142. padding: 8rpx 12rpx;
  143. width: 100%;
  144. }
  145. .search-button {
  146. background-color: #f27c22;
  147. /* 橘色背景 */
  148. color: white;
  149. border: none;
  150. padding: 0rpx 30rpx 0rpx 30rpx;
  151. border-radius: 20rpx;
  152. margin-left: 10rpx;
  153. font-size: 14px;
  154. cursor: pointer;
  155. white-space: nowrap;
  156. /* Prevent text overflow */
  157. }
  158. </style>