123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- <template>
- <div class="sld_home_top_search container">
- <div class="ld sld_home_top_search_left">
- <a href="javascript:void(0)" class="sld_logo_wrap flex_row_start_center" @click="go_home">
- <img :src="filtersStore.getSiteLogo" />
- </a>
- </div>
- <div class="sld_seach_wrap">
- <div class="sld_seach_box ld">
- <div class="form" @submit.prevent>
- <input
- v-model="keyword"
- type="text"
- class="text"
- autocomplete="off"
- :placeholder="L['请输入关键词']"
- @keyup.enter="search"
- ref="searchInput"
- @focus="inputFocus"
- @input="inputChange"
- @blur="inputBlur"
- />
- <input type="submit" :value="L['搜索']" class="button" @click="search" />
- </div>
- <div class="hot_search_wrap">
- <div>
- <template v-for="(item, index) in hotList.data" :key="index">
- <a
- href="javascript:void(0)"
- @click="quickSearch(index, 'quick')"
- :title="tmpHotList[index]"
- >{{ item }}</a
- >
- </template>
- </div>
- </div>
- </div>
- <div class="search_association" id="searchA" v-show="SAList.length && SAShow">
- <div
- class="s_a_item"
- v-for="(item, index) in SAList"
- @mousedown="quickSearch(item.wordsContent, 'associ')"
- >
- <!-- 因为click事件与blur事件冲突,blur事件优先,于是换成mousedown -->
- <div>{{ item.wordsContent }}</div>
- <div>{{ item.searchGoodsNum }} {{L['个商品']}}</div>
- </div>
- </div>
- </div>
- <div v-if="searchBarFixed" class="container_header">
- <div class="container_header_box flex_row_start_center">
- <div class="sld_cart_wrap fixed_sld_cart_wrap">
- <nuxt-link tag="a" class="sld_logo_wrap flex_row_start_center" :to="`/`">
- <img :src="filtersStore.getSiteLogo" />
- </nuxt-link>
- </div>
- <div class="sld_seach_wrap" style="margin-right: 90px">
- <div class="sld_seach_box ld">
- <div class="form">
- <input
- v-model="keyword"
- type="text"
- class="text"
- autocomplete="off"
- style="color: rgb(153, 153, 153)"
- :placeholder="L['请输入关键词']"
- ref="searchInput"
- @focus="inputFocus"
- />
- <input type=" submit" :value="L['搜索']" class="button" @click="search" />
- </div>
- </div>
- </div>
- <div class="sld_cart_wrap">
- <dl class>
- <dt
- class="ld cart_icon_text_wrap"
- >
- <img src="/email.svg" />
- <nuxt-link target="_self" :to="`/home/contact`">{{
- L["发布需求"]
- }}</nuxt-link>
- </dt>
- </dl>
- </div>
- </div>
- </div>
- <div class="sld_cart_wrap">
- <dl class>
- <nuxt-link target="_self" :to="`/home/contact`">
- <dt
- class="ld cart_icon_text_wrap"
- >
- <img src="/email.svg" />
- <span>{{ L["发布需求"] }}</span>
- </dt>
- </nuxt-link>
- </dl>
- </div>
- </div>
- </template>
- <script setup>
- // import { lang_zn } from "@/assets/language/zh.js";
- import { getCurLanguage } from '@/composables/common.js';
- import { useFiltersStore } from '@/store/filter.js'
- import {ref} from "vue";
- const filtersStore = useFiltersStore()
- // const L = lang_zn;
- const L = getCurLanguage();
- const { proxy } = getCurrentInstance();
- const searchBarFixed = ref(false);
- const hotList = reactive({ data: [] }); //热门搜索词列表
- const tmpHotList = ref([]);
- const SAList = ref([]);
- const SAShow = ref(false);
- const router = useRouter();
- const route = useRoute();
- const keyword = ref(calcMallUrlKeyword(route.path))
- const go_home = () => {
- window.location.href="/"
- };
- const getInitData = async () => {
- const {data:res} = await useFetchRaw(apiUrl + "v3/system/front/setting/getSettings?names=hot_search_words,gz_code");
- if(res._rawValue.state == 200){
- hotList.data = res._rawValue.data
- let tmp_data = hotList.data[0] ? hotList.data[0].split(",").filter((i) => i != "") : [];
- tmpHotList.value = tmp_data;
- hotList.data = tmp_data;
- hotList.data = hotList.data.map((key) => {
- if (key.length > 20) {
- return key.substring(0, 20) + "...";
- } else {
- return key;
- }
- });
- }
- }
- getInitData()
- //搜索事件
- const search = () => {
- proxy.$refs.searchInput.style.color = "rgb(153,153,153)";
- if (keyword.value) {
- router.push({
- path: `/goods/list/search_keyword-`+keyword.value,
- });
- }
- };
- const searchAssociation = (input) => {
- get("v3/goods/front/goods/searchWords/list", {
- keyWord: input,
- }).then((res) => {
- if (res.state == 200) {
- SAList.value = res.data;
- }
- });
- };
- const inputChange = (e) => {
- let input = e.target.value.trim();
- SAShow.value = true;
- if (input) {
- searchAssociation(input);
- } else {
- SAList.value = [];
- }
- };
- //热门搜索事件
- const quickSearch = (val, type) => {
- if (type == "quick") {
- router.push({
- path: `/goods/list/search_keyword-`+tmpHotList.value[val],
- });
- } else {
- if (val == keyword.value) {
- keyword.value = val;
- } else {
- router.push({
- path: `/goods/list/search_keyword-`+val,
- });
- }
- }
- };
- const inputFocus = () => {
- proxy.$refs.searchInput.style.color = "#333";
- SAShow.value = true;
- if (keyword.value && SAList.value.length == 0) {
- searchAssociation(keyword.value);
- }
- };
- const inputBlur = () => {
- SAShow.value = false;
- };
- //滚动事件
- if (process.client) {
- const handleScroll = () => {
- var height = 600;
- var scrollTop =
- window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
- if (scrollTop > height) {
- searchBarFixed.value = true;
- } else {
- searchBarFixed.value = false;
- }
- };
- window.addEventListener("scroll", handleScroll);
- }
- </script>
- <style lang="scss" scoped>
- a:active,
- a:visited {
- color: #333;
- }
- .sld_home_top_search {
- height: 80px;
- position: relative;
- z-index: 12;
- width: 1210px;
- margin: 0 auto 0px;
- padding-left: 0px;
- padding-right: 0px;
- display: flex;
- align-items: center;
- border-bottom: 1px solid #dbdbdb;
- margin-bottom: 10px;
- .container_header {
- width: 100%;
- position: fixed;
- background-color: #fff;
- left: 0;
- right: 0;
- top: 0;
- z-index: 999;
- border-bottom: 2px solid $colorMain;
- .sld_seach_wrap,
- .sld_cart_wrap {
- margin: 5px;
- position: relative;
- }
- .container_header_box {
- width: 1200px;
- margin: 0 auto;
- >div:last-child{
- width: 400px;
- }
- .fixed_sld_cart_wrap {
- margin-right: 120px;
- a {
- width: 100%;
- height: 100%;
- img {
- max-width: 100%;
- max-height: 100%;
- }
- }
- }
- }
- }
- .container_header {
- -webkit-animation: searchTop 0.5s ease-in-out;
- animation: searchTop 0.5s ease-in-out;
- }
- @-webkit-keyframes searchTop {
- 0% {
- top: -50px;
- }
- to {
- top: 0;
- }
- }
- @keyframes searchTop {
- 0% {
- top: -50px;
- }
- to {
- top: 0;
- }
- }
- &:before {
- display: table;
- content: " ";
- }
- .sld_home_top_search_left {
- position: relative;
- flex:0 0 250px;
- .sld_logo_wrap {
- img {
- max-width: 144px;
- max-height: 100%;
- }
- }
- }
- .sld_seach_wrap {
- flex: auto;
- padding-top: 4px;
- position: relative;
- .sld_seach_box {
- z-index: 11;
- height: 38px;
- border: 2px solid $colorMain;
- .form {
- background-color: $colorMain;
- height: 34px;
- overflow: hidden;
- .text {
- height: 36px;
- background-color: #fff;
- width: calc(100% - 103px);
- -webkit-appearance: none;
- -webkit-border-radius: 0;
- height: 34px;
- color: rgb(153, 153, 153);
- padding: 5px 5px 5px 10px;
- background-position: 0 -360px;
- background-color: #fff;
- background-repeat: repeat-x;
- line-height: 20px;
- font-family: arial, "\5b8b\4f53";
- font-size: 12px;
- outline: none;
- border: none;
- }
- input {
- margin: 0;
- padding: 0;
- height: 34px;
- border: 0;
- }
- input::placeholder {
- font-size: 12px;
- /*font-family: Microsoft YaHei;*/
- font-weight: 400;
- color: rgb(153, 153, 153);
- }
- ::-webkit-input-placeholder {
- margin-left: 20px;
- font-size: 12px;
- /*font-family: Microsoft YaHei;*/
- font-weight: 400;
- color: rgb(153, 153, 153);
- }
- /* 使用webkit内核的浏览器 */
- :-moz-placeholder {
- font-size: 12px;
- /*font-family: Microsoft YaHei;*/
- font-weight: 400;
- color: rgb(153, 153, 153);
- }
- /* Firefox版本19+ */
- :-ms-input-placeholder {
- font-size: 12px;
- /*font-family: Microsoft YaHei;*/
- font-weight: 400;
- color: rgb(153, 153, 153);
- }
- /* IE浏览器 */
- .button {
- width: 103px;
- background: $colorMain;
- font-size: 16px;
- font-weight: 600;
- color: #fff;
- float: right;
- cursor: pointer;
- text-align: center;
- }
- }
- .hot_search_wrap {
- height: 30px;
- line-height: 30px;
- color: #999;
- overflow: hidden;
- strong {
- float: left;
- font-weight: 400;
- }
- a {
- color: #666;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- word-break: break-all;
- &:link,
- &:visited {
- float: left;
- margin-right: 10px;
- }
- &:hover {
- color: $colorMain;
- }
- }
- }
- }
- .search_association {
- background: #fff;
- position: absolute;
- top: 43px;
- overflow: hidden;
- position: absolute;
- left: 0;
- width: 580px;
- border: 1px solid #ccc;
- background: #fff;
- z-index: 99;
- .s_a_item {
- display: flex;
- justify-content: space-between;
- overflow: hidden;
- padding: 1px 5px;
- line-height: 24px;
- cursor: pointer;
- font-size: 12px;
- -webkit-font-smoothing: antialiased;
- color: #666;
- div:first-child {
- width: 250px;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- div:last-child {
- overflow: hidden;
- color: #aaa;
- }
- &:hover {
- background-color: rgb(255, 233, 188);
- }
- }
- }
- }
- }
- .sld_cart_wrap {
- position: relative;
- z-index: 99;
- height: 40px;
- flex: 0 0 240px;
- text-align: center;
- dl {
- margin-bottom: 0px;
- .cart_goods_num {
- font: 11px/16px Verdana;
- color: #fff;
- background: $colorMain;
- text-align: center;
- display: inline-block;
- height: 16px;
- min-width: 16px;
- border: none 0;
- border-radius: 8px;
- margin-left: 10px;
- }
- dt {
- position: absolute;
- z-index: 3;
- width: 100%;
- height: 38px;
- cursor: pointer;
- font-weight: 400;
- line-height: 38px;
- padding: 0;
- color: $colorMain;
- font-size: 15px;
- img {
- margin: -2px 11px 0 0px;
- vertical-align: middle;
- width: 16px;
- }
- &.cart_icon_text_wrap {
- a {
- color: #666666;
- font-size: 15px;
- line-height: 36px;
- }
- }
- }
- dd {
- .cart_goods {
- dl {
- padding-top: 8px;
- }
- dd {
- &.cart_goods_price {
- position: static;
- em {
- margin-right: 6px;
- width: auto;
- color: #666;
- &:nth-child(1) {
- display: block;
- font-weight: 600;
- }
- &:nth-child(2) {
- display: block;
- text-align: right;
- margin-top: 6px;
- }
- }
- }
- }
- }
- }
- }
- dd {
- position: absolute;
- top: 37px;
- right: 0;
- width: 355px;
- border: 1px solid #e3e3e3;
- background: #fff;
- z-index: 1;
- }
- }
- .ld {
- position: relative;
- zoom: 1;
- }
- .cart_data {
- height: 300px;
- display: flex;
- flex-direction: column;
- position: relative;
- .cart_data_title {
- font-weight: 600;
- float: left;
- padding: 7px;
- line-height: 32px;
- height: 32px;
- }
- .cart_list {
- padding: 20px;
- overflow-y: scroll;
- .cart_list_pre {
- margin-bottom: 20px;
- .cart_pre_left {
- .cart_pre_img {
- width: 48px;
- height: 48px;
- border: 1px solid #e3e3e3;
- cursor: pointer;
- img {
- width: 100%;
- height: 100%;
- }
- }
- .cart_pre_cen {
- width: 150px;
- margin-left: 20px;
- cursor: pointer;
- .cart_pre_name {
- word-break: break-all;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
- .cart_pre_spec {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin-top: 5px;
- }
- }
- }
- .cart_pre_right {
- .cart_pre_price {
- color: #666;
- }
- .cart_pre_del {
- color: #666;
- cursor: pointer;
- margin-top: 10px;
- &:hover {
- color: $colorMain;
- }
- }
- }
- }
- }
- .cart_bottom {
- width: 100%;
- height: 44px;
- border: 1px solid #e3e3e3;
- .cart_bottom_left {
- padding-left: 11px;
- height: 44px;
- span {
- color: #666;
- &:nth-child(2) {
- margin-left: 5px;
- }
- }
- }
- .cart_bottom_right {
- width: 110px;
- height: 44px;
- text-align: center;
- color: #fff;
- line-height: 44px;
- cursor: pointer;
- }
- }
- }
- </style>
|