SldHomeTopSearch.vue 15 KB

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