WholeStationSearch.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="autoBox box">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item :to="{ path: 'home' }">{{ $t('common.Home') }}</el-breadcrumb-item>
  6. <el-breadcrumb-item>{{ $t('common.SearchResults') }}</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <!-- <wordcloud
  10. :data="defaultWords"
  11. nameKey="name"
  12. valueKey="value"
  13. :color="myColors"
  14. :showTooltip="false"
  15. :wordClick="wordClickHandler">
  16. </wordcloud> -->
  17. <div style="margin-top: 70px;width: 100%;height: 50px;position: relative;">
  18. <el-autocomplete
  19. :placeholder="$t('common.EnterContent')"
  20. v-model="title" @change="onInput(title)"
  21. class="input-with-select" maxlength="50"
  22. show-word-limit
  23. :fetch-suggestions="querySearchAsync"
  24. @select="handleSelect"
  25. style="width: 650px;position: absolute;left: 50%;top: 0;transform: translateX(-50%);">
  26. <template slot-scope="{ item }">
  27. <div class="innerHead" v-if="item.value!=='暂无匹配内容'">
  28. <div>
  29. <p style="margin:0">
  30. <span v-html="item.nameStr"/>
  31. </p>
  32. </div>
  33. </div>
  34. <div v-else>
  35. <!--<span v-if="$i18n.locale=='zh'">暂无匹配内容</span>-->
  36. <!--<span v-if="$i18n.locale=='en'">No match is found</span>-->
  37. <span style="display: inline-block;">&nbsp;</span>
  38. </div>
  39. </template>
  40. <el-button class="cursor" slot="append" type="primary" @click="getSearchList()">
  41. {{ $t('common.Search') }}
  42. </el-button>
  43. </el-autocomplete>
  44. </div>
  45. <div style="margin: 20px 100px 0 100px;">
  46. <el-menu :default-active="activeIndex" class="el-menu-demo" style="font-size: 19px;" mode="horizontal"
  47. @select="handleSelect">
  48. <el-menu-item index="all">{{ $t('common.All') }}</el-menu-item>
  49. <el-menu-item index="project">{{ $t('common.Project') }}</el-menu-item>
  50. <el-menu-item index="member_unit">{{ $t('common.MemberUnit') }}</el-menu-item>
  51. <el-menu-item index="unit">{{ $t('common.Enterprise') }}</el-menu-item>
  52. <el-menu-item index="information">{{ $t('common.News') }}</el-menu-item>
  53. <el-menu-item index="activity">{{ $t('common.Events') }}</el-menu-item>
  54. <el-menu-item index="meeting">{{ $t('common.Conference') }}</el-menu-item>
  55. <el-menu-item index="journal">{{ $t('common.Publications') }}</el-menu-item>
  56. <el-menu-item index="country">{{ $t('common.Country') }}</el-menu-item>
  57. </el-menu>
  58. </div>
  59. <div style="margin: 20px 100px 0 100px;" v-show="true">
  60. {{ $t('common.CorrelationResult') }} <span style="color: #00cd63;">{{ searchData.totalCount }}</span>
  61. {{ $t('common.aResult') }}
  62. </div>
  63. <!-- <div style="margin-top: 30px;width: 100%;">
  64. <div>
  65. <div class="cursor" v-for="(item,index) in initData" @click=""
  66. style="padding:0 100px;margin-top:20px;">
  67. <p><span style="float: left;font-weight: 700;" v-html="item.title"></span></p>
  68. <p><span style="float: left;margin-right: 10px;">{{ item.content }}</span><br/></p>
  69. <p><span style="float: left;margin-right: 10px;">{{$t('common.LatestUpdateTime')}}:{{formatDate(item.createDate)}}</span></p><br>
  70. </div>
  71. </div>
  72. </div>
  73. </div>-->
  74. <div v-loading="loading" style="min-height:200px">
  75. <div class="cursor" v-for="(item,index) in initData" :key="index" @click="toViewNew(item)"
  76. style="padding:0 100px;margin-top:20px;">
  77. <div class="div1"><span style="font-weight: 700;" v-html="item.title"></span></div>
  78. <div class="div2">
  79. <!-- -webkit-box-orient: vertical; -->
  80. <!-- class="plate" -->
  81. <span v-html="item.content"
  82. style="line-height: 30px;color: #333;font-size: 14px;
  83. position:relative;
  84. overflow: hidden;
  85. display: inline-block;
  86. max-height:95px;"></span></div>
  87. <div class="div3">{{ $t('common.LatestUpdateTime') }}: {{ formatDate(item.update_date) }}</div>
  88. </div>
  89. </div>
  90. <div style="width: 100%;position: relative;height: 100px;">
  91. <el-pagination
  92. style="height: 80px;position: absolute;left: 50%;top: 100px;transform: translate(-50%,-50%);"
  93. background
  94. :index="indexMethod"
  95. layout="prev, pager, next"
  96. :page-size="pageSize"
  97. :current-page.sync="currentPage"
  98. :total="num-0"
  99. @current-change="handleCurrentChange"
  100. ></el-pagination>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import Bus from "@/api/bus"; //注意引入
  106. import {search} from "@/api/search";
  107. import request from '@/utils/request'
  108. import wordcloud from 'vue-wordcloud'
  109. import {getDcpSearchWordsBeforeLogin, getDcpSearchWordsAfterLogin} from "@/api/dataBroadcastInfos";
  110. import qs from 'qs'
  111. export default {
  112. name: 'WholeStationSearch',
  113. components: {wordcloud},
  114. data() {
  115. return {
  116. title: this.$route.query.input,// 搜索内容
  117. activeIndex: this.$route.query.select || 'all', // 搜索类型
  118. initData: [],
  119. searchData: [],
  120. currentPage: 1,
  121. loading: true,
  122. pageSize: 10,
  123. num: 0,
  124. myColors: ['#1f77b4', '#629fc9', '#94bedb', '#c9e0ef', '#000'],
  125. defaultWords: [{value: 100, name: "文字"},
  126. {value: 400, name: "图片"},
  127. {value: 333, name: "参考"},
  128. {value: 855, name: "音视频"},
  129. {value: 343, name: "新媒体"},
  130. {value: 343, name: "测试1"},
  131. {value: 43, name: "测试2"},
  132. {value: 543, name: "测试3"},
  133. {value: 333, name: "测试4"},
  134. {value: 323, name: "测试5"},
  135. {value: 33, name: "测试6"},
  136. {value: 13, name: "测试7"},
  137. {value: 543, name: "测试8"},
  138. {value: 66, name: "测试9"},
  139. {value: 666, name: "测试10"},
  140. ],
  141. restaurants: [],
  142. state: '',
  143. timeout: null
  144. }
  145. },
  146. created() {
  147. },
  148. watch: {
  149. '$i18n.locale'() {
  150. this.getSearchList();
  151. //区分登录与未登录的下拉框信息
  152. if (this.$Cookies.get('token')) {
  153. this.MygetDcpSearchWordsAfterLogin()
  154. } else {
  155. this.MygetDcpSearchWordsBeforeLogin();
  156. }
  157. },
  158. },
  159. mounted() {
  160. //区分登录与未登录的下拉框信息
  161. if (this.$Cookies.get('token')) {
  162. this.MygetDcpSearchWordsAfterLogin()
  163. } else {
  164. this.MygetDcpSearchWordsBeforeLogin();
  165. }
  166. this.getSearchList();
  167. },
  168. methods: {
  169. wordClickHandler(name, value, vm) {
  170. console.log('wordClickHandler', name, value, vm);
  171. },
  172. onInput(title) {
  173. this.$forceUpdate(title);
  174. this.getSearchList();
  175. },
  176. //获取搜索数据
  177. getSearchList() {
  178. var activeId = this.activeIndex;
  179. if (this.activeIndex == 'all') {
  180. activeId = 'project,unit,member_unit,information,activity,meeting,journal,country';
  181. }
  182. this.initData = [];
  183. this.loading = true;
  184. search(activeId, {
  185. pageNo: this.pageNo,
  186. keyword: this.title,
  187. pageSize: this.pageSize,
  188. language: this.$i18n.locale
  189. }).then(res => {
  190. if (res.data) {
  191. debugger
  192. this.searchData = res.data;
  193. this.num = res.data.totalCount;
  194. this.initData = res.data.list;
  195. this.loading = false;
  196. }
  197. })
  198. },
  199. handleSelect(key, keyPath) {
  200. console.log(key, keyPath);
  201. this.activeIndex = key;
  202. this.pageNo = 1;
  203. this.currentPage = 1;
  204. this.handleCurrentChange(1);
  205. this.getSearchList();
  206. },
  207. //跳到一个新的页面
  208. toViewNew(json) {
  209. //跳转路径名
  210. var router;
  211. //请求参数
  212. const reqParams = {};
  213. //判断是否为项目
  214. if (json.index == 'project') {
  215. router = 'projectPresentationDetails';
  216. reqParams.name = router,
  217. reqParams.query = {
  218. key: json.base_entity_id,
  219. screenId: 0,
  220. dataIndex: 0,
  221. cruPage: 1,
  222. };
  223. }
  224. //判断是否为企业
  225. else if (json.index == 'unit') {
  226. router = 'enterpriseDetails';
  227. reqParams.name = router,
  228. reqParams.query = {key: json.base_entity_id};
  229. }
  230. //判断是否为资讯
  231. else if (json.index == 'information') {
  232. router = 'realTimeInfoItemdetails';
  233. reqParams.name = router,
  234. reqParams.query = {key: json.base_entity_id};
  235. }
  236. //判断是否为活动
  237. else if (json.index == 'activity') {
  238. router = 'cooperationExchangeListDetails';
  239. reqParams.name = router,
  240. reqParams.query = {key: json.base_entity_id};
  241. }
  242. //判断是否为会议
  243. else if (json.index == 'meeting') {
  244. //存在未开始,已结束的会议
  245. if (json.meeting_is_enroll == '01') {
  246. router = 'ConferenceDetail';
  247. reqParams.name = router,
  248. reqParams.query = {key: json.id};
  249. // debugger
  250. } else {
  251. router = 'ConferenceResult';
  252. reqParams.name = router,
  253. reqParams.query = {key: json.id};
  254. }
  255. }
  256. //判断是否为期刊
  257. else if (json.index == 'journal') {
  258. //期刊数据是url链接
  259. router = 'RealTimeInfoJournaldetails';
  260. window.open(json.link, '_blank');
  261. return;
  262. }
  263. //判断是否为国别
  264. else if (json.index == 'country') {
  265. router = 'countryNationalSpace';
  266. reqParams.name = router
  267. reqParams.query = {key: json.base_entity_id};
  268. }
  269. //判断是否为会员单位
  270. else if (json.index == 'member_unit') {
  271. router = 'IntroductionPresentationDetails';
  272. reqParams.name = router
  273. reqParams.query = {
  274. key: json.id,
  275. // key: '3641f9b2e90111eaa9a3e454e8b99384',
  276. member: JSON.stringify({
  277. memberNameZh: json.member_name_zh,
  278. memberNameEn: json.member_name_en,
  279. unitId: json.unit_id,
  280. // memberNameZh: '恒星太阳能公司',
  281. // memberNameEn: 'SunPower by Stellar Solar',
  282. // unitId: '33c097e3e91411eaa9a3e454e8b99384',
  283. })
  284. };
  285. console.log(json)
  286. console.log(reqParams)
  287. }
  288. this.$store.commit('modify', router);
  289. window.localStorage.setItem('router', router);
  290. console.log(reqParams)
  291. const {href} = this.$router.resolve(
  292. reqParams
  293. );
  294. window.open(href, '_blank');
  295. },
  296. handleCurrentChange(val) {
  297. this.pageNo = val;
  298. this.getSearchList();
  299. },
  300. //分页索引接着上一页的索引
  301. indexMethod(index) {
  302. return (this.page - 1) * 10 + index + 1;
  303. },
  304. MygetDcpSearchWordsBeforeLogin() {
  305. getDcpSearchWordsBeforeLogin(this.$i18n.locale).then((res) => {
  306. this.restaurants = res.data.dcpSearchWordsBeforeLogin;
  307. // this.restaurants = this.loadAll();
  308. var arr = [];
  309. res.data.dcpSearchWordsBeforeLogin.forEach(element => {
  310. arr.push({"value": element.searchWordsName})
  311. });
  312. this.restaurants = arr;
  313. })
  314. },
  315. MygetDcpSearchWordsAfterLogin() {
  316. getDcpSearchWordsAfterLogin().then((res) => {
  317. var arr = [];
  318. res.data.dcpSearchWordsAfterLogin.forEach(element => {
  319. arr.push({"value": element.searchName})
  320. });
  321. this.restaurants = arr;
  322. })
  323. },
  324. // querySearchAsync(queryString, cb) {
  325. // var restaurants = this.restaurants;
  326. // var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
  327. // clearTimeout(this.timeout);
  328. // this.timeout = setTimeout(() => {
  329. // cb(results);
  330. // }, 500 * Math.random());
  331. // },
  332. querySearchAsync(queryString, cb) {
  333. var restaurants = this.restaurants;
  334. var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
  335. clearTimeout(this.timeout);
  336. this.timeout = setTimeout(() => {
  337. results = results.map(res => {
  338. res.nameStr = res.value.replace(queryString, `<span style="color: red;">${queryString}</span>`)
  339. return res
  340. })
  341. if (results.length === 0) {
  342. results[0] = {
  343. value: '暂无匹配内容'
  344. }
  345. }
  346. console.log(results);
  347. cb(results);
  348. }, 500 * Math.random());
  349. },
  350. createStateFilter(queryString) {
  351. return (state) => {
  352. return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  353. };
  354. },
  355. // handleSelect(item) {
  356. // console.log('我的------------',item);
  357. // }
  358. }
  359. }
  360. </script>
  361. <style scoped>
  362. .box {
  363. margin-top: 10px;
  364. background: #fff;
  365. /* height: 500px; */
  366. padding: 20px 0;
  367. }
  368. .crumbs {
  369. margin-left: 20px;
  370. }
  371. .el-menu-item {
  372. font-size: 18px;
  373. }
  374. .div1 {
  375. font-size: 20px;
  376. font-family: HiraginoSansGB-W3, HiraginoSansGB;
  377. font-weight: normal;
  378. line-height: 30px;
  379. }
  380. .div2 {
  381. font-size: 18px;
  382. font-family: HiraginoSansGB-W3, HiraginoSansGB;
  383. font-weight: normal;
  384. color: #666666;
  385. line-height: 32px;
  386. }
  387. .div3 {
  388. font-size: 16px;
  389. font-family: HiraginoSansGB-W3, HiraginoSansGB;
  390. font-weight: normal;
  391. color: #999999;
  392. line-height: 30px;
  393. }
  394. </style>