index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view>
  3. <view class='searchGood'>
  4. <view class='search acea-row row-between-wrapper'>
  5. <view class='input acea-row row-between-wrapper'>
  6. <text class='iconfont icon-sousuo2'></text>
  7. <input type='text' :value='searchValue' :focus="focus" placeholder='点击搜索商品、店铺名称' placeholder-class='placeholder'
  8. @input="setValue"></input>
  9. </view>
  10. <view class='bnt' @tap='searchBut'>搜索</view>
  11. </view>
  12. <view class='title'>历史记录 <text class="iconfont icon-shanchu" @click="remove"></text></view>
  13. <view class='list acea-row' :style="{'height':historyBox?'auto':'150rpx'}" v-if="historyList.length > 0">
  14. <block v-for="(item,index) in historyList" :key="index">
  15. <view class='item line1' @tap='setHotSearchValue(item,0)'>{{item}}</view>
  16. </block>
  17. </view>
  18. <view>
  19. <view class="more-btn" v-if="historyList.length>9 && !historyBox" @click="historyBox = true">
  20. 展开全部<text class="iconfont icon-xiangxia"></text>
  21. </view>
  22. <view class="more-btn" v-if="historyList.length>9 && historyBox" @click="historyBox = false">
  23. 收起<text class="iconfont icon-xiangshang"></text>
  24. </view>
  25. </view>
  26. <view v-if="historyList.length == 0" style="text-align: center; color: #999;">暂无搜索历史~</view>
  27. <view class='title'>热门搜索</view>
  28. <view class='list acea-row' :style="{'height': hotSearchBox?'auto':'150rpx'}">
  29. <block v-for="(item,index) in hotSearchList" :key="index">
  30. <view class='item line1' @tap='setHotSearchValue(item,1)'>{{item.keyword}}</view>
  31. </block>
  32. </view>
  33. <view>
  34. <view class="more-btn" v-if="hotSearchList.length>8 && !hotSearchBox" @click="hotSearchBox = true">
  35. 展开全部<text class="iconfont icon-xiangxia"></text>
  36. </view>
  37. <view class="more-btn" v-if="hotSearchList.length>8 && hotSearchBox" @click="hotSearchBox = false">
  38. 收起<text class="iconfont icon-xiangshang"></text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. getSearchKeyword,
  47. } from '@/api/store.js';
  48. export default {
  49. data() {
  50. return {
  51. hostProduct: [],
  52. searchValue: '',
  53. focus: true,
  54. bastList: [],
  55. hotSearchList: [],
  56. first: 0,
  57. limit: 8,
  58. page: 1,
  59. loading: false,
  60. loadend: false,
  61. loadTitle: '加载更多',
  62. hotPage: 1,
  63. isScroll: true,
  64. // 搜索历史
  65. historyList: [],
  66. // 临时搜索列表
  67. tempStorage: [],
  68. historyBox: false,
  69. hotSearchBox: false
  70. };
  71. },
  72. onLoad() {
  73. },
  74. onShow: function() {
  75. try {
  76. this.historyList = []
  77. this.tempStorage = []
  78. let arr = uni.getStorageSync('historyList')
  79. if (arr.length > 0) {
  80. this.historyList = arr
  81. } else {
  82. this.historyList = []
  83. }
  84. this.tempStorage = this.historyList
  85. } catch (e) {}
  86. this.getRoutineHotSearch();
  87. },
  88. methods: {
  89. // 清空历史记录
  90. remove() {
  91. let self = this
  92. uni.showModal({
  93. title: '提示',
  94. content: '确认删除全部历史搜索记录?',
  95. success: function(res) {
  96. if (res.confirm) {
  97. self.tempStorage = []
  98. try {
  99. uni.setStorageSync('historyList', self.tempStorage)
  100. self.historyList = []
  101. } catch (e) {}
  102. } else if (res.cancel) {
  103. console.log('用户点击取消');
  104. }
  105. }
  106. });
  107. },
  108. getRoutineHotSearch: function() {
  109. let that = this;
  110. getSearchKeyword().then(res => {
  111. that.$set(that, 'hotSearchList', res.data);
  112. });
  113. },
  114. setHotSearchValue: function(event, key) {
  115. this.focus = false
  116. if (key) {
  117. this.$set(this, 'searchValue', event.keyword);
  118. } else {
  119. this.$set(this, 'searchValue', event);
  120. }
  121. this.$nextTick(() => {
  122. this.focus = true
  123. })
  124. this.searchBut()
  125. },
  126. setValue: function(event) {
  127. this.$set(this, 'searchValue', event.detail.value);
  128. },
  129. searchBut: function() {
  130. let status = false
  131. this.tempStorage.forEach((el, index) => {
  132. if (el == this.searchValue) {
  133. status = true
  134. }
  135. })
  136. if (!status && this.searchValue) {
  137. this.tempStorage.unshift(this.searchValue)
  138. }
  139. try {
  140. uni.setStorageSync('historyList', this.tempStorage);
  141. } catch (e) {}
  142. uni.navigateTo({
  143. url: '/pages/columnGoods/goods_search_con/index?searchValue=' + this.searchValue
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style>
  150. page {
  151. background-color: #fff;
  152. }
  153. </style>
  154. <style lang="scss">
  155. .searchGood .search {
  156. padding-left: 30rpx;
  157. }
  158. .searchGood .search {
  159. margin-top: 20rpx;
  160. }
  161. .searchGood .search .input {
  162. width: 598rpx;
  163. background-color: #f7f7f7;
  164. border-radius: 33rpx;
  165. padding: 0 35rpx;
  166. box-sizing: border-box;
  167. height: 66rpx;
  168. }
  169. .searchGood .search .input input {
  170. width: 472rpx;
  171. font-size: 28rpx;
  172. }
  173. .searchGood .search .input .placeholder {
  174. color: #bbb;
  175. }
  176. .searchGood .search .input .iconfont {
  177. color: #000;
  178. font-size: 35rpx;
  179. }
  180. .searchGood .search .bnt {
  181. width: 120rpx;
  182. text-align: center;
  183. height: 66rpx;
  184. line-height: 66rpx;
  185. font-size: 30rpx;
  186. color: #282828;
  187. }
  188. .searchGood .title {
  189. position: relative;
  190. font-size: 28rpx;
  191. color: #282828;
  192. margin: 50rpx 30rpx 25rpx 30rpx;
  193. .icon-shanchu {
  194. position: absolute;
  195. right: 0;
  196. top: 50%;
  197. transform: translateY(-50%);
  198. color: #999;
  199. }
  200. }
  201. .searchGood .list {
  202. padding: 0 10rpx;
  203. overflow: hidden;
  204. }
  205. .searchGood .list .item {
  206. font-size: 26rpx;
  207. color: #666;
  208. padding: 0 21rpx;
  209. height: 60rpx;
  210. background: rgba(242, 242, 242, 1);
  211. border-radius: 22rpx;
  212. line-height: 60rpx;
  213. margin: 0 0 20rpx 20rpx;
  214. max-width: 150rpx;
  215. }
  216. .searchGood .line {
  217. border-bottom: 1rpx solid #eee;
  218. margin: 20rpx 30rpx 0 30rpx;
  219. }
  220. .more-btn {
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. margin: 0 0 20rpx 20rpx;
  225. height: 60rpx;
  226. font-size: 24rpx;
  227. color: #999;
  228. .iconfont {
  229. font-size: 22rpx;
  230. margin-left: 10rpx;
  231. }
  232. }
  233. </style>