search.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="search-container container">
  3. <view class="searchTarget-header">
  4. <input type="text" placeholder="请输入关键字" placeholder-class="sea_ipt_placeholder" class="sea_ipt" v-model="searchTxt" focus="true" confirm-type="search" @confirm="searchHandle" />
  5. <icon type="search" size="15" class="sea_ico" />
  6. <view class="ipt-right">
  7. <icon type="clear" size="16" color="#E0E0E0" v-show="searchTxt" @click="clearIpt" />
  8. <text class="line">|</text>
  9. <text @click="searchHandle" style="color: #3385ff">搜索</text>
  10. </view>
  11. </view>
  12. <view class="radio-content">
  13. <van-radio-group :value="radioSelect" @change="onChangeRadio" direction="horizontal">
  14. <van-radio icon-size="16" name="1">搜全部</van-radio>
  15. <van-radio icon-size="16" name="2">搜纪要</van-radio>
  16. <van-radio icon-size="16" name="3">搜图表</van-radio>
  17. </van-radio-group>
  18. </view>
  19. <view class="tab-cont">
  20. <scroll-view scroll-x="true" scroll-with-animation class="scroll-tab" :scroll-into-view="'_' + tabIndex">
  21. <block v-for="item in tabBars" :key="item.mode">
  22. <view class="scroll-tab-item" :class="{ active: orderColumn === item.mode }" @click.stop="toggleTab(item)">
  23. {{ item.PermissionName }}
  24. </view>
  25. </block>
  26. </scroll-view>
  27. </view>
  28. <view class="search-cont" v-if="!isResult">
  29. <view class="search-cont-top">
  30. <view class="cont-tit">
  31. <text>热搜关键词:</text>
  32. </view>
  33. <view class="targetList">
  34. <view class="target-item" v-for="(item, index) in hotKeyWord" :key="index" @click="chooseTarget(item.KeyWord)"># {{ item.KeyWord }}</view>
  35. </view>
  36. </view>
  37. <view class="search-cont-top">
  38. <view class="cont-tit">
  39. <text>弘则推荐:</text>
  40. </view>
  41. <view class="targetList">
  42. <view class="target-item" v-for="(item, index) in keywordList" :key="index" @click="chooseTarget(item)"># {{ item }}</view>
  43. </view>
  44. </view>
  45. <view class="search-cont-top" v-if="historySearchList.length">
  46. <view class="cont-tit">
  47. <text>搜索历史:</text>
  48. <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/empty_ico.png" class="empty_ico" @click="clearHistory"></image>
  49. </view>
  50. <view class="targetList">
  51. <block v-for="(item, index) in historySearchList" :key="index">
  52. <view v-if="index < 8" class="target-item" @click="chooseTarget(item)"># {{ item }}</view>
  53. </block>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 内容地方 -->
  58. <view class="search-cont" v-else>123 </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { Search } from "@/config/api.js";
  63. import { Debounce, Throttle } from "@/config/util.js";
  64. let app = getApp({ allowDefault: true });
  65. export default {
  66. data() {
  67. return {
  68. searchTxt: "", //搜索关键字
  69. isResult: false, //显示搜索结果
  70. haveResult: true, //是否有搜索数据
  71. // 历史搜索列表
  72. historySearchList: [],
  73. // 关键字列表
  74. keywordList: [],
  75. // 搜索结果列表
  76. resultList: [],
  77. indList: [],
  78. page_no: 1,
  79. pageSize: 10,
  80. totalPage: 0,
  81. hotKeyWord: [],
  82. radioSelect: "",
  83. tabBars: [
  84. {
  85. PermissionName: "匹配度排序",
  86. mode: "Matching",
  87. },
  88. {
  89. PermissionName: "综合排序",
  90. mode: "Comprehensive",
  91. },
  92. {
  93. PermissionName: "发布时间排序",
  94. mode: "PublishDate",
  95. },
  96. ],
  97. orderColumn: "Matching",
  98. };
  99. },
  100. watch: {
  101. searchTxt(newVal) {
  102. if (newVal.length <= 0) {
  103. this.isResult = false;
  104. }
  105. },
  106. },
  107. methods: {
  108. //获取热搜关键词的请求
  109. async researchHotKeyWord() {
  110. const res = await Research.researchHotKeyWord();
  111. if (res.Ret === 200) {
  112. this.hotKeyWord = res.Data.List || [];
  113. }
  114. },
  115. //点击了搜索的变化
  116. onChangeRadio(value) {
  117. this.radioSelect = value.detail;
  118. this.clearIpt();
  119. },
  120. /* 获取关键词 */
  121. getKeyWord() {
  122. Search.getKeys().then((res) => {
  123. if (res.Ret === 200) {
  124. this.keywordList = res.Data.Item.ConfigValue ? res.Data.Item.ConfigValue.split(",") : [];
  125. }
  126. });
  127. },
  128. // 选择历史搜索
  129. chooseTarget(item) {
  130. this.searchTxt = item;
  131. this.SecName = item;
  132. this.resultList = [];
  133. this.indList = [];
  134. if (!this.historySearchList.includes(this.searchTxt)) {
  135. this.historySearchList.unshift(this.searchTxt);
  136. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  137. }
  138. this.getDataList();
  139. },
  140. // 拼接
  141. join(str, key) {
  142. return str.replace(new RegExp(`${key}`, "g"), `%%${key}%%`).split("%%");
  143. },
  144. // 搜索数据
  145. searchHandle: Debounce(function () {
  146. if (this.searchTxt) {
  147. //添加搜索记录
  148. if (!this.historySearchList.includes(this.searchTxt)) {
  149. this.historySearchList.unshift(this.searchTxt);
  150. this.$db.set("historySearchList", JSON.stringify(this.historySearchList));
  151. }
  152. this.resultList = [];
  153. this.indList = [];
  154. this.getDataList();
  155. } else {
  156. this.$util.toast("请输入关键字");
  157. }
  158. }),
  159. // 查找数据
  160. async getDataList() {
  161. this.isResult = true;
  162. },
  163. /* 表单清空 */
  164. clearIpt() {
  165. this.searchTxt = "";
  166. this.isTabAct = false;
  167. },
  168. /* 历史搜索清空 */
  169. clearHistory() {
  170. this.historySearchList = [];
  171. this.$db.del("historySearchList");
  172. },
  173. //tabs切换事件
  174. toggleTab(item) {
  175. this.orderColumn = item.mode
  176. },
  177. },
  178. onLoad(options) {
  179. this.radioSelect = options.id == 31 ? "1" : "2";
  180. if (options.text) {
  181. this.searchTxt = options.text;
  182. this.getDataList();
  183. }
  184. // 获取历史搜索记录
  185. if (this.$db.get("historySearchList")) {
  186. let historyList = JSON.parse(this.$db.get("historySearchList"));
  187. this.historySearchList = historyList;
  188. }
  189. },
  190. onShow() {
  191. this.$store.dispatch("statistics", { PageType: "SummarySearch" });
  192. this.getKeyWord();
  193. // this.researchHotKeyWord();
  194. },
  195. };
  196. </script>
  197. <style lang="scss">
  198. .search-container {
  199. background-color: #fff;
  200. padding-bottom: 30rpx;
  201. .searchTarget-header {
  202. padding: 0 34rpx;
  203. width: 100%;
  204. background-color: #fff;
  205. position: sticky;
  206. top: 0;
  207. left: 0;
  208. z-index: 99;
  209. padding: 30rpx 0;
  210. display: flex;
  211. justify-content: center;
  212. align-items: center;
  213. .sea_ipt_placeholder {
  214. color: #8d8d8d;
  215. }
  216. .sea_ipt {
  217. width: 682rpx;
  218. height: 70rpx;
  219. line-height: 70rpx;
  220. box-sizing: border-box;
  221. border: 1rpx solid #e5e5e5;
  222. background-color: rgba(245, 245, 245, 0.2);
  223. font-size: 26rpx;
  224. color: #4a4a4a;
  225. padding: 0 180rpx 0 78rpx;
  226. border-radius: 70rpx;
  227. }
  228. .sea_ico {
  229. width: 31rpx;
  230. height: 31rpx;
  231. position: absolute;
  232. left: 68rpx;
  233. top: 50%;
  234. transform: translateY(-50%);
  235. }
  236. .ipt-right {
  237. display: flex;
  238. align-items: center;
  239. position: absolute;
  240. right: 59rpx;
  241. top: 50%;
  242. transform: translateY(-50%);
  243. color: #3385ff;
  244. .line {
  245. margin: 0 21rpx;
  246. color: #e0e0e0;
  247. }
  248. }
  249. }
  250. .radio-content {
  251. width: 100%;
  252. padding-left: 58rpx;
  253. background-color: #fff;
  254. position: sticky;
  255. height: 70rpx;
  256. top: 128rpx;
  257. left: 0;
  258. z-index: 99;
  259. display: flex;
  260. }
  261. .search-cont {
  262. .search-cont-top {
  263. padding: 0 34rpx 0;
  264. margin-bottom: 10rpx;
  265. padding-top: 20rpx;
  266. &:last-child {
  267. margin-bottom: 0;
  268. }
  269. .cont-tit {
  270. font-size: 32rpx;
  271. margin-bottom: 20rpx;
  272. font-weight: 500;
  273. display: flex;
  274. justify-content: space-between;
  275. .empty_ico {
  276. width: 32rpx;
  277. height: 33rpx;
  278. }
  279. }
  280. .targetList {
  281. display: flex;
  282. flex-wrap: wrap;
  283. font-size: 28rpx;
  284. .target-item {
  285. width: 50%;
  286. margin-bottom: 20rpx;
  287. }
  288. }
  289. }
  290. .result-cont {
  291. padding: 0 34rpx 0;
  292. padding-left: 21rpx;
  293. .result-list {
  294. display: flex;
  295. align-items: center;
  296. color: #333;
  297. padding-bottom: 30rpx;
  298. border-bottom: 1rpx solid #ebedf0;
  299. margin-bottom: 30rpx;
  300. .result_ico {
  301. width: 28rpx;
  302. height: 28rpx;
  303. margin-right: 20rpx;
  304. }
  305. text {
  306. display: inline;
  307. }
  308. .highlight {
  309. color: #3385ff;
  310. }
  311. }
  312. }
  313. .result-data {
  314. // margin-top: 80rpx;
  315. min-height: calc(100vh - 130rpx);
  316. padding: 20rpx 34rpx 40rpx;
  317. display: flex;
  318. background-color: #f7f7f7;
  319. }
  320. }
  321. .tab-cont {
  322. position: sticky;
  323. top: 128rpx;
  324. width: 100%;
  325. padding: 0 26rpx;
  326. background-color: #fff;
  327. font-size: 32rpx;
  328. .scroll-tab {
  329. width: 100%;
  330. white-space: nowrap;
  331. }
  332. .scroll-tab-item {
  333. text-align: center;
  334. display: inline-block;
  335. // padding: 0 8rpx 20rpx 8rpx;
  336. padding-bottom: 20rpx;
  337. margin-right: 40rpx;
  338. border-bottom: 8rpx solid transparent;
  339. position: relative;
  340. &:last-child {
  341. margin-right: 0;
  342. }
  343. &.active {
  344. border-bottom: none;
  345. color: #2c83ff;
  346. font-weight: 700;
  347. border-bottom: 2px solid;
  348. border-image: linear-gradient(to right, #2e85ff, #7eeaf6) 1;
  349. }
  350. .border_act {
  351. width: 100%;
  352. height: 8rpx;
  353. position: absolute;
  354. bottom: 0;
  355. left: 0;
  356. }
  357. }
  358. }
  359. }
  360. </style>