search.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="goods-search flex-col">
  3. <view class="header-wrap">
  4. <view class="search">
  5. <u-search v-model="keyword" @focus="showHistory = true" :focus="showHistory" @search="onSearch" @custom="onSearch"
  6. bg-color="#F4F4F4" :height="60" :action-style="actionStyle"></u-search>
  7. </view>
  8. </view>
  9. <view v-show="showHistory" class="search-content bg-white">
  10. <scroll-view :scroll-y="true" style="height: 100%">
  11. <view class="search-words">
  12. <view class="title flex row-between">
  13. <view>历史搜索</view>
  14. <view class="xs muted m-r-20" style="padding: 10rpx 20rpx" @tap="clearSearchFun">清空</view>
  15. </view>
  16. <view class="words flex flex-wrap">
  17. <view v-for="(item, index) in historyList" :key="index" class="item m-r-20 m-b-20 line-1"
  18. @tap="onChangeKeyword(item)">{{item}}
  19. </view>
  20. </view>
  21. </view>
  22. <view class="search-words">
  23. <view class="title">热门搜索</view>
  24. <view class="words flex flex-wrap">
  25. <view v-for="(item, index) in appConfig.hot_search" :key="index"
  26. class="item m-r-20 m-b-20 line-1" @tap="onChangeKeyword(item)">{{item}}</view>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <view class="content">
  32. <!-- 搜索结果列表 -->
  33. <search-list :keyword="keyword"></search-list>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. getHistorySearch,
  40. clearSearch
  41. } from '@/api/app';
  42. import {
  43. mapGetters
  44. } from 'vuex';
  45. import {
  46. trottle
  47. } from '@/utils/tools';
  48. export default {
  49. data() {
  50. return {
  51. keyword: '',
  52. page: 1,
  53. showHistory: false,
  54. historyList: []
  55. };
  56. },
  57. watch: {
  58. // 监听属性
  59. keyword(value, old) {
  60. if (!value && !this.id) {
  61. this.showHistory = true
  62. }
  63. },
  64. showHistory(value) {
  65. if (value) {
  66. this.getSearchpageFun();
  67. }
  68. },
  69. },
  70. onLoad(options) {
  71. this.onSearch = trottle(this.onSearch, 500, this);
  72. this.init(options);
  73. },
  74. computed: {
  75. ...mapGetters(['sysInfo', 'appConfig']),
  76. actionStyle() {
  77. return {
  78. 'background': '#DD4250',
  79. 'border-radius': '100rpx',
  80. 'font-size': '24rpx',
  81. 'width': '100rpx',
  82. 'height': '60rpx',
  83. 'line-height': '60rpx',
  84. 'color': '#ffffff',
  85. 'flex': 'none'
  86. }
  87. }
  88. },
  89. methods: {
  90. downCallback() {
  91. this.onRefresh()
  92. },
  93. onChange(e) {
  94. this.keyword = e.value
  95. },
  96. clearSearchFun() {
  97. clearSearch().then(res => {
  98. if (res.code == 1) {
  99. this.getSearchpageFun();
  100. }
  101. });
  102. },
  103. init(option) {
  104. const {
  105. id,
  106. name,
  107. type
  108. } = this.$Route.query
  109. this.type = type
  110. if (id) {
  111. uni.setNavigationBarTitle({
  112. title: name
  113. });
  114. this.id = id;
  115. this.$nextTick(() => {
  116. this.onRefresh()
  117. })
  118. } else {
  119. uni.setNavigationBarTitle({
  120. title: '人才搜索'
  121. });
  122. this.showHistory = true
  123. }
  124. },
  125. getSearchpageFun() {
  126. getHistorySearch().then(res => {
  127. if (res.code == 1) {
  128. this.historyList = res.data
  129. }
  130. });
  131. },
  132. onClear() {
  133. if (this.id) {
  134. this.onRefresh();
  135. }
  136. },
  137. onSearch() {
  138. this.showHistory = false
  139. this.$nextTick(() => {
  140. this.onRefresh()
  141. })
  142. },
  143. onRefresh() {
  144. //通风报信
  145. uni.$emit("refreshTalentsSearchList", {
  146. keyword: this.keyword
  147. })
  148. },
  149. onChangeKeyword(item) {
  150. this.keyword = item
  151. this.showHistory = false
  152. this.onRefresh();
  153. },
  154. }
  155. };
  156. </script>
  157. <style lang="scss">
  158. page {
  159. height: 100%;
  160. padding: 0;
  161. }
  162. .goods-search {
  163. height: 100%;
  164. position: relative;
  165. .header-wrap {
  166. position: relative;
  167. z-index: 999;
  168. .search {
  169. background: #fff;
  170. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.03);
  171. position: relative;
  172. z-index: 1;
  173. padding: 0 30rpx 20rpx;
  174. }
  175. }
  176. .search-content {
  177. position: absolute;
  178. width: 100%;
  179. height: 100%;
  180. padding-top: 100rpx;
  181. z-index: 100;
  182. .search-words {
  183. padding-left: 24rpx;
  184. padding-bottom: 20rpx;
  185. .title {
  186. padding: 26rpx 0;
  187. font-size: 32rpx;
  188. font-weight: 500;
  189. }
  190. .words {
  191. .item {
  192. line-height: 66rpx;
  193. height: 66rpx;
  194. padding: 0 24rpx;
  195. background: #F7F8FA;
  196. border-radius: 8rpx 8rpx 8rpx 8rpx;
  197. font-size: 24rpx;
  198. color: #666666;
  199. }
  200. }
  201. }
  202. }
  203. .content {
  204. flex: 1;
  205. min-height: 0;
  206. .goods-list {
  207. overflow: hidden;
  208. }
  209. }
  210. }
  211. </style>