index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view>
  3. <JHeader title="搜索" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <!-- 搜索商品 -->
  5. <view>
  6. <view class="flex-items-plus flex-row mar-top-20">
  7. <view class="searchImg-box flex-items-plus">
  8. <tui-icon
  9. style="position: absolute;left: 38upx;" name="search" :size="65" unit="upx"
  10. color="#d1d1d1"
  11. ></tui-icon>
  12. <input
  13. v-model="keyWord" class="search-box" maxlength="20" placeholder-class="searchboxPlace"
  14. placeholder="请输入您想要的宝贝"
  15. />
  16. </view>
  17. <view class="mar-left-40 fs26" @click="getList">搜索</view>
  18. </view>
  19. </view>
  20. <!-- 热门搜索 -->
  21. <view class="hotSearchBox tipsBox">
  22. <view v-if="hotSearchList.length > 0" class="boxTitle mar-leftgetList-30">
  23. <label class="fs30 font-color-999 fs-weight-300">热门搜索</label>
  24. <tui-icon
  25. v-if="isSee" name="seen" color="#393939" :size="40"
  26. unit="upx" style="position: absolute;right: 30upx;"
  27. @click="changeHotSearchListIsSee"
  28. ></tui-icon>
  29. <tui-icon
  30. v-else name="unseen" color="#393939" :size="40"
  31. unit="upx" style="position: absolute;right: 30upx;"
  32. @click="changeHotSearchListIsSee"
  33. ></tui-icon>
  34. </view>
  35. <view>
  36. <view v-if="isSee" class="flex-wrap-1 flex-row">
  37. <view
  38. v-for="(item, index) in hotSearchList" :key="index"
  39. class="historySearDel-box flex-items-plus mar-right-30"
  40. >
  41. <view class="boxContent" @click="historyKeyword(item)">{{ item }}</view>
  42. </view>
  43. </view>
  44. <view v-else class="notSeeContent">当前热门搜索已隐藏</view>
  45. </view>
  46. </view>
  47. <view class="line" color="#F3F4F5" />
  48. <!-- 历史搜索 -->
  49. <view class="historyBox tipsBox">
  50. <view v-if="historyList.length > 0" class="boxTitle mar-leftgetList-30">
  51. <label class="fs30 font-color-999 fs-weight-300 ">历史搜索</label>
  52. <tui-icon name="delete" color="#333333" :size="30" unit="upx" style="position: absolute;right: 30upx;" @click="historyDelAll"></tui-icon>
  53. </view>
  54. <view class="historySear-box flex-wrap-1 flex-row">
  55. <view
  56. v-for="(item, index) in historyList" :key="item.searchId"
  57. class="historySearDel-box flex-items-plus flex-sp-between mar-right-30"
  58. >
  59. <view class="boxContent historyText line1" @click="historyKeyword(item.search)">{{ item.search }}</view>
  60. <label class="font-color-DDD fs22 pad-topbot-10 text-align">|</label>
  61. <view class="historyIconBox" @click="historyDelOne(item.searchId)">
  62. <tui-icon name="shut" color="#9e9e9e" :size="16" unit="upx"></tui-icon>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { getSelectHotSearchApi, getSearchHistoryApi, deleteProductAllSearchApi, deleteSearchRecordApi } from '../../../api/anotherTFInterface'
  71. export default {
  72. name: 'Search',
  73. data() {
  74. return {
  75. keyWord: '',
  76. historyList: [],
  77. hotSearchList: [],
  78. list: [],
  79. isSee: true
  80. }
  81. },
  82. onShow() {
  83. this.findSearchHistory()
  84. this.findHotSearch()
  85. },
  86. methods: {
  87. searchTextDel() {
  88. this.keyWord = ''
  89. },
  90. getList() {
  91. if (!this.keyWord) {
  92. uni.showToast({
  93. title: '请输入要搜索内容!',
  94. duration: 2000,
  95. icon: 'none'
  96. })
  97. } else {
  98. uni.navigateTo({
  99. url: `/another-tf/another-serve/goodsList/index?keyWord=${this.keyWord}`
  100. })
  101. }
  102. },
  103. historyKeyword(keyWord) {
  104. uni.navigateTo({
  105. url: `/another-tf/another-serve/goodsList/index?keyWord=${keyWord}`
  106. })
  107. },
  108. // 热门搜索
  109. findHotSearch() {
  110. getSelectHotSearchApi({}).then((res) => {
  111. this.hotSearchList = res.data
  112. })
  113. },
  114. changeHotSearchListIsSee() {
  115. this.isSee = !this.isSee
  116. },
  117. // 历史记录
  118. findSearchHistory() {
  119. getSearchHistoryApi({}).then((res) => {
  120. this.historyList = res.data
  121. })
  122. },
  123. historyDelAll() {
  124. uni.showModal({
  125. title: '温馨提示',
  126. content: '您确定要清空搜索记录吗?',
  127. confirmText: '确定清空',
  128. cancelText: '点错了',
  129. success: (res) => {
  130. if (res.confirm) {
  131. this.deleteAllSearch()
  132. }
  133. }
  134. })
  135. },
  136. deleteAllSearch() {
  137. deleteProductAllSearchApi({}).then((res) => {
  138. this.historyList = res.data
  139. })
  140. },
  141. historyDelOne(searchId) {
  142. uni.showModal({
  143. title: '温馨提示',
  144. content: '您确定要删除这一条记录吗?',
  145. confirmText: '确定删除',
  146. cancelText: '点错了',
  147. success: (res) => {
  148. if (res.confirm) {
  149. deleteSearchRecordApi({ searchId })
  150. .then((res) => {
  151. this.findSearchHistory()
  152. })
  153. }
  154. }
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang='less' scoped>
  161. input {
  162. padding-left: 80upx;
  163. }
  164. .searchImg-box {
  165. .search-box {
  166. background-color: #F1F1F1;
  167. width: 530upx;
  168. height: 66upx;
  169. }
  170. .searchboxPlace {
  171. font-size: 26upx;
  172. color: #A9A9A9;
  173. padding-right: 30upx;
  174. }
  175. .searchClose-icon {
  176. width: 30upx;
  177. height: 30upx;
  178. margin-left: -50upx;
  179. z-index: 99999;
  180. }
  181. }
  182. // 热门搜索
  183. .hotSearchBox {
  184. padding: 0 36upx;
  185. .historyText {
  186. flex: 1;
  187. }
  188. .notSeeContent {
  189. margin-top: 20upx;
  190. text-align: center;
  191. font-size: 24upx;
  192. color: #CCCCCC;
  193. }
  194. }
  195. .line {
  196. margin: 70upx 0;
  197. height: 2upx;
  198. background: #F3F4F5;
  199. }
  200. // 历史搜索
  201. .historyBox {
  202. padding: 0 36upx;
  203. .historySear-box {
  204. width: 100%;
  205. }
  206. .historyIconBox {
  207. width: 50upx;
  208. }
  209. }
  210. .tipsBox {
  211. padding: 15rpx 24rpx;
  212. }
  213. .boxTitle {
  214. margin: 30rpx 0;
  215. }
  216. .historySearDel-box {
  217. height: 54upx;
  218. line-height: 54upx;
  219. margin: 15rpx 15rpx;
  220. background-color: #F1F1F1;
  221. text-align: center;
  222. overflow: hidden;
  223. .boxContent {
  224. font-size: 28rpx;
  225. padding: 0 30rpx;
  226. }
  227. }
  228. </style>