search.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <view class="searchTarget-container container">
  3. <view class="searchTarget-header">
  4. <input type="text"
  5. placeholder="请输入关键字"
  6. placeholder-class="sea_ipt_placeholder"
  7. class="sea_ipt"
  8. v-model="searchTxt"
  9. focus="true"
  10. confirm-type="search"
  11. @confirm="searchHandle"/>
  12. <icon type="search" size="15" class="sea_ico"/>
  13. <view class="ipt-right">
  14. <icon type="clear" size="16" color="#E0E0E0" v-show="searchTxt" @click="clearIpt"/>
  15. <text class="line">|</text>
  16. <text @click="searchHandle" style="color: #3385FF;">搜索</text>
  17. </view>
  18. </view>
  19. <view class="search-cont">
  20. <template v-if="!isResult">
  21. <view class="search-cont-top" v-if="historySearchList.length">
  22. <view class="cont-tit">
  23. <text>搜索历史</text>
  24. <image src="@/static/img/empty_ico.png" class="empty_ico" @click="clearHistory"></image>
  25. </view>
  26. <view class="targetList">
  27. <view class="target-item" v-for="(item,index) in historySearchList" :key="index" @click="chooseTarget(item)">{{item}}</view>
  28. </view>
  29. </view>
  30. <view class="search-cont-top">
  31. <view class="cont-tit">
  32. <text>弘则推荐</text>
  33. </view>
  34. <view class="targetList">
  35. <view class="target-item" v-for="(item,index) in keywordList" :key="index" @click="chooseTarget(item)">{{item}}</view>
  36. </view>
  37. </view>
  38. </template>
  39. <template v-else>
  40. <block v-if="haveResult">
  41. <!-- 等接口待完善 -->
  42. <view class="tab-cont">
  43. <scroll-view
  44. scroll-x="true"
  45. scroll-with-animation
  46. class="scroll-tab"
  47. :scroll-into-view="'_'+tabIndex">
  48. <block v-for="(item, index) in tabBars" :key="item.ChartPermissionId">
  49. <view :id="'_'+index" class="scroll-tab-item" :class="{ active: tabAct_id === item.ChartPermissionId }" @click.stop="toggleTab(item,index)">
  50. {{item.PermissionName}}
  51. <image src="@/static/img/border_act.png" mode="" class="border_act" v-if="tabAct_id === item.ChartPermissionId"></image>
  52. </view>
  53. </block>
  54. </scroll-view>
  55. </view>
  56. <view class="result-data">
  57. <view class="report-ul">
  58. <view class="report-item" v-for="(report,index) in resultList" :key="index" v-if="index%2 === 0" @click="goDetail(report)">
  59. <!-- <view class="item-content">{{report.content}}</view> -->
  60. <view class="item-content"><u-parse :html="report.Body[0]+'...'"></u-parse></view>
  61. <view class="line"></view>
  62. <view class="item-title"><u-parse :html="report.Title"></u-parse></view>
  63. <view class="item-abstract" v-if="report.abstract">
  64. <image src="@/static/img/report_ico.png" class="report_ico"></image>
  65. {{report.abstract}}
  66. </view>
  67. <text class="item-createtime">{{report.PublishDate}}</text>
  68. </view>
  69. </view>
  70. <view class="report-ul">
  71. <view class="report-item" v-for="(report,index) in resultList" :key="index" v-if="index%2 !== 0" @click="goDetail(report)">
  72. <!-- <view class="item-content">{{report.content}}</view> -->
  73. <view class="item-content"><u-parse :html="report.Body[0]+'...'"></u-parse></view>
  74. <view class="line"></view>
  75. <view class="item-title"><u-parse :html="report.Title"></u-parse></view>
  76. <view class="item-abstract" v-if="report.ExpertBackground">
  77. <image src="@/static/img/report_ico.png" class="report_ico"></image>
  78. {{report.ExpertBackground}}
  79. </view>
  80. <text class="item-createtime">{{report.PublishDate}}</text>
  81. </view>
  82. </view>
  83. </view>
  84. <u-loadmore :status="status" icon-type="flower" :load-text="loadText" bg-color="#F7F7F7" padding-bottom="20rpx"/>
  85. <!-- v-if="totalPage>1" -->
  86. </block>
  87. <view class="nodata" v-else>
  88. <image src="@/static/img/nodata.png" mode="" class="nodata_ico"></image>
  89. <text>未找到您想搜索的内容</text>
  90. </view>
  91. </template>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. import { Search } from '@/config/api.js';
  97. import { Debounce,Throttle } from '@/config/util.js'
  98. export default {
  99. data() {
  100. return {
  101. searchTxt:'',//搜索关键字
  102. isResult:false,//显示搜索结果
  103. haveResult:true,//是否有搜索数据
  104. // 历史搜索列表
  105. historySearchList:[],
  106. // 关键字列表
  107. keywordList:[],
  108. targetList:[],//所有指标列表
  109. // 搜索结果列表
  110. resultList:[],
  111. page_no: 1,
  112. pageSize: 10,
  113. totalPage: 0,
  114. orderColumn:'Comprehensive',
  115. loadText:{
  116. loadmore: '上拉加载更多',
  117. loading: '加载中',
  118. nomore: '已经到底了'
  119. },
  120. status:'loadmore',
  121. tabAct_id: 1,
  122. isTabAct:true,
  123. tabBars: [{
  124. PermissionName: '综合排序',
  125. ChartPermissionId:1,
  126. mode:'Comprehensive'
  127. }, {
  128. PermissionName: '匹配度排序',
  129. ChartPermissionId:2,
  130. mode:'Matching'
  131. }, {
  132. PermissionName: '发布时间排序',
  133. ChartPermissionId:3,
  134. mode:'PublishDate'
  135. }],
  136. };
  137. },
  138. watch:{
  139. searchTxt(newVal) {
  140. if(newVal.length <= 0) {
  141. this.tabAct_id=1
  142. this.isResult = false;
  143. }
  144. },
  145. //监听tabs的变化
  146. tabAct_id: {
  147. handler() {
  148. if(this.isTabAct){
  149. // console.log(111)
  150. // this.getDataList();
  151. }
  152. },
  153. // immediate:true
  154. }
  155. },
  156. methods:{
  157. //tabs切换事件
  158. toggleTab (item,index) {
  159. this.orderColumn=item.mode
  160. if(this.tabAct_id !== item.ChartPermissionId) {
  161. this.tabAct_id = item.ChartPermissionId;
  162. this.pageNum = 1;
  163. this.getDataList();
  164. uni.pageScrollTo({
  165. scrollTop: 0,
  166. duration: 0,
  167. });
  168. }
  169. },
  170. /* 获取关键词 */
  171. getKeyWord() {
  172. Search.getKeys().then(res => {
  173. if(res.Ret === 200) {
  174. this.keywordList = res.Data.Item.ConfigValue ? res.Data.Item.ConfigValue.split(',') : [];
  175. }
  176. })
  177. },
  178. // 选择历史搜索
  179. chooseTarget(item) {
  180. this.searchTxt = item;
  181. this.SecName = item;
  182. this.resultList = [];
  183. this.page_no = 1;
  184. this.getDataList();
  185. },
  186. // 键盘输入过程中
  187. searchDoing() {
  188. this.isResult = false;
  189. //全部指标列表
  190. let arr = JSON.parse(JSON.stringify(this.targetList));
  191. let filterArr = [];
  192. // // 过滤出符合搜索条件的值
  193. arr.forEach((item,index)=>{
  194. if(item.SecName.includes(this.searchTxt)){
  195. item.SecName = this.join(item.SecName,this.searchTxt)
  196. filterArr.unshift(item);
  197. }
  198. });
  199. this.keywordList = filterArr;
  200. },
  201. // 拼接
  202. join(str,key){
  203. return str.replace(new RegExp(`${key}`, 'g'), `%%${key}%%`).split('%%');
  204. },
  205. // 搜索数据
  206. searchHandle: Debounce(function() {
  207. if(this.searchTxt) {
  208. //添加搜索记录
  209. if(!this.historySearchList.includes(this.searchTxt)) {
  210. this.historySearchList.unshift(this.searchTxt);
  211. this.$db.set('historySearchList',JSON.stringify(this.historySearchList))
  212. }
  213. this.resultList = [];
  214. this.page_no = 1;
  215. this.getDataList();
  216. }else {
  217. this.$util.toast('请输入关键字')
  218. }
  219. }),
  220. // 查找数据
  221. getDataList() {
  222. this.isResult = true;
  223. Search.getResult({
  224. KeyWord: this.searchTxt,
  225. // PageSize: this.pageSize,
  226. // CurrentIndex: this.page_no,
  227. OrderColumn:this.orderColumn
  228. }).then(res => {
  229. if(res.Ret === 200) {
  230. // this.status = this.page_no < res.Data.Paging.Pages ? 'loadmore' : 'nomore';
  231. this.status = 'nomore';
  232. this.totalPage = res.Data.Paging.Pages;//总页数
  233. if(this.page_no === 1) {
  234. this.resultList = res.Data.List || [];
  235. this.haveResult = this.resultList.length ? true : false
  236. }else {
  237. this.resultList = this.resultList.concat(res.Data.List)
  238. }
  239. }
  240. })
  241. },
  242. // 点击数据列表修改数据
  243. itemClick(item) {
  244. let data = encodeURIComponent(JSON.stringify(item));
  245. uni.navigateTo({
  246. url:'/pages/recordData/recordData?data=' + data
  247. })
  248. },
  249. /* 表单清空 */
  250. clearIpt() {
  251. this.searchTxt = '';
  252. this.isTabAct=false
  253. this.orderColumn='Comprehensive'
  254. //
  255. },
  256. /* 历史搜索清空 */
  257. clearHistory() {
  258. this.historySearchList = [];
  259. this.$db.del('historySearchList');
  260. },
  261. /* 进入详情 校验是否有该品种权限 */
  262. goDetail(item) {
  263. uni.navigateTo({
  264. url:'/pages/reportDetail/reportDetail?id=' + item.ArticleId,
  265. });
  266. },
  267. },
  268. /* 触底 */
  269. onReachBottom: Throttle(function() {
  270. // this.status = 'nomore';
  271. if(this.isResult) {
  272. // if(this.status === 'nomore') return ;
  273. // this.page_no++;
  274. // this.getDataList();
  275. }
  276. }),
  277. onLoad() {
  278. // 获取历史搜索记录
  279. if(this.$db.get('historySearchList')) {
  280. let historyList = JSON.parse(this.$db.get('historySearchList'));
  281. this.historySearchList = historyList;
  282. }
  283. },
  284. onShow() {
  285. this.getKeyWord();
  286. }
  287. }
  288. </script>
  289. <style lang="scss">
  290. .searchTarget-container {
  291. background-color: #fff;
  292. .searchTarget-header {
  293. padding: 0 34rpx;
  294. width: 100%;
  295. background-color: #fff;
  296. position: fixed;
  297. top: 0;
  298. left: 0;
  299. z-index: 99;
  300. padding: 30rpx 0;
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. .sea_ipt_placeholder {
  305. color: #E5E5E5;
  306. }
  307. .sea_ipt {
  308. width: 682rpx;
  309. height: 70rpx;
  310. line-height: 70rpx;
  311. box-sizing: border-box;
  312. border: 1rpx solid #E5E5E5;
  313. background-color: rgba(245, 245, 245, 0.2);
  314. font-size: 26rpx;
  315. color: #4A4A4A;
  316. padding: 0 180rpx 0 78rpx;
  317. border-radius: 70rpx;
  318. }
  319. .sea_ico {
  320. width: 31rpx;
  321. height: 31rpx;
  322. position: absolute;
  323. left: 68rpx;
  324. top: 50%;
  325. transform: translateY(-50%);
  326. }
  327. .ipt-right {
  328. display: flex;
  329. align-items: center;
  330. position: absolute;
  331. right:59rpx;
  332. top: 50%;
  333. transform: translateY(-50%);
  334. color: #3385FF;
  335. .line {
  336. margin: 0 21rpx;
  337. color: #E0E0E0;
  338. }
  339. }
  340. }
  341. .search-cont {
  342. padding-top: 130rpx;
  343. .search-cont-top {
  344. padding: 0 34rpx 0;
  345. margin-bottom: 10rpx;
  346. padding-top: 20rpx;
  347. &:last-child {
  348. margin-bottom: 0;
  349. }
  350. .cont-tit {
  351. color: #666;
  352. font-size: 28rpx;
  353. margin-bottom: 30rpx;
  354. display: flex;
  355. justify-content: space-between;
  356. .empty_ico {
  357. width: 32rpx;
  358. height: 33rpx;
  359. }
  360. }
  361. .targetList {
  362. display: flex;
  363. flex-wrap: wrap;
  364. // justify-content: space-between;
  365. .target-item {
  366. padding: 4rpx 18rpx;
  367. color: #4A4A4A;
  368. font-size: 26rpx;
  369. // border: 1rpx solid #3385ff;
  370. background-color: #F7F7F7;
  371. margin-bottom: 30rpx;
  372. margin-right: 30rpx;
  373. border-radius: 20rpx;
  374. }
  375. }
  376. }
  377. .result-cont {
  378. padding: 0 34rpx 0;
  379. padding-left: 21rpx;
  380. .result-list {
  381. display: flex;
  382. align-items: center;
  383. color: #333;
  384. padding-bottom: 30rpx;
  385. border-bottom: 1rpx solid #EBEDF0;
  386. margin-bottom: 30rpx;
  387. .result_ico {
  388. width: 28rpx;
  389. height: 28rpx;
  390. margin-right: 20rpx;
  391. }
  392. text {
  393. display: inline;
  394. }
  395. .highlight {
  396. color: #3385FF;
  397. }
  398. }
  399. }
  400. .result-data {
  401. margin-top: 80rpx;
  402. min-height: calc(100vh - 130rpx);
  403. padding: 20rpx 34rpx 40rpx;
  404. display: flex;
  405. background-color: #F7F7F7;
  406. .report-ul {
  407. width: 50%;
  408. &:first-child {
  409. margin-right: 10rpx;
  410. }
  411. .report-item {
  412. padding: 20rpx 20rpx 24rpx 20rpx;
  413. margin-bottom: 20rpx;
  414. border-radius: 8rpx;
  415. box-shadow: 0 3rpx 6rpx rgba($color: #000000, $alpha: 0.16);
  416. background: #fff;
  417. .item-content {
  418. // height: 273rpx;
  419. font-size: 24rpx;
  420. line-height: 40rpx;
  421. color: #7F7F7F;
  422. display: -webkit-box;
  423. // text-overflow:ellipsis;
  424. // overflow: hidden;
  425. text {
  426. display: inline;
  427. }
  428. }
  429. .line {
  430. margin: 18rpx 0;
  431. content: '';
  432. width: 100%;
  433. height: 1px;
  434. padding: 0 32rpx;
  435. box-sizing: border-box;
  436. background-color: #E5E5E5;
  437. -webkit-transform: scale(1, 0.5);
  438. transform: scale(1, 0.5);
  439. -webkit-transform-origin: center bottom;
  440. transform-origin: center bottom;
  441. }
  442. .item-title {
  443. font-size: 28rpx;
  444. color: #4A4A4A;
  445. margin-bottom: 10rpx;
  446. text {
  447. display: inline;
  448. }
  449. }
  450. .item-abstract {
  451. font-size: 26rpx;
  452. color: #6A6A6A;
  453. margin-bottom: 10rpx;
  454. .report_ico {
  455. width: 32rpx;
  456. height: 26rpx;
  457. margin-right: 20rpx;
  458. display: inline-block;
  459. }
  460. }
  461. .item-createtime {
  462. color: #ACACAC;
  463. font-size: 24rpx;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. .tab-cont {
  470. position: fixed;
  471. top: 128rpx;
  472. width: 100%;
  473. padding: 0 26rpx;
  474. background-color: #fff;
  475. font-size: 32rpx;
  476. z-index: 99;
  477. box-shadow: 0 3rpx 6rpx rgba(187,216,255,0.2);
  478. .scroll-tab {
  479. width: 100%;
  480. white-space: nowrap;
  481. }
  482. .scroll-tab-item {
  483. // flex-grow: 1;
  484. text-align: center;
  485. display: inline-block;
  486. padding: 0 8rpx 30rpx 8rpx;
  487. margin-right: 40rpx;
  488. border-bottom: 8rpx solid transparent;
  489. position: relative;
  490. &:last-child {
  491. margin-right: 0;
  492. }
  493. &.active {
  494. border-bottom: none;
  495. color: #2C83FF;
  496. font-weight: 700;
  497. }
  498. .border_act {
  499. width: 100%;
  500. height: 8rpx;
  501. position: absolute;
  502. bottom: 0;
  503. left: 0;
  504. }
  505. }
  506. }
  507. }
  508. </style>