SldHomeTopSearch.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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 useFetchRaw(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: 100%;
  217. // margin: 0 auto 0px;
  218. padding: 0 240px;
  219. display: flex;
  220. align-items: center;
  221. // justify-content: center;
  222. border-bottom: 1px solid #dbdbdb;
  223. // margin-bottom: 10px;
  224. background: #F6F8FA;
  225. .container_header {
  226. width: 100%;
  227. position: fixed;
  228. background-color: #fff;
  229. left: 0;
  230. right: 0;
  231. top: 0;
  232. z-index: 999;
  233. border-bottom: 2px solid $colorMain;
  234. .sld_seach_wrap,
  235. .sld_cart_wrap {
  236. margin: 5px;
  237. position: relative;
  238. }
  239. .container_header_box {
  240. width: 1200px;
  241. margin: 0 auto;
  242. >div:last-child{
  243. width: 400px;
  244. }
  245. .fixed_sld_cart_wrap {
  246. margin-right: 120px;
  247. a {
  248. width: 100%;
  249. height: 100%;
  250. img {
  251. max-width: 100%;
  252. max-height: 100%;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. .container_header {
  259. -webkit-animation: searchTop 0.5s ease-in-out;
  260. animation: searchTop 0.5s ease-in-out;
  261. }
  262. @-webkit-keyframes searchTop {
  263. 0% {
  264. top: -50px;
  265. }
  266. to {
  267. top: 0;
  268. }
  269. }
  270. @keyframes searchTop {
  271. 0% {
  272. top: -50px;
  273. }
  274. to {
  275. top: 0;
  276. }
  277. }
  278. &:before {
  279. display: table;
  280. content: " ";
  281. }
  282. .sld_home_top_search_left {
  283. height: 100%;
  284. // flex:0 0 200px;
  285. // position: absolute;
  286. // left: 240px;
  287. width: 200px;
  288. .sld_logo_wrap {
  289. height: 100%;
  290. img {
  291. width: 100%;
  292. // height: 100%;
  293. }
  294. }
  295. }
  296. .sld_seach_wrap {
  297. // width: 536px;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. flex: 1;
  302. width: 100%;
  303. overflow: hidden;
  304. padding: 4px 20px;
  305. position: relative;
  306. .sld_seach_box {
  307. width: 536px;
  308. z-index: 11;
  309. height: 38px;
  310. border: 2px solid $colorMain;
  311. .form {
  312. background-color: $colorMain;
  313. height: 34px;
  314. overflow: hidden;
  315. .text {
  316. height: 36px;
  317. background-color: #fff;
  318. width: calc(100% - 103px);
  319. -webkit-appearance: none;
  320. -webkit-border-radius: 0;
  321. height: 34px;
  322. color: rgb(153, 153, 153);
  323. padding: 5px 5px 5px 10px;
  324. background-position: 0 -360px;
  325. background-color: #fff;
  326. background-repeat: repeat-x;
  327. line-height: 20px;
  328. font-family: arial, "\5b8b\4f53";
  329. font-size: 12px;
  330. outline: none;
  331. border: none;
  332. }
  333. input {
  334. margin: 0;
  335. padding: 0;
  336. height: 34px;
  337. border: 0;
  338. }
  339. input::placeholder {
  340. font-size: $fontE;
  341. /*font-family: Microsoft YaHei;*/
  342. font-weight: 400;
  343. color: rgba(40,46,48,0.6);
  344. }
  345. ::-webkit-input-placeholder {
  346. margin-left: 20px;
  347. font-size: $fontE;
  348. /*font-family: Microsoft YaHei;*/
  349. font-weight: 400;
  350. color: rgba(40,46,48,0.6);
  351. }
  352. /* 使用webkit内核的浏览器 */
  353. :-moz-placeholder {
  354. font-size: $fontE;
  355. /*font-family: Microsoft YaHei;*/
  356. font-weight: 400;
  357. color: rgba(40,46,48,0.6);
  358. }
  359. /* Firefox版本19+ */
  360. :-ms-input-placeholder {
  361. font-size: $fontE;
  362. /*font-family: Microsoft YaHei;*/
  363. font-weight: 400;
  364. color: rgba(40,46,48,0.6);
  365. }
  366. /* IE浏览器 */
  367. .button {
  368. width: 103px;
  369. background: $colorMain;
  370. font-size: $fontE;
  371. font-weight: 600;
  372. color: #fff;
  373. float: right;
  374. cursor: pointer;
  375. text-align: center;
  376. }
  377. }
  378. .hot_search_wrap {
  379. height: 30px;
  380. line-height: 30px;
  381. color: #999;
  382. overflow: hidden;
  383. strong {
  384. float: left;
  385. font-weight: 400;
  386. }
  387. a {
  388. color: #666;
  389. white-space: nowrap;
  390. overflow: hidden;
  391. text-overflow: ellipsis;
  392. word-break: break-all;
  393. &:link,
  394. &:visited {
  395. float: left;
  396. margin-right: 10px;
  397. }
  398. &:hover {
  399. color: $colorMain;
  400. }
  401. }
  402. }
  403. }
  404. .search_association {
  405. background: #fff;
  406. position: absolute;
  407. top: 43px;
  408. overflow: hidden;
  409. position: absolute;
  410. left: 0;
  411. width: 580px;
  412. border: 1px solid #ccc;
  413. background: #fff;
  414. z-index: 99;
  415. .s_a_item {
  416. display: flex;
  417. justify-content: space-between;
  418. overflow: hidden;
  419. padding: 1px 5px;
  420. line-height: 24px;
  421. cursor: pointer;
  422. font-size: 12px;
  423. -webkit-font-smoothing: antialiased;
  424. color: #666;
  425. div:first-child {
  426. width: 250px;
  427. white-space: nowrap;
  428. text-overflow: ellipsis;
  429. overflow: hidden;
  430. }
  431. div:last-child {
  432. overflow: hidden;
  433. color: #aaa;
  434. }
  435. &:hover {
  436. background-color: rgb(255, 233, 188);
  437. }
  438. }
  439. }
  440. }
  441. }
  442. .sld_cart_wrap {
  443. // position: absolute;
  444. // right: 240px;
  445. z-index: 99;
  446. height: 40px;
  447. width: 210px;
  448. text-align: center;
  449. dl {
  450. margin-bottom: 0px;
  451. .cart_goods_num {
  452. font: 11px/16px Verdana;
  453. color: #fff;
  454. background: $colorMain;
  455. text-align: center;
  456. display: inline-block;
  457. height: 16px;
  458. min-width: 16px;
  459. border: none 0;
  460. border-radius: 8px;
  461. margin-left: 10px;
  462. }
  463. dt {
  464. // position: absolute;
  465. z-index: 3;
  466. width: 100%;
  467. height: 38px;
  468. cursor: pointer;
  469. font-weight: 400;
  470. line-height: 38px;
  471. padding: 0;
  472. color: $colorMain;
  473. font-size: 15px;
  474. img {
  475. margin: -2px 11px 0 0px;
  476. vertical-align: middle;
  477. width: 20px;
  478. }
  479. &.cart_icon_text_wrap {
  480. background-color: #fff;
  481. a {
  482. color: #666666;
  483. font-size: 15px;
  484. line-height: 36px;
  485. }
  486. span {
  487. font-weight: bold;
  488. font-size: $fontE;
  489. color: $colorMain;
  490. }
  491. }
  492. }
  493. dd {
  494. .cart_goods {
  495. dl {
  496. padding-top: 8px;
  497. }
  498. dd {
  499. &.cart_goods_price {
  500. position: static;
  501. em {
  502. margin-right: 6px;
  503. width: auto;
  504. color: #666;
  505. &:nth-child(1) {
  506. display: block;
  507. font-weight: 600;
  508. }
  509. &:nth-child(2) {
  510. display: block;
  511. text-align: right;
  512. margin-top: 6px;
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. }
  520. dd {
  521. position: absolute;
  522. top: 37px;
  523. right: 0;
  524. width: 355px;
  525. border: 1px solid #e3e3e3;
  526. background: #fff;
  527. z-index: 1;
  528. }
  529. }
  530. .ld {
  531. position: relative;
  532. zoom: 1;
  533. }
  534. .cart_data {
  535. height: 300px;
  536. display: flex;
  537. flex-direction: column;
  538. position: relative;
  539. .cart_data_title {
  540. font-weight: 600;
  541. float: left;
  542. padding: 7px;
  543. line-height: 32px;
  544. height: 32px;
  545. }
  546. .cart_list {
  547. padding: 20px;
  548. overflow-y: scroll;
  549. .cart_list_pre {
  550. margin-bottom: 20px;
  551. .cart_pre_left {
  552. .cart_pre_img {
  553. width: 48px;
  554. height: 48px;
  555. border: 1px solid #e3e3e3;
  556. cursor: pointer;
  557. img {
  558. width: 100%;
  559. height: 100%;
  560. }
  561. }
  562. .cart_pre_cen {
  563. width: 150px;
  564. margin-left: 20px;
  565. cursor: pointer;
  566. .cart_pre_name {
  567. word-break: break-all;
  568. text-overflow: ellipsis;
  569. display: -webkit-box;
  570. -webkit-box-orient: vertical;
  571. -webkit-line-clamp: 2;
  572. overflow: hidden;
  573. }
  574. .cart_pre_spec {
  575. overflow: hidden;
  576. text-overflow: ellipsis;
  577. white-space: nowrap;
  578. margin-top: 5px;
  579. }
  580. }
  581. }
  582. .cart_pre_right {
  583. .cart_pre_price {
  584. color: #666;
  585. }
  586. .cart_pre_del {
  587. color: #666;
  588. cursor: pointer;
  589. margin-top: 10px;
  590. &:hover {
  591. color: $colorMain;
  592. }
  593. }
  594. }
  595. }
  596. }
  597. .cart_bottom {
  598. width: 100%;
  599. height: 44px;
  600. border: 1px solid #e3e3e3;
  601. .cart_bottom_left {
  602. padding-left: 11px;
  603. height: 44px;
  604. span {
  605. color: #666;
  606. &:nth-child(2) {
  607. margin-left: 5px;
  608. }
  609. }
  610. }
  611. .cart_bottom_right {
  612. width: 110px;
  613. height: 44px;
  614. text-align: center;
  615. color: #fff;
  616. line-height: 44px;
  617. cursor: pointer;
  618. }
  619. }
  620. }
  621. </style>