SldHomeTopSearch.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <template>
  2. <div class="sld_home_top_search container">
  3. <div class="ld sld_home_top_search_left">
  4. <a href="javascript:void(0)" class="sld_logo_wrap flex_row_start_center" @click="go_home">
  5. <img :src="filtersStore.getSiteLogo" />
  6. </a>
  7. </div>
  8. <div class="sld_seach_wrap">
  9. <div class="sld_seach_box ld">
  10. <div class="form" @submit.prevent>
  11. <input
  12. v-model="keyword"
  13. type="text"
  14. class="text"
  15. autocomplete="off"
  16. :placeholder="L['请输入关键词']"
  17. @keyup.enter="search"
  18. ref="searchInput"
  19. @focus="inputFocus"
  20. @input="inputChange"
  21. @blur="inputBlur"
  22. />
  23. <input type="submit" :value="L['搜索']" class="button" @click="search" />
  24. </div>
  25. <div class="hot_search_wrap">
  26. <div>
  27. <template v-for="(item, index) in hotList.data" :key="index">
  28. <a
  29. href="javascript:void(0)"
  30. @click="quickSearch(index, 'quick')"
  31. :title="tmpHotList[index]"
  32. >{{ item }}</a
  33. >
  34. </template>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="search_association" id="searchA" v-show="SAList.length && SAShow">
  39. <div
  40. class="s_a_item"
  41. v-for="(item, index) in SAList"
  42. @mousedown="quickSearch(item.wordsContent, 'associ')"
  43. >
  44. <!-- 因为click事件与blur事件冲突,blur事件优先,于是换成mousedown -->
  45. <div>{{ item.wordsContent }}</div>
  46. <div>{{ item.searchGoodsNum }} {{L['个商品']}}</div>
  47. </div>
  48. </div>
  49. </div>
  50. <div v-if="searchBarFixed" class="container_header">
  51. <div class="container_header_box flex_row_start_center">
  52. <div class="sld_cart_wrap fixed_sld_cart_wrap">
  53. <nuxt-link tag="a" class="sld_logo_wrap flex_row_start_center" :to="`/`">
  54. <img :src="filtersStore.getSiteLogo" />
  55. </nuxt-link>
  56. </div>
  57. <div class="sld_seach_wrap" style="margin-right: 90px">
  58. <div class="sld_seach_box ld">
  59. <div class="form">
  60. <input
  61. v-model="keyword"
  62. type="text"
  63. class="text"
  64. autocomplete="off"
  65. style="color: rgb(153, 153, 153)"
  66. :placeholder="L['请输入关键词']"
  67. ref="searchInput"
  68. @focus="inputFocus"
  69. />
  70. <input type=" submit" :value="L['搜索']" class="button" @click="search" />
  71. </div>
  72. </div>
  73. </div>
  74. <div class="sld_cart_wrap">
  75. <dl class>
  76. <dt
  77. class="ld cart_icon_text_wrap"
  78. >
  79. <img src="/email.svg" />
  80. <nuxt-link target="_self" :to="`/home/contact`">{{
  81. L["发布需求"]
  82. }}</nuxt-link>
  83. </dt>
  84. </dl>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="sld_cart_wrap">
  89. <dl class>
  90. <nuxt-link target="_self" :to="`/home/contact`">
  91. <dt
  92. class="ld cart_icon_text_wrap"
  93. >
  94. <img src="/email.svg" />
  95. <span>{{ L["发布需求"] }}</span>
  96. </dt>
  97. </nuxt-link>
  98. </dl>
  99. </div>
  100. </div>
  101. </template>
  102. <script setup>
  103. // import { lang_zn } from "@/assets/language/zh.js";
  104. import { getCurLanguage } from '@/composables/common.js';
  105. import { useFiltersStore } from '@/store/filter.js'
  106. import {ref} from "vue";
  107. const filtersStore = useFiltersStore()
  108. // const L = lang_zn;
  109. const L = getCurLanguage();
  110. const { proxy } = getCurrentInstance();
  111. const searchBarFixed = ref(false);
  112. const hotList = reactive({ data: [] }); //热门搜索词列表
  113. const tmpHotList = ref([]);
  114. const SAList = ref([]);
  115. const SAShow = ref(false);
  116. const router = useRouter();
  117. const route = useRoute();
  118. const keyword = ref(calcMallUrlKeyword(route.path))
  119. const go_home = () => {
  120. window.location.href="/"
  121. };
  122. const getInitData = async () => {
  123. const {data:res} = await useFetch(apiUrl + "v3/system/front/setting/getSettings?names=hot_search_words,gz_code");
  124. if(res._rawValue.state == 200){
  125. hotList.data = res._rawValue.data
  126. let tmp_data = hotList.data[0] ? hotList.data[0].split(",").filter((i) => i != "") : [];
  127. tmpHotList.value = tmp_data;
  128. hotList.data = tmp_data;
  129. hotList.data = hotList.data.map((key) => {
  130. if (key.length > 20) {
  131. return key.substring(0, 20) + "...";
  132. } else {
  133. return key;
  134. }
  135. });
  136. }
  137. }
  138. getInitData()
  139. //搜索事件
  140. const search = () => {
  141. proxy.$refs.searchInput.style.color = "rgb(153,153,153)";
  142. if (keyword.value) {
  143. router.push({
  144. path: `/goods/list/search_keyword-`+keyword.value,
  145. });
  146. }
  147. };
  148. const searchAssociation = (input) => {
  149. get("v3/goods/front/goods/searchWords/list", {
  150. keyWord: input,
  151. }).then((res) => {
  152. if (res.state == 200) {
  153. SAList.value = res.data;
  154. }
  155. });
  156. };
  157. const inputChange = (e) => {
  158. let input = e.target.value.trim();
  159. SAShow.value = true;
  160. if (input) {
  161. searchAssociation(input);
  162. } else {
  163. SAList.value = [];
  164. }
  165. };
  166. //热门搜索事件
  167. const quickSearch = (val, type) => {
  168. if (type == "quick") {
  169. router.push({
  170. path: `/goods/list/search_keyword-`+tmpHotList.value[val],
  171. });
  172. } else {
  173. if (val == keyword.value) {
  174. keyword.value = val;
  175. } else {
  176. router.push({
  177. path: `/goods/list/search_keyword-`+val,
  178. });
  179. }
  180. }
  181. };
  182. const inputFocus = () => {
  183. proxy.$refs.searchInput.style.color = "#333";
  184. SAShow.value = true;
  185. if (keyword.value && SAList.value.length == 0) {
  186. searchAssociation(keyword.value);
  187. }
  188. };
  189. const inputBlur = () => {
  190. SAShow.value = false;
  191. };
  192. //滚动事件
  193. if (process.client) {
  194. const handleScroll = () => {
  195. var height = 600;
  196. var scrollTop =
  197. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  198. if (scrollTop > height) {
  199. searchBarFixed.value = true;
  200. } else {
  201. searchBarFixed.value = false;
  202. }
  203. };
  204. window.addEventListener("scroll", handleScroll);
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. a:active,
  209. a:visited {
  210. color: #333;
  211. }
  212. .sld_home_top_search {
  213. height: 80px;
  214. position: relative;
  215. z-index: 12;
  216. width: 1210px;
  217. margin: 0 auto 0px;
  218. padding-left: 0px;
  219. padding-right: 0px;
  220. display: flex;
  221. align-items: center;
  222. border-bottom: 1px solid #dbdbdb;
  223. margin-bottom: 10px;
  224. .container_header {
  225. width: 100%;
  226. position: fixed;
  227. background-color: #fff;
  228. left: 0;
  229. right: 0;
  230. top: 0;
  231. z-index: 999;
  232. border-bottom: 2px solid $colorMain;
  233. .sld_seach_wrap,
  234. .sld_cart_wrap {
  235. margin: 5px;
  236. position: relative;
  237. }
  238. .container_header_box {
  239. width: 1200px;
  240. margin: 0 auto;
  241. >div:last-child{
  242. width: 400px;
  243. }
  244. .fixed_sld_cart_wrap {
  245. margin-right: 120px;
  246. a {
  247. width: 100%;
  248. height: 100%;
  249. img {
  250. max-width: 100%;
  251. max-height: 100%;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. .container_header {
  258. -webkit-animation: searchTop 0.5s ease-in-out;
  259. animation: searchTop 0.5s ease-in-out;
  260. }
  261. @-webkit-keyframes searchTop {
  262. 0% {
  263. top: -50px;
  264. }
  265. to {
  266. top: 0;
  267. }
  268. }
  269. @keyframes searchTop {
  270. 0% {
  271. top: -50px;
  272. }
  273. to {
  274. top: 0;
  275. }
  276. }
  277. &:before {
  278. display: table;
  279. content: " ";
  280. }
  281. .sld_home_top_search_left {
  282. position: relative;
  283. flex:0 0 250px;
  284. .sld_logo_wrap {
  285. img {
  286. max-width: 144px;
  287. max-height: 100%;
  288. }
  289. }
  290. }
  291. .sld_seach_wrap {
  292. flex: auto;
  293. padding-top: 4px;
  294. position: relative;
  295. .sld_seach_box {
  296. z-index: 11;
  297. height: 38px;
  298. border: 2px solid $colorMain;
  299. .form {
  300. background-color: $colorMain;
  301. height: 34px;
  302. overflow: hidden;
  303. .text {
  304. height: 36px;
  305. background-color: #fff;
  306. width: calc(100% - 103px);
  307. -webkit-appearance: none;
  308. -webkit-border-radius: 0;
  309. height: 34px;
  310. color: rgb(153, 153, 153);
  311. padding: 5px 5px 5px 10px;
  312. background-position: 0 -360px;
  313. background-color: #fff;
  314. background-repeat: repeat-x;
  315. line-height: 20px;
  316. font-family: arial, "\5b8b\4f53";
  317. font-size: 12px;
  318. outline: none;
  319. border: none;
  320. }
  321. input {
  322. margin: 0;
  323. padding: 0;
  324. height: 34px;
  325. border: 0;
  326. }
  327. input::placeholder {
  328. font-size: 12px;
  329. /*font-family: Microsoft YaHei;*/
  330. font-weight: 400;
  331. color: rgb(153, 153, 153);
  332. }
  333. ::-webkit-input-placeholder {
  334. margin-left: 20px;
  335. font-size: 12px;
  336. /*font-family: Microsoft YaHei;*/
  337. font-weight: 400;
  338. color: rgb(153, 153, 153);
  339. }
  340. /* 使用webkit内核的浏览器 */
  341. :-moz-placeholder {
  342. font-size: 12px;
  343. /*font-family: Microsoft YaHei;*/
  344. font-weight: 400;
  345. color: rgb(153, 153, 153);
  346. }
  347. /* Firefox版本19+ */
  348. :-ms-input-placeholder {
  349. font-size: 12px;
  350. /*font-family: Microsoft YaHei;*/
  351. font-weight: 400;
  352. color: rgb(153, 153, 153);
  353. }
  354. /* IE浏览器 */
  355. .button {
  356. width: 103px;
  357. background: $colorMain;
  358. font-size: 16px;
  359. font-weight: 600;
  360. color: #fff;
  361. float: right;
  362. cursor: pointer;
  363. text-align: center;
  364. }
  365. }
  366. .hot_search_wrap {
  367. height: 30px;
  368. line-height: 30px;
  369. color: #999;
  370. overflow: hidden;
  371. strong {
  372. float: left;
  373. font-weight: 400;
  374. }
  375. a {
  376. color: #666;
  377. white-space: nowrap;
  378. overflow: hidden;
  379. text-overflow: ellipsis;
  380. word-break: break-all;
  381. &:link,
  382. &:visited {
  383. float: left;
  384. margin-right: 10px;
  385. }
  386. &:hover {
  387. color: $colorMain;
  388. }
  389. }
  390. }
  391. }
  392. .search_association {
  393. background: #fff;
  394. position: absolute;
  395. top: 43px;
  396. overflow: hidden;
  397. position: absolute;
  398. left: 0;
  399. width: 580px;
  400. border: 1px solid #ccc;
  401. background: #fff;
  402. z-index: 99;
  403. .s_a_item {
  404. display: flex;
  405. justify-content: space-between;
  406. overflow: hidden;
  407. padding: 1px 5px;
  408. line-height: 24px;
  409. cursor: pointer;
  410. font-size: 12px;
  411. -webkit-font-smoothing: antialiased;
  412. color: #666;
  413. div:first-child {
  414. width: 250px;
  415. white-space: nowrap;
  416. text-overflow: ellipsis;
  417. overflow: hidden;
  418. }
  419. div:last-child {
  420. overflow: hidden;
  421. color: #aaa;
  422. }
  423. &:hover {
  424. background-color: rgb(255, 233, 188);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. .sld_cart_wrap {
  431. position: relative;
  432. z-index: 99;
  433. height: 40px;
  434. flex: 0 0 240px;
  435. text-align: center;
  436. dl {
  437. margin-bottom: 0px;
  438. .cart_goods_num {
  439. font: 11px/16px Verdana;
  440. color: #fff;
  441. background: $colorMain;
  442. text-align: center;
  443. display: inline-block;
  444. height: 16px;
  445. min-width: 16px;
  446. border: none 0;
  447. border-radius: 8px;
  448. margin-left: 10px;
  449. }
  450. dt {
  451. position: absolute;
  452. z-index: 3;
  453. width: 100%;
  454. height: 38px;
  455. cursor: pointer;
  456. font-weight: 400;
  457. line-height: 38px;
  458. padding: 0;
  459. color: $colorMain;
  460. font-size: 15px;
  461. img {
  462. margin: -2px 11px 0 0px;
  463. vertical-align: middle;
  464. width: 16px;
  465. }
  466. &.cart_icon_text_wrap {
  467. a {
  468. color: #666666;
  469. font-size: 15px;
  470. line-height: 36px;
  471. }
  472. }
  473. }
  474. dd {
  475. .cart_goods {
  476. dl {
  477. padding-top: 8px;
  478. }
  479. dd {
  480. &.cart_goods_price {
  481. position: static;
  482. em {
  483. margin-right: 6px;
  484. width: auto;
  485. color: #666;
  486. &:nth-child(1) {
  487. display: block;
  488. font-weight: 600;
  489. }
  490. &:nth-child(2) {
  491. display: block;
  492. text-align: right;
  493. margin-top: 6px;
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. dd {
  502. position: absolute;
  503. top: 37px;
  504. right: 0;
  505. width: 355px;
  506. border: 1px solid #e3e3e3;
  507. background: #fff;
  508. z-index: 1;
  509. }
  510. }
  511. .ld {
  512. position: relative;
  513. zoom: 1;
  514. }
  515. .cart_data {
  516. height: 300px;
  517. display: flex;
  518. flex-direction: column;
  519. position: relative;
  520. .cart_data_title {
  521. font-weight: 600;
  522. float: left;
  523. padding: 7px;
  524. line-height: 32px;
  525. height: 32px;
  526. }
  527. .cart_list {
  528. padding: 20px;
  529. overflow-y: scroll;
  530. .cart_list_pre {
  531. margin-bottom: 20px;
  532. .cart_pre_left {
  533. .cart_pre_img {
  534. width: 48px;
  535. height: 48px;
  536. border: 1px solid #e3e3e3;
  537. cursor: pointer;
  538. img {
  539. width: 100%;
  540. height: 100%;
  541. }
  542. }
  543. .cart_pre_cen {
  544. width: 150px;
  545. margin-left: 20px;
  546. cursor: pointer;
  547. .cart_pre_name {
  548. word-break: break-all;
  549. text-overflow: ellipsis;
  550. display: -webkit-box;
  551. -webkit-box-orient: vertical;
  552. -webkit-line-clamp: 2;
  553. overflow: hidden;
  554. }
  555. .cart_pre_spec {
  556. overflow: hidden;
  557. text-overflow: ellipsis;
  558. white-space: nowrap;
  559. margin-top: 5px;
  560. }
  561. }
  562. }
  563. .cart_pre_right {
  564. .cart_pre_price {
  565. color: #666;
  566. }
  567. .cart_pre_del {
  568. color: #666;
  569. cursor: pointer;
  570. margin-top: 10px;
  571. &:hover {
  572. color: $colorMain;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. .cart_bottom {
  579. width: 100%;
  580. height: 44px;
  581. border: 1px solid #e3e3e3;
  582. .cart_bottom_left {
  583. padding-left: 11px;
  584. height: 44px;
  585. span {
  586. color: #666;
  587. &:nth-child(2) {
  588. margin-left: 5px;
  589. }
  590. }
  591. }
  592. .cart_bottom_right {
  593. width: 110px;
  594. height: 44px;
  595. text-align: center;
  596. color: #fff;
  597. line-height: 44px;
  598. cursor: pointer;
  599. }
  600. }
  601. }
  602. </style>