SldHomeTopSearch.vue 15 KB

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