search.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view>
  3. <u-navbar back-text="搜索" back-icon-size="28" back-icon-color="#ffffff"
  4. :background="{backgroundColor: '#2795FD',}" :back-text-style="{color: '#ffffff'}"></u-navbar>
  5. <!-- 搜索框 -->
  6. <view class="search">
  7. <view class="search-box">
  8. <view class="option">
  9. <nxsearch :selectList="selectList" button="inside" @search="doSearch" @confirm="doSearch" v-model="searchQuery.keyword" placeholder="输入关键字找工作" />
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 搜索历史 -->
  14. <view class="search-history">
  15. <view class="top">
  16. <view class="title">
  17. 搜索历史
  18. </view>
  19. <view class="clear" @click="clear()" >
  20. 清空历史
  21. </view>
  22. </view>
  23. <view class="history">
  24. <view class="tag" v-for="(mod,index) in searchHistory" :key="index" v-text="mod" @click="searchQuery.keyword=mod,submit()">
  25. 打杂
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as API from '@/apis/pagejs/packages.js'
  33. import nxsearch from "@/components/nx-search.vue"
  34. export default {
  35. components: {
  36. nxsearch
  37. },
  38. data() {
  39. return {
  40. step:true,//步骤 ,true第一步查询,false第二步显示结果
  41. searchQuery: {
  42. keyword: '',
  43. selectIndex: 0
  44. },
  45. selectList: [
  46. {
  47. id: 1,
  48. name: '找零工'
  49. },
  50. {
  51. id: 0,
  52. name: '找工作'
  53. }
  54. ],
  55. recordsTotal:0,
  56. listForm:{
  57. typeId:"",
  58. title:"",
  59. pageIndex: 1,
  60. pageSize: 4,
  61. totalPage: 1,
  62. },
  63. list: [
  64. ],
  65. searchHistory:[],
  66. }
  67. },
  68. onLoad(op){
  69. if(op.type){
  70. this.searchQuery.selectIndex=op.type
  71. }
  72. var sz=this.carhelp.get("setSearchHistory");
  73. if(sz){
  74. this.searchHistory=sz
  75. }else{
  76. this.searchHistory= []
  77. }
  78. },
  79. onReachBottom() {
  80. if (this.list.length < this.recordsTotal) {
  81. this.myLoadmore();
  82. }
  83. },
  84. methods: {
  85. ckInfo(id){
  86. var url="/pages/news/articleDetails?id="+id;
  87. uni.navigateTo({
  88. url:url
  89. })
  90. },
  91. clear(){
  92. this.setSearchHistory([]);
  93. mui.toast("搜索内容已清空");
  94. },
  95. setHistory(){
  96. //搜索记录保存
  97. var key =this.searchQuery.keyword;
  98. var sz=this.searchHistory;
  99. if(!sz){
  100. sz=[];
  101. }
  102. var temp =[];
  103. //去重 ,后插入的,排队到最前面
  104. if(sz.length){
  105. for(var i in sz){
  106. if(i==0){
  107. temp.push(key);
  108. }
  109. if(sz[i]==key){
  110. continue;
  111. }
  112. temp.push(sz[i]);
  113. if(temp.length==10){
  114. break
  115. }
  116. }
  117. }else{
  118. temp.push(key);
  119. }
  120. this.setSearchHistory(temp);
  121. },
  122. setSearchHistory(obj){
  123. this.searchHistory=obj
  124. this.carhelp.set("setSearchHistory",obj)
  125. },
  126. blur(){
  127. },
  128. focus(){
  129. this.step=true;
  130. },
  131. submit(){
  132. if(!this.searchQuery.keyword){
  133. return
  134. }
  135. this.setHistory()
  136. this.step=false;
  137. this.listForm.pageIndex=1
  138. // var ref =this.$refs.searchinput.getRef()
  139. // ref.blur()
  140. this.query();
  141. },
  142. myLoadmore(){
  143. this.listForm.pageIndex += 1;
  144. this.query();
  145. },
  146. query(){
  147. uni.showLoading({
  148. title: "加载中",
  149. mask: true,
  150. })
  151. API.findRecruitSearch({
  152. pageIndex:1,
  153. pageSize:20,
  154. type:this.selectList[this.searchQuery.selectIndex].id,
  155. content:this.searchQuery.keyword
  156. }).then((res) => {
  157. uni.hideLoading();
  158. this.tabList[this.current].list=res.data.data
  159. this.tabList[this.current].recordsTotal=res.data.recordsTotal
  160. }).catch(error => {
  161. uni.showToast({
  162. title: error
  163. })
  164. //this.getPhone()
  165. })
  166. },
  167. // 执行搜索
  168. doSearch(searchQuery) {
  169. console.log('searchQuery', searchQuery);
  170. this.submit()
  171. },
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. // 搜索框
  177. .search {
  178. padding: 16rpx 32rpx;
  179. .search-box {
  180. border-radius: 50px;
  181. // background-color: rgba(243, 246, 249, 1);
  182. height: 72rpx;
  183. line-height: 72rpx;
  184. }
  185. }
  186. // 搜索历史
  187. .search-history{
  188. padding: 0 32rpx;
  189. margin-top: 40rpx;
  190. .top{
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. .title{
  195. color: #101010;
  196. }
  197. .clear{
  198. color: rgba(169, 169, 169, 1);
  199. font-size: 24rpx;
  200. }
  201. }
  202. .history{
  203. display: flex;
  204. margin-top: 16rpx;
  205. .tag{
  206. width: 144rpx;
  207. height: 56rpx;
  208. line-height: 56rpx;
  209. border-radius: 4px;
  210. background-color: rgba(241, 244, 247, 1);
  211. color: rgba(88, 88, 88, 1);
  212. font-size: 12px;
  213. text-align: center;
  214. font-family: Arial;
  215. margin-right: 16rpx;
  216. }
  217. }
  218. }
  219. </style>