searchNew.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div>
  3. <div class="box1">
  4. <div class="box2">
  5. <div class="title">
  6. <!-- <div class="statistics">-->
  7. <!-- {{ $t('common.Searchin')}}-->
  8. <!-- <span> {{informationTotal}} </span>-->
  9. <!-- {{ $t('common.SearchInInformation')}}-->
  10. <!-- </div>-->
  11. <div class="input-box">
  12. <el-autocomplete
  13. class="input-with-select"
  14. :placeholder="$t('common.LookingSearch')"
  15. maxlength="50"
  16. show-word-limit
  17. @keyup.enter.native="toView('WholeStationSearch',select,homeInput)"
  18. v-model="homeInput"
  19. :fetch-suggestions="querySearchAsync"
  20. @select="handleSelect"
  21. >
  22. <template slot-scope="{ item }">
  23. <div class="innerHead" v-if="item.value!=='暂无匹配内容'">
  24. <div>
  25. <p>
  26. <span v-html="item.nameStr"/>
  27. </p>
  28. </div>
  29. </div>
  30. <div v-else>
  31. <!--<span v-if="$i18n.locale=='zh'">暂无匹配内容</span>
  32. <span v-if="$i18n.locale=='en'">No match is found</span> -->
  33. <span style="display: inline-block;">&nbsp;</span>
  34. </div>
  35. </template>
  36. <el-select v-model="select" slot="prepend" style="text-align: center !important;">
  37. <el-option class="beforecontent" :label="$t('common.WholeStation')" value="all"></el-option>
  38. <el-option class="beforecontent" :label="$t('common.Project')" value="project"></el-option>
  39. <el-option class="beforecontent" :label="$t('common.MemberUnit')" value="member_unit"></el-option>
  40. <el-option class="beforecontent" :label="$t('common.Enterprise')" value="unit"></el-option>
  41. <el-option class="beforecontent" :label="$t('common.News')" value="information"></el-option>
  42. <el-option class="beforecontent" :label="$t('common.Events')" value="activity"></el-option>
  43. <el-option class="beforecontent" :label="$t('common.Conference')" value="meeting"></el-option>
  44. <el-option class="beforecontent" :label="$t('common.Publications')" value="journal"></el-option>
  45. <el-option class="beforecontent" :label="$t('common.Country')" value="country"></el-option>
  46. </el-select>
  47. <!-- <el-button slot="append" >搜索</el-button> -->
  48. <!-- <template slot="prepend">{{serch}}</template> -->
  49. </el-autocomplete>
  50. <!-- <ul class="quick-search-list">-->
  51. <!-- <li v-for="(item,index) in hotSerch" @click="toView('WholeStationSearch',select,item.label,2)">-->
  52. <!-- {{$t(item.label)}}-->
  53. <!-- </li>-->
  54. <!-- </ul>-->
  55. </div>
  56. <el-button type="warning" @click="toView('WholeStationSearch',select,homeInput)">{{$i18n.locale=='en'? 'Search': '搜索'}}</el-button>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import Bus from "@/api/bus"; //注意引入
  64. import { getDcpSearchWordsBeforeLogin,getDcpSearchWordsAfterLogin } from "@/api/dataBroadcastInfos";
  65. export default {
  66. name: "Search",
  67. data() {
  68. return {
  69. title: "项目资源",
  70. serch: "项目",
  71. select: "all",
  72. homeInput: "",
  73. placeHolder: "",
  74. label: "",
  75. hotSerch:[{
  76. label:'common.cleanenergy'
  77. },{
  78. label:'common.Smartgrid'
  79. },{
  80. label:'common.Energystorage'
  81. },{
  82. label:'common.UHV'
  83. },{
  84. label:'common.GEI'
  85. }],
  86. restaurants: [],
  87. state: '',
  88. timeout: null
  89. };
  90. },
  91. watch: {
  92. "$i18n.locale"() {
  93. //区分登录与未登录的下拉框信息
  94. if(this.$Cookies.get('token')){
  95. this.MygetDcpSearchWordsAfterLogin()
  96. }else{
  97. this.MygetDcpSearchWordsBeforeLogin();
  98. }
  99. },
  100. videoUrl: function (val) {
  101. // const myPlayer = this.$refs.videoPlayer.player
  102. if (val !== "") {
  103. this.$refs.videoPlayer.player.src(val);
  104. }
  105. },
  106. state: function (val) {
  107. if (val) {
  108. this.$refs.videoPlayer.player.pause();
  109. }
  110. },
  111. },
  112. created() {
  113. // this.lookingChange();
  114. Bus.$on("title", (val) => {
  115. this.title = val.label;
  116. });
  117. Bus.$on("serch", (val) => {
  118. this.serch = val.label;
  119. });
  120. // let that = this;
  121. // document.onkeypress = (e) =>{
  122. // var keycode = document.all ? event.keyCode : e.which;
  123. // if (keycode == 13) {
  124. // that.toView('WholeStationSearch',that.select,that.homeInput)
  125. // return false;
  126. // }
  127. // };
  128. //区分登录与未登录的下拉框信息
  129. if(this.$Cookies.get('token')){
  130. this.MygetDcpSearchWordsAfterLogin()
  131. }else{
  132. this.MygetDcpSearchWordsBeforeLogin();
  133. }
  134. },
  135. props: {
  136. informationTotal: {
  137. type: String,
  138. default: "",
  139. },
  140. },
  141. methods: {
  142. // lookingChange(){
  143. // this.placeHolder=$t('common.LookingSearch');
  144. // }
  145. toView(router, select, input,num) {
  146. if(num){
  147. input=this.$t(input);
  148. }
  149. if (!input) {
  150. this.$message({
  151. message: this.$t("common.Theinputboxcannotbeempty"),
  152. type: "warning",
  153. });
  154. } else {
  155. this.$store.commit("modify", router);
  156. window.localStorage.setItem("router", router);
  157. const { href } = this.$router.resolve({
  158. name: router,
  159. query: {
  160. select: select,
  161. input: input,
  162. },
  163. });
  164. window.open(href, "_blank");
  165. }
  166. },
  167. MygetDcpSearchWordsBeforeLogin(){
  168. getDcpSearchWordsBeforeLogin(this.$i18n.locale).then((res)=>{
  169. this.restaurants = res.data.dcpSearchWordsBeforeLogin;
  170. // this.restaurants = this.loadAll();
  171. var arr = [];
  172. res.data.dcpSearchWordsBeforeLogin.forEach(element => {
  173. arr.push({"value":element.searchWordsName})
  174. });
  175. this.restaurants = arr;
  176. })
  177. },
  178. MygetDcpSearchWordsAfterLogin(){
  179. getDcpSearchWordsAfterLogin().then((res)=>{
  180. var arr = [];
  181. res.data.dcpSearchWordsAfterLogin.forEach(element => {
  182. arr.push({"value":element.searchName})
  183. });
  184. this.restaurants = arr;
  185. })
  186. },
  187. // querySearchAsync(queryString, cb) {
  188. // var restaurants = this.restaurants;
  189. // var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
  190. // clearTimeout(this.timeout);
  191. // this.timeout = setTimeout(() => {
  192. // cb(results);
  193. // }, 500 * Math.random());
  194. // console.log('111111111111111111',queryString)
  195. // },
  196. querySearchAsync(queryString, cb) {
  197. var restaurants = this.restaurants;
  198. var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
  199. clearTimeout(this.timeout);
  200. this.timeout = setTimeout(() => {
  201. results = results.map(res => {
  202. res.nameStr = res.value.replace(queryString, `<span style="color: red;">${queryString}</span>`)
  203. return res
  204. })
  205. if (results.length === 0) {
  206. results[0] = {
  207. value: '暂无匹配内容'
  208. }
  209. }
  210. console.log(results);
  211. cb(results);
  212. }, 500 * Math.random());
  213. },
  214. createStateFilter(queryString) {
  215. return (state) => {
  216. return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  217. };
  218. },
  219. handleSelect(item) {
  220. this.toView('WholeStationSearch',this.select,item.value)
  221. }
  222. },
  223. };
  224. </script>
  225. <!-- Add "scoped" attribute to limit CSS to this component only -->
  226. <style scoped>
  227. *{
  228. box-sizing: border-box;
  229. padding: 0;
  230. margin: 0;
  231. }
  232. .box1 {
  233. width:100%;
  234. background: #0E4891;
  235. height: 60px;
  236. }
  237. .box2 {
  238. width: 1180px;
  239. margin: 0 auto;
  240. padding-top: 11px;
  241. }
  242. .box1 .title {
  243. font-size: 15px;
  244. font-weight: 700;
  245. height: 50px;
  246. line-height: 50px;
  247. color: #666;
  248. width: 1180px;
  249. display: flex;
  250. margin-top: 2px;
  251. }
  252. .box1 .statistics{
  253. font-size: 16px;
  254. font-weight: 600;
  255. color: #FFFFFF;
  256. line-height: 40px;
  257. }
  258. .box1 .statistics span{
  259. font-size: 24px;
  260. color: #FFAA05;
  261. }
  262. .box1 .input-box{
  263. flex: 1;
  264. margin: 0 10px 0 20px;
  265. margin-top: -8px;
  266. }
  267. .box1 >>> .el-input--suffix .el-input__inner {
  268. text-align: center;
  269. }
  270. .box2>>>.el-input__inner {
  271. height: 36px;
  272. }
  273. .box1 .title >>> .el-input-group__prepend {
  274. width: 70px;
  275. background: #fff;
  276. font-size: 16px;
  277. font-weight: bold;
  278. color: #2573E0;
  279. line-height: 22px;
  280. }
  281. .box1 >>>.el-button{
  282. height: 36px;
  283. width: 80px;
  284. font-size: 16px;
  285. }
  286. .box1 .header1 >>> .el-input-group__prepend {
  287. background-color: #fff;
  288. color: #000;
  289. }
  290. .box1 .title >>> .el-input-group {
  291. border-radius: 20px;
  292. }
  293. .quick-search-list{
  294. font-size: 12px;
  295. color: #fff;
  296. line-height: 26px;
  297. margin-left: 87px;
  298. }
  299. .quick-search-list li{
  300. display: inline-block;
  301. margin-right: 20px;
  302. cursor: pointer;
  303. }
  304. .quick-search-list li:hover{
  305. color: #dd531b;
  306. }
  307. .beforecontent {
  308. padding-left: 20px;
  309. }
  310. .el-autocomplete{
  311. width: 100%;
  312. }
  313. </style>