index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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" confirm-type="search" @confirm="searchBut()"></input>
  9. </view>
  10. <view class='bnt' @tap='searchCancle'>取消</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. // +----------------------------------------------------------------------
  46. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  47. // +----------------------------------------------------------------------
  48. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  49. // +----------------------------------------------------------------------
  50. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  51. // +----------------------------------------------------------------------
  52. // | Author: CRMEB Team <admin@crmeb.com>
  53. // +----------------------------------------------------------------------
  54. import { hotSearchLst } from '@/api/community.js';
  55. export default {
  56. data() {
  57. return {
  58. hostProduct: [],
  59. searchValue: '',
  60. focus: true,
  61. hotSearchList: [],
  62. page: 1,
  63. loading: false,
  64. loadend: false,
  65. loadTitle: '加载更多',
  66. isScroll: true,
  67. // 搜索历史
  68. historyList: [],
  69. // 临时搜索列表
  70. tempStorage: [],
  71. historyBox: false,
  72. hotSearchBox: false,
  73. };
  74. },
  75. onLoad() {
  76. },
  77. onShow: function() {
  78. try {
  79. this.historyList = []
  80. this.tempStorage = []
  81. let arr = uni.getStorageSync('historyPlant')
  82. if (arr.length > 0) {
  83. this.historyList = arr
  84. } else {
  85. this.historyList = []
  86. }
  87. this.tempStorage = this.historyList
  88. } catch (e) {}
  89. this.getRoutineHotSearch();
  90. },
  91. methods: {
  92. // 清空历史记录
  93. remove() {
  94. let self = this
  95. uni.showModal({
  96. title: '提示',
  97. content: '确认删除全部历史搜索记录?',
  98. success: function(res) {
  99. if (res.confirm) {
  100. self.tempStorage = []
  101. try {
  102. uni.setStorageSync('historyPlant', self.tempStorage)
  103. self.historyList = []
  104. } catch (e) {}
  105. } else if (res.cancel) {
  106. console.log('用户点击取消');
  107. }
  108. }
  109. });
  110. },
  111. getRoutineHotSearch: function() {
  112. let that = this;
  113. hotSearchLst().then(res => {
  114. that.$set(that, 'hotSearchList', res.data);
  115. });
  116. },
  117. setHotSearchValue: function(event, key) {
  118. this.focus = false
  119. if (key) {
  120. this.$set(this, 'searchValue', event.keyword);
  121. } else {
  122. this.$set(this, 'searchValue', event);
  123. }
  124. this.$nextTick(() => {
  125. this.focus = true
  126. })
  127. this.searchBut()
  128. },
  129. setValue: function(event) {
  130. this.$set(this, 'searchValue', event.detail.value);
  131. },
  132. searchBut: function() {
  133. let status = false
  134. this.tempStorage.forEach((el, index) => {
  135. if (el == this.searchValue) {
  136. status = true
  137. }
  138. })
  139. if (!status && this.searchValue) {
  140. this.tempStorage.unshift(this.searchValue)
  141. }
  142. try {
  143. uni.setStorageSync('historyPlant', this.tempStorage);
  144. } catch (e) {}
  145. uni.navigateTo({
  146. url: '/pages/plantGrass/plant_search_list/index?searchValue=' + this.searchValue
  147. })
  148. },
  149. searchCancle(){
  150. uni.navigateBack();
  151. }
  152. }
  153. }
  154. </script>
  155. <style>
  156. page {
  157. background-color: #fff;
  158. }
  159. </style>
  160. <style lang="scss" scoped>
  161. .searchGood .search {
  162. padding-left: 30rpx;
  163. margin-top: 20rpx;
  164. }
  165. .searchGood .search .input {
  166. width: 598rpx;
  167. background-color: #f7f7f7;
  168. border-radius: 33rpx;
  169. padding: 0 35rpx;
  170. box-sizing: border-box;
  171. height: 66rpx;
  172. }
  173. .searchGood .search .input input {
  174. width: 472rpx;
  175. font-size: 28rpx;
  176. }
  177. .searchGood .search .input .placeholder {
  178. color: #bbb;
  179. }
  180. .searchGood .search .input .iconfont {
  181. color: #000;
  182. font-size: 35rpx;
  183. }
  184. .searchGood .search .bnt {
  185. width: 120rpx;
  186. text-align: center;
  187. height: 66rpx;
  188. line-height: 66rpx;
  189. font-size: 30rpx;
  190. color: #282828;
  191. }
  192. .searchGood .title {
  193. position: relative;
  194. font-size: 28rpx;
  195. color: #282828;
  196. margin: 50rpx 30rpx 25rpx 30rpx;
  197. .icon-shanchu {
  198. position: absolute;
  199. right: 0;
  200. top: 50%;
  201. transform: translateY(-50%);
  202. color: #999;
  203. }
  204. }
  205. .searchGood .list {
  206. padding: 0 10rpx;
  207. overflow: hidden;
  208. }
  209. .searchGood .list .item {
  210. font-size: 26rpx;
  211. color: #666;
  212. padding: 0 21rpx;
  213. height: 60rpx;
  214. background: rgba(242, 242, 242, 1);
  215. border-radius: 22rpx;
  216. line-height: 60rpx;
  217. margin: 0 0 20rpx 20rpx;
  218. max-width: 150rpx;
  219. }
  220. .searchGood .line {
  221. border-bottom: 1rpx solid #eee;
  222. margin: 20rpx 30rpx 0 30rpx;
  223. }
  224. .more-btn {
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. margin: 0 0 20rpx 20rpx;
  229. height: 60rpx;
  230. font-size: 24rpx;
  231. color: #999;
  232. .iconfont {
  233. font-size: 22rpx;
  234. margin-left: 10rpx;
  235. }
  236. }
  237. </style>