index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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~2021 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. isAuto: false, //没有授权的不会自动授权
  74. isShowAuth: false, //是否隐藏授权
  75. };
  76. },
  77. onLoad() {
  78. },
  79. onShow: function() {
  80. try {
  81. this.historyList = []
  82. this.tempStorage = []
  83. let arr = uni.getStorageSync('historyPlant')
  84. if (arr.length > 0) {
  85. this.historyList = arr
  86. } else {
  87. this.historyList = []
  88. }
  89. this.tempStorage = this.historyList
  90. } catch (e) {}
  91. this.getRoutineHotSearch();
  92. },
  93. methods: {
  94. // 清空历史记录
  95. remove() {
  96. let self = this
  97. uni.showModal({
  98. title: '提示',
  99. content: '确认删除全部历史搜索记录?',
  100. success: function(res) {
  101. if (res.confirm) {
  102. self.tempStorage = []
  103. try {
  104. uni.setStorageSync('historyPlant', self.tempStorage)
  105. self.historyList = []
  106. } catch (e) {}
  107. } else if (res.cancel) {
  108. console.log('用户点击取消');
  109. }
  110. }
  111. });
  112. },
  113. getRoutineHotSearch: function() {
  114. let that = this;
  115. hotSearchLst().then(res => {
  116. that.$set(that, 'hotSearchList', res.data);
  117. });
  118. },
  119. setHotSearchValue: function(event, key) {
  120. this.focus = false
  121. if (key) {
  122. this.$set(this, 'searchValue', event.keyword);
  123. } else {
  124. this.$set(this, 'searchValue', event);
  125. }
  126. this.$nextTick(() => {
  127. this.focus = true
  128. })
  129. this.searchBut()
  130. },
  131. setValue: function(event) {
  132. this.$set(this, 'searchValue', event.detail.value);
  133. },
  134. searchBut: function() {
  135. let status = false
  136. this.tempStorage.forEach((el, index) => {
  137. if (el == this.searchValue) {
  138. status = true
  139. }
  140. })
  141. if (!status && this.searchValue) {
  142. this.tempStorage.unshift(this.searchValue)
  143. }
  144. try {
  145. uni.setStorageSync('historyPlant', this.tempStorage);
  146. } catch (e) {}
  147. uni.navigateTo({
  148. url: '/pages/plantGrass/plant_search_list/index?searchValue=' + this.searchValue
  149. })
  150. },
  151. searchCancle(){
  152. uni.navigateBack();
  153. }
  154. }
  155. }
  156. </script>
  157. <style>
  158. page {
  159. background-color: #fff;
  160. }
  161. </style>
  162. <style lang="scss" scoped>
  163. .searchGood .search {
  164. padding-left: 30rpx;
  165. margin-top: 20rpx;
  166. }
  167. .searchGood .search .input {
  168. width: 598rpx;
  169. background-color: #f7f7f7;
  170. border-radius: 33rpx;
  171. padding: 0 35rpx;
  172. box-sizing: border-box;
  173. height: 66rpx;
  174. }
  175. .searchGood .search .input input {
  176. width: 472rpx;
  177. font-size: 28rpx;
  178. }
  179. .searchGood .search .input .placeholder {
  180. color: #bbb;
  181. }
  182. .searchGood .search .input .iconfont {
  183. color: #000;
  184. font-size: 35rpx;
  185. }
  186. .searchGood .search .bnt {
  187. width: 120rpx;
  188. text-align: center;
  189. height: 66rpx;
  190. line-height: 66rpx;
  191. font-size: 30rpx;
  192. color: #282828;
  193. }
  194. .searchGood .title {
  195. position: relative;
  196. font-size: 28rpx;
  197. color: #282828;
  198. margin: 50rpx 30rpx 25rpx 30rpx;
  199. .icon-shanchu {
  200. position: absolute;
  201. right: 0;
  202. top: 50%;
  203. transform: translateY(-50%);
  204. color: #999;
  205. }
  206. }
  207. .searchGood .list {
  208. padding: 0 10rpx;
  209. overflow: hidden;
  210. }
  211. .searchGood .list .item {
  212. font-size: 26rpx;
  213. color: #666;
  214. padding: 0 21rpx;
  215. height: 60rpx;
  216. background: rgba(242, 242, 242, 1);
  217. border-radius: 22rpx;
  218. line-height: 60rpx;
  219. margin: 0 0 20rpx 20rpx;
  220. max-width: 150rpx;
  221. }
  222. .searchGood .line {
  223. border-bottom: 1rpx solid #eee;
  224. margin: 20rpx 30rpx 0 30rpx;
  225. }
  226. .more-btn {
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. margin: 0 0 20rpx 20rpx;
  231. height: 60rpx;
  232. font-size: 24rpx;
  233. color: #999;
  234. .iconfont {
  235. font-size: 22rpx;
  236. margin-left: 10rpx;
  237. }
  238. }
  239. </style>