indedxSearch.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <view class="container search-container">
  3. <view class="sticky-content">
  4. <view class="searchTarget-header">
  5. <input
  6. type="text"
  7. :placeholder="searchPlaceholderList.TabSearch"
  8. placeholder-class="sea_ipt_placeholder"
  9. class="sea_ipt"
  10. v-model="searchTxt"
  11. focus="true"
  12. confirm-type="search"
  13. @confirm="searchHandle"
  14. />
  15. <icon type="search" size="15" class="sea_ico" />
  16. <view class="ipt-right">
  17. <icon type="clear" size="16" color="#E0E0E0" v-show="searchTxt" @click="clearIpt" />
  18. <text class="line">|</text>
  19. <text @click="searchHandle" style="color: #3385ff">搜索</text>
  20. </view>
  21. </view>
  22. <view class="search-tabs" v-if="isResult">
  23. <view :class="['tabs-item', tabsActive === item.id && 'active']" v-for="item in tabsList" :key="item.id" @click="tabsHandel(item)">
  24. {{ item.title }}
  25. <view class="item-act" v-if="tabsActive === item.id"></view>
  26. </view>
  27. </view>
  28. <block v-if="isResult">
  29. <view class="more-summary more-box" v-if="(tabsActive === 1 || tabsActive === 2) && haveResultSummary">
  30. <view>
  31. <text class="more-text" v-if="tabsActive === 1"> 纪要/图表 </text>
  32. </view>
  33. <view style="display: flex; align-items: center">
  34. <view class="summary-select">
  35. <text @click="summarySelectHandler(item, '纪要')" :class="['select-item', summarySelectActive == item.value && 'active-item']" v-for="item in summarySelect" :key="item.value">{{
  36. item.name
  37. }}</text>
  38. </view>
  39. <view v-if="tabsActive === 1" class="more-rivet" @click="tabsActiveMore(2)"> 更多 <u-icon name="arrow-right" color="#3385FF" size="28"></u-icon> </view>
  40. </view>
  41. </view>
  42. <view class="activity-select" style="display: flex; align-items: center; justify-content: flex-end" v-if="tabsActive == 4">
  43. <view class="summary-select">
  44. <text @click="summarySelectHandler(item, '活动')" :class="['select-item', activitySelectActive == item.value && 'active-item']" v-for="item in activitySelect" :key="item.value">
  45. {{ item.name }}
  46. </text>
  47. </view>
  48. <view v-if="tabsActive === 1" class="more-rivet" @click="tabsActiveMore(2)"> 更多 <u-icon name="arrow-right" color="#3385FF" size="28"></u-icon> </view>
  49. </view>
  50. </block>
  51. </view>
  52. <view class="search-cont" v-if="!isResult">
  53. <block v-for="key in keywordList" :key="key.title">
  54. <view class="history" v-if="key.title !== '搜索历史' || (key.title == '搜索历史' && historySearchList.length)">
  55. <view class="history-title title">
  56. <text>{{ key.title }}</text>
  57. <image v-if="key.imgShown" @click="clearHistory" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/empty_ico.png" class="empty_ico"></image>
  58. </view>
  59. <view class="history-item">
  60. <block v-for="(item, index) in relyOn(key.title)" :key="item">
  61. <block v-if="key.title == '搜索历史'">
  62. <view v-if="index < 8" class="item" @click="chooseTarget(item)">{{ item }}</view>
  63. </block>
  64. <view v-else class="item" @click="chooseTarget(item)">{{ item }}</view>
  65. </block>
  66. </view>
  67. </view>
  68. </block>
  69. </view>
  70. <view v-else class="content">
  71. <block v-if="haveResult">
  72. <view>
  73. <summary-chart :resultList="tabsActive == 1 ? resultList.slice(0, 10) : resultList" :tabsActiveChild="tabsActive" v-if="resultList.length && (tabsActive == 2 || tabsActive == 1)" />
  74. <view class="more-report more-box" v-if="tabsActive === 1 && haveResultReport">
  75. <text class="more-text"> 资源包/报告 </text>
  76. <view>
  77. <view class="more-rivet" @click="tabsActiveMore(3)"> 更多 <u-icon name="arrow-right" color="#3385FF" size="28"></u-icon> </view>
  78. </view>
  79. </view>
  80. <reportPage :reportPageData="reportPageData" v-if="Object.keys(reportPageData).length && (tabsActive == 3 || tabsActive == 1)" />
  81. <view class="more-activity more-box" v-if="tabsActive === 1 && haveResultActivity">
  82. <text class="more-text"> 活动/回放 </text>
  83. <view>
  84. <view class="more-rivet" @click="tabsActiveMore(4)"> 更多 <u-icon name="arrow-right" color="#3385FF" size="28"></u-icon> </view>
  85. </view>
  86. </view>
  87. <activityBack :collectLists="collectList" :tabsActiveSearch="tabsActive" v-if="collectList.length && (tabsActive == 4 || tabsActive == 1)" />
  88. </view>
  89. </block>
  90. <view class="nodata" v-else>
  91. <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
  92. <text>未找到您想搜索的内容</text>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import { KeywordList, TabsList, SummarySelect, ActivitySelect } from "./searchList";
  99. import { Search, activity, Report } from "@/config/api";
  100. import { Debounce, Throttle } from "@/config/util.js";
  101. import summaryChart from "../components/summaryChart.vue";
  102. import activityBack from "../components/activityBack.vue";
  103. import reportPage from "../components/report.vue";
  104. export default {
  105. components: { summaryChart, activityBack, reportPage },
  106. data() {
  107. return {
  108. searchTxt: "",
  109. isResult: false,
  110. historySearchList: [], //历史搜索
  111. hotKeyWord: [], //热搜关键词
  112. wordList: [], //推荐关键词
  113. tabsActive: 1, //搜索的筛选条件
  114. resultList: [], //纪要与图表
  115. resultDataList: [], ////纪要与图表
  116. collectList: [], //活动的数据
  117. reportPageData: {}, //报告的数据
  118. // haveResult: true, //是否有搜索数据
  119. haveResultSummary: true, //是否有搜索数据
  120. haveResultActivity: true, //是否有搜索数据
  121. haveResultReport: true, //是否有搜索数据
  122. summarySelectActive: "Matching",
  123. activitySelectActive: "0",
  124. refresh: false, //正在下拉
  125. pageNum: 1,
  126. pageSize: null,
  127. totalPage: 0,
  128. status: "loadmore",
  129. loadText: {
  130. loadmore: "上拉加载更多",
  131. loading: "加载中",
  132. nomore: "已经到底了",
  133. },
  134. };
  135. },
  136. computed: {
  137. keywordList() {
  138. return KeywordList;
  139. },
  140. tabsList() {
  141. return TabsList;
  142. },
  143. summarySelect() {
  144. return SummarySelect;
  145. },
  146. activitySelect() {
  147. return ActivitySelect;
  148. },
  149. haveResult() {
  150. let all = this.haveResultSummary || this.haveResultActivity || this.haveResultReport;
  151. return this.tabsActive == 1 ? all : this.tabsActive == 2 ? this.haveResultSummary : this.tabsActive == 3 ? this.haveResultReport : this.haveResultActivity;
  152. },
  153. },
  154. watch: {
  155. tabsActive: {
  156. handler(val) {
  157. val == 1 ? (this.pageSize = 5) : (this.pageSize = 10);
  158. },
  159. deep: true,
  160. immediate: true,
  161. },
  162. },
  163. methods: {
  164. //搜索事件
  165. searchHandle() {
  166. if (this.searchTxt) {
  167. if (!this.historySearchList.includes(this.searchTxt)) {
  168. this.historySearchList.unshift(this.searchTxt);
  169. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  170. }
  171. this.getListInit();
  172. this.getDataList();
  173. } else {
  174. this.$util.toast("请输入关键字");
  175. }
  176. },
  177. //清除搜索关键字
  178. clearIpt() {
  179. this.searchTxt = "";
  180. this.tabsActive = 1;
  181. this.isResult = false;
  182. this.getListInit();
  183. },
  184. //关键词 遍历的依赖
  185. relyOn(val) {
  186. return val == "搜索历史" ? this.historySearchList : val == "热搜关键词" ? this.hotKeyWord : this.wordList;
  187. },
  188. //点击了筛选项目
  189. tabsHandel(item) {
  190. this.tabsActive = item.id;
  191. this.getListInit();
  192. this.getDataList();
  193. },
  194. //获取热搜关键词的请求
  195. async researchHotKeyWord() {
  196. const res = await Search.getKeys();
  197. if (res.Ret === 200) {
  198. this.hotKeyWord = res.Data.ListHot ? res.Data.ListHot.map((key) => key.KeyWord) : [];
  199. this.wordList = res.Data.Item ? res.Data.Item.ConfigValue.split(",") : [];
  200. }
  201. },
  202. // 选择历史搜索
  203. chooseTarget(item) {
  204. this.searchTxt = item;
  205. if (!this.historySearchList.includes(item)) {
  206. this.historySearchList.unshift(item);
  207. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  208. }
  209. this.getListInit();
  210. this.getDataList();
  211. },
  212. //搜索
  213. getDataList() {
  214. this.isResult = true;
  215. if (this.tabsActive == 1) {
  216. this.synthesiz();
  217. this.getReportList();
  218. this.getActivityBackList();
  219. } else if (this.tabsActive == 2) {
  220. this.synthesiz();
  221. } else if (this.tabsActive == 3) {
  222. this.getReportList();
  223. } else if (this.tabsActive == 4) {
  224. this.getActivityBackList();
  225. }
  226. },
  227. //纪要 图表的搜索
  228. async synthesiz() {
  229. const res = await Search.getArtAndChartList({
  230. KeyWord: this.searchTxt.replace(/^\s+|\s+$/g, ""),
  231. OrderColumn: this.summarySelectActive,
  232. PageSize: 10,
  233. CurrentIndex: this.pageNum,
  234. ListType: 1,
  235. });
  236. if (res.Ret === 200) {
  237. this.status = this.pageNum < res.Data.Paging.Pages ? "loadmore" : "nomore";
  238. this.totalPage = res.Data.Paging.Totals;
  239. if (this.pageNum == 1) {
  240. this.haveResultSummary = res.Data.List.length || res.Data.ChartList.length ? true : false;
  241. }
  242. if (res.Data.List.length && res.Data.ChartList.length) {
  243. if (this.pageNum == 1) {
  244. this.resultDataList.push(res.Data.List.shift());
  245. if (this.refresh) {
  246. uni.stopPullDownRefresh();
  247. this.refresh = false;
  248. }
  249. }
  250. let newArr = [];
  251. let newArrTwo = [];
  252. for (let i = 0; i < res.Data.List.length; i += 2) {
  253. newArr.push(res.Data.List.slice(i, i + 2));
  254. }
  255. for (let i = 0; i < res.Data.ChartList.length; i += 2) {
  256. newArrTwo.push(res.Data.ChartList.slice(i, i + 2));
  257. }
  258. let arr = [];
  259. newArr.forEach((item, index) => {
  260. if (newArrTwo[index]) {
  261. arr.push(newArrTwo[index], item);
  262. } else {
  263. arr.push(item);
  264. }
  265. });
  266. this.resultDataList = this.resultDataList.concat(arr.flat(Infinity));
  267. } else if (!res.Data.List.length) {
  268. res.Data.ChartList.length && this.resultDataList.push(...res.Data.ChartList);
  269. } else if (!res.Data.ChartList.length) {
  270. res.Data.List.length && this.resultDataList.push(...res.Data.List);
  271. }
  272. this.resultList = this.resultDataList;
  273. }
  274. },
  275. //活动回放的接口获取列表
  276. async getActivityBackList() {
  277. const res = await activity.getActivityListNew({
  278. PageSize: this.pageSize,
  279. CurrentIndex: this.pageNum,
  280. KeyWord: this.searchTxt,
  281. ActiveState: "1,2,3", //活动进行状态
  282. PlayBack: Number(this.activitySelectActive),
  283. });
  284. if (res.Ret !== 200) return;
  285. this.status = this.pageNum < res.Data.Paging.Pages ? "loadmore" : "nomore";
  286. this.totalPage = res.Data.Paging.Pages; //总页数
  287. if (this.pageNum === 1) {
  288. this.collectList = res.Data.List || [];
  289. this.haveResultActivity = this.collectList.length ? true : false;
  290. if (this.refresh) {
  291. uni.stopPullDownRefresh();
  292. this.refresh = false;
  293. }
  294. } else {
  295. this.collectList.push(...res.Data.List);
  296. }
  297. },
  298. //获取报告的
  299. async getReportList() {
  300. const res = await Report.getSearchReportAndResource({
  301. KeyWord: this.searchTxt.replace(/^\s+|\s+$/g, ""),
  302. PageSize: this.tabsActive == 1 ? 5 : "",
  303. });
  304. if (res.Ret === 200) {
  305. if (this.refresh) {
  306. uni.stopPullDownRefresh();
  307. this.refresh = false;
  308. }
  309. this.reportPageData = res.Data || {};
  310. if (res.Data.ListHzReport.length || res.Data.ListHzResource.length || res.Data.ListYxReport.length || res.Data.ListYxResource.length) {
  311. this.haveResultReport = true;
  312. } else {
  313. this.haveResultReport = false;
  314. }
  315. }
  316. },
  317. //点击了更多
  318. tabsActiveMore(val) {
  319. this.tabsActive = val;
  320. this.getListInit();
  321. this.getDataList();
  322. },
  323. //纪要、图标的筛选
  324. summarySelectHandler(item, type) {
  325. this.pageNum = 1;
  326. if (type == "纪要") {
  327. this.summarySelectActive = item.value;
  328. this.resultList = [];
  329. this.resultDataList = [];
  330. this.synthesiz();
  331. } else {
  332. this.activitySelectActive = item.value;
  333. this.collectList = [];
  334. this.getActivityBackList();
  335. }
  336. },
  337. /* 历史搜索清空 */
  338. clearHistory() {
  339. this.historySearchList = [];
  340. this.$db.del("historySearchList");
  341. },
  342. getListInit() {
  343. uni.pageScrollTo({
  344. scrollTop: 0,
  345. duration: 300,
  346. });
  347. this.pageNum = 1;
  348. this.pageSize = this.tabsActive == 1 ? 5 : 10;
  349. this.totalPage = 0;
  350. this.summarySelectActive = "Matching";
  351. this.activitySelectActive = "0";
  352. this.status = "loadmore";
  353. this.resultList = [];
  354. this.resultDataList = [];
  355. this.collectList = [];
  356. this.reportPageData = {};
  357. },
  358. },
  359. onLoad(options) {
  360. this.researchHotKeyWord();
  361. if (this.$db.get("historySearchList")) {
  362. this.historySearchList = JSON.parse(this.$db.get("historySearchList"));
  363. }
  364. },
  365. onShow() {},
  366. /* 下拉刷新 */
  367. onPullDownRefresh: Throttle(function () {
  368. this.page_no = 1;
  369. this.refresh = true;
  370. this.getDataList();
  371. }),
  372. // 上拉加载this.resultList
  373. onReachBottom: Throttle(function () {
  374. if (this.tabsActive == 1) return;
  375. if (this.status === "nomore") return;
  376. this.status = "loading";
  377. this.pageNum++;
  378. this.getDataList();
  379. }),
  380. };
  381. </script>
  382. <style lang="scss" scoped>
  383. .search-container {
  384. background-color: #f5f6fa;
  385. padding: 200rpx 0 0rpx;
  386. min-height: 100vh;
  387. box-sizing: border-box;
  388. .sticky-content {
  389. position: fixed;
  390. top: 0;
  391. left: 0;
  392. width: 100%;
  393. z-index: 99;
  394. background-color: #fff;
  395. }
  396. .searchTarget-header {
  397. padding: 0 34rpx;
  398. width: 100%;
  399. position: relative;
  400. padding: 30rpx 0;
  401. display: flex;
  402. justify-content: center;
  403. align-items: center;
  404. .sea_ipt_placeholder {
  405. color: #8d8d8d;
  406. }
  407. .sea_ipt {
  408. width: 682rpx;
  409. height: 70rpx;
  410. line-height: 70rpx;
  411. box-sizing: border-box;
  412. background: #f9f9f9;
  413. font-size: 26rpx;
  414. color: #4a4a4a;
  415. padding: 0 180rpx 0 78rpx;
  416. border-radius: 70rpx;
  417. }
  418. .sea_ico {
  419. width: 31rpx;
  420. height: 31rpx;
  421. position: absolute;
  422. left: 68rpx;
  423. top: 50%;
  424. transform: translateY(-50%);
  425. }
  426. .ipt-right {
  427. display: flex;
  428. align-items: center;
  429. position: absolute;
  430. right: 59rpx;
  431. top: 50%;
  432. transform: translateY(-50%);
  433. color: #3385ff;
  434. .line {
  435. margin: 0 21rpx;
  436. color: #e0e0e0;
  437. }
  438. }
  439. }
  440. .search-cont {
  441. padding: 32rpx;
  442. font-size: 24rpx;
  443. margin-top: -80rpx;
  444. color: #666666;
  445. background-color: #fff;
  446. height: calc(100vh - 135rpx);
  447. overflow: hidden;
  448. .title {
  449. font-size: 32rpx;
  450. font-weight: 500;
  451. color: #333333;
  452. }
  453. .history {
  454. height: 270rpx;
  455. .history-title {
  456. display: flex;
  457. align-items: center;
  458. justify-content: space-between;
  459. .empty_ico {
  460. width: 36rpx;
  461. height: 36rpx;
  462. }
  463. }
  464. .history-item {
  465. width: 100%;
  466. overflow: hidden;
  467. display: flex;
  468. flex-wrap: wrap;
  469. .item {
  470. background-color: #f9f9f9;
  471. padding: 10rpx 20rpx;
  472. margin: 20rpx 20rpx 0 0;
  473. border-radius: 4rpx;
  474. }
  475. }
  476. }
  477. }
  478. .search-tabs {
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. width: 100%;
  483. font-size: 32rpx;
  484. color: #333333;
  485. padding-left: 35rpx;
  486. overflow: hidden;
  487. overflow-x: auto;
  488. background-color: #fff;
  489. margin-bottom: 10rpx;
  490. .tabs-item {
  491. margin-right: 50rpx;
  492. flex-shrink: 0;
  493. padding-bottom: 10rpx;
  494. position: relative;
  495. .item-act {
  496. width: 80%;
  497. position: absolute;
  498. bottom: 0;
  499. left: 50%;
  500. transform: translateX(-50%);
  501. height: 4rpx;
  502. border-radius: 21px;
  503. background: linear-gradient(90deg, #2e85ff 0%, #7eeaf6 100%);
  504. }
  505. }
  506. .active {
  507. color: #4791ff;
  508. font-weight: 500;
  509. }
  510. }
  511. .content {
  512. width: 100%;
  513. background-color: #f5f6fa;
  514. }
  515. .nodata {
  516. font-size: 40rpx;
  517. .bind-mobile {
  518. width: 244rpx;
  519. height: 58rpx;
  520. background: #3385ff;
  521. border-radius: 8rpx;
  522. font-size: 28rpx;
  523. line-height: 58rpx;
  524. text-align: center;
  525. color: #fff;
  526. margin: 50rpx auto;
  527. }
  528. }
  529. .more-box {
  530. display: flex;
  531. height: 88rpx;
  532. padding: 0 30rpx;
  533. align-items: center;
  534. justify-content: space-between;
  535. font-size: 28rpx;
  536. background-color: #f5f6fa;
  537. position: sticky;
  538. left: 0;
  539. z-index: 99;
  540. .more-text {
  541. font-weight: 500;
  542. color: #333333;
  543. &::before {
  544. content: "";
  545. display: inline-block;
  546. height: 20rpx;
  547. width: 4rpx;
  548. background-color: #3189ff;
  549. margin-right: 20rpx;
  550. }
  551. }
  552. .more-rivet {
  553. color: #3385ff;
  554. margin-left: 20rpx;
  555. }
  556. }
  557. .summary-select {
  558. display: flex;
  559. align-items: center;
  560. width: 252rpx;
  561. background-color: #f9f9f9;
  562. color: #999999;
  563. font-size: 24rpx;
  564. height: 51rpx;
  565. border-radius: 47rpx;
  566. box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(0, 0, 0, 0.09);
  567. overflow: hidden;
  568. .select-item {
  569. display: flex;
  570. align-items: center;
  571. justify-content: center;
  572. width: 50%;
  573. height: 100%;
  574. border-radius: 47rpx;
  575. }
  576. .active-item {
  577. background-color: #3385ff;
  578. color: #fff;
  579. }
  580. }
  581. .activity-select {
  582. padding-right: 34rpx;
  583. height: 88rpx;
  584. position: sticky;
  585. top: 184rpx;
  586. left: 0;
  587. z-index: 99;
  588. background-color: #f5f6fa;
  589. }
  590. .more-summary {
  591. top: 184rpx;
  592. }
  593. .more-report {
  594. top: 184rpx;
  595. z-index: 100;
  596. }
  597. .more-activity {
  598. top: 184rpx;
  599. z-index: 101;
  600. }
  601. }
  602. </style>