search.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="goods-search flex-col bg-white">
  3. <div class="nav-container flex">
  4. <el-breadcrumb style="flex: 1;" separator="/">
  5. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  6. <el-breadcrumb-item class="line1" style="max-width: 800px;">搜索:{{ keyword}}</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div v-show="showHistory" class="search-content bg-white">
  10. <div :scroll-y="true" style="height: 100%">
  11. <div class="search-words">
  12. <div class="title flex row-between">
  13. <div>历史搜索</div>
  14. <div class="xs muted m-r-20" style="padding: 10px 20px" @click="clearSearchFun">清空</div>
  15. </div>
  16. <div class="words flex flex-wrap">
  17. <div v-for="(item, index) in historyList" :key="index" class="item m-r-20 m-b-20 line-1"
  18. @click="onChangeKeyword(item)">{{item}}
  19. </div>
  20. </div>
  21. </div>
  22. <div class="search-words">
  23. <div class="title">热门搜索</div>
  24. <div class="words flex flex-wrap">
  25. <div v-for="(item, index) in config.hot_search" :key="index"
  26. class="item m-r-20 m-b-20 line-1" @click="onChangeKeyword(item)">{{item}}</div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="content" v-show="!showHistory">
  32. <!-- 搜索结果列表 -->
  33. <div v-if="talentsList.length > 0">
  34. <talents-list :list="talentsList" />
  35. <div class="pagination flex row-center" style="padding-bottom: 38px" v-if="count">
  36. <el-pagination background hide-on-single-page layout="prev, pager, next" :page-size="9"
  37. :total="count" prev-text="上一页" next-text="下一页" @current-change="changePage">
  38. </el-pagination>
  39. </div>
  40. </div>
  41. <null-data v-else :img="require('@/static/images/goods_null.png')" text="暂无数据~"></null-data>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import {
  47. mapState
  48. } from 'vuex';
  49. import {
  50. trottle
  51. } from '@/utils/tools';
  52. export default {
  53. data() {
  54. return {
  55. keyword: '',
  56. page: 1,
  57. showHistory: false,
  58. historyList: [],
  59. talentsList: [],
  60. };
  61. },
  62. watch: {
  63. // 监听属性
  64. keyword(value, old) {
  65. if (!value && !this.id) {
  66. this.showHistory = true
  67. }
  68. },
  69. showHistory(value) {
  70. if (value) {
  71. this.getSearchpageFun();
  72. }
  73. },
  74. },
  75. created() {
  76. this.onSearch = trottle(this.onSearch, 500, this);
  77. this.init();
  78. },
  79. mounted() {
  80. this.$nuxt.$on('search', (val) => {
  81. this.keyword = val
  82. this.showHistory = false
  83. this.getTalents()
  84. })
  85. this.$nuxt.$on('searchFouce', (val) => {
  86. this.showHistory = true
  87. })
  88. },
  89. computed: {
  90. ...mapState(['sysInfo', 'config']),
  91. actionStyle() {
  92. return {
  93. 'background': '#DD4250',
  94. 'border-radius': '100px',
  95. 'font-size': '24px',
  96. 'width': '100px',
  97. 'height': '60px',
  98. 'line-height': '60px',
  99. 'color': '#ffffff',
  100. 'flex': 'none'
  101. }
  102. }
  103. },
  104. methods: {
  105. downCallback() {
  106. this.onRefresh()
  107. },
  108. onChange(e) {
  109. this.keyword = e.value
  110. },
  111. clearSearchFun() {
  112. clearSearch().then(res => {
  113. if (res.code == 1) {
  114. this.getSearchpageFun();
  115. }
  116. });
  117. },
  118. init() {
  119. const {
  120. id,
  121. name,
  122. type
  123. } = this.$route.query
  124. this.type = type
  125. if (id) {
  126. // uni.setNavigationBarTitle({
  127. // title: name
  128. // });
  129. this.id = id;
  130. this.$nextTick(() => {
  131. this.onRefresh()
  132. })
  133. } else {
  134. // uni.setNavigationBarTitle({
  135. // title: '人才搜索'
  136. // });
  137. this.showHistory = true
  138. }
  139. },
  140. getSearchpageFun() {
  141. this.$get('article/history-search', {}).then(res => {
  142. if (res.code == 1) {
  143. this.historyList = res.data
  144. }
  145. });
  146. },
  147. onClear() {
  148. if (this.id) {
  149. this.onRefresh();
  150. }
  151. },
  152. onSearch() {
  153. this.showHistory = false
  154. this.$nextTick(() => {
  155. this.onRefresh()
  156. })
  157. },
  158. onRefresh() {
  159. this.getTalents()
  160. },
  161. changePage(current) {
  162. this.page = current
  163. this.getTalents()
  164. },
  165. async getTalents() {
  166. const params = {
  167. page_size: 9,
  168. page_no: this.page,
  169. cid: this.cateTwoId,
  170. chain: this.chain
  171. }
  172. const {
  173. code,
  174. data,
  175. _meta
  176. } = await this.$get('article', {
  177. params,
  178. })
  179. if (code == 1) {
  180. this.talentsList = data
  181. this.count = _meta.totalCount
  182. }
  183. },
  184. onChangeKeyword(item) {
  185. this.keyword = item
  186. this.showHistory = false
  187. this.$nuxt.$emit('keyword', this.keyword);
  188. this.onRefresh();
  189. },
  190. }
  191. };
  192. </script>
  193. <style lang="scss">
  194. page {
  195. height: 100%;
  196. padding: 0;
  197. }
  198. .goods-search {
  199. height: 100%;
  200. position: relative;
  201. .header-wrap {
  202. position: relative;
  203. z-index: 999;
  204. .search {
  205. background: #fff;
  206. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.03);
  207. position: relative;
  208. z-index: 1;
  209. padding: 0 30px 20px;
  210. }
  211. }
  212. .nav-container {
  213. padding: 24px 24px 0;
  214. }
  215. .search-content {
  216. // position: absolute;
  217. width: 100%;
  218. height: 100%;
  219. // padding-top: 100px;
  220. z-index: 100;
  221. .search-words {
  222. padding-left: 24px;
  223. padding-bottom: 20px;
  224. .title {
  225. padding: 26px 0;
  226. // font-size: 32px;
  227. font-weight: 500;
  228. }
  229. .words {
  230. .item {
  231. line-height: 33px;
  232. height: 33px;
  233. padding: 0 24px;
  234. background: #F7F8FA;
  235. border-radius: 8px 8px 8px 8px;
  236. // font-size: 24px;
  237. color: #666666;
  238. cursor: pointer;
  239. }
  240. }
  241. }
  242. }
  243. .content {
  244. flex: 1;
  245. min-height: 0;
  246. .goods-list {
  247. overflow: hidden;
  248. }
  249. }
  250. }
  251. </style>