123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- <template>
- <div class="main-search" @touchstart="cancelFocus" @click="setShowSearchType(false)" id="main-search">
- <!--<div class="main-search-header">-->
- <!--<div class="options" @click="setShowSearchType(!showSearchType, $event)">-->
- <!--{{searchType == 'product' ? '产品' : '店铺'}}-->
- <!--<i></i>-->
- <!--<ul v-if="showSearchType">-->
- <!--<li @click="setSearchType(searchType == 'product' ? 'store' : 'product', $event)">{{searchType == 'product' ? '店铺' : '产品'}}</li>-->
- <!--</ul>-->
- <!--</div>-->
- <!--<input type="text" id="search-box" v-model="keyword" @keyup.13="onSearch()">-->
- <!--<span @click="onSearch()">搜索</span>-->
- <!--<a @click="cancelSearch">取消</a>-->
- <!--</div>-->
- <div class="main-search-header">
- <input type="text" v-model="keyword" id="search-box" @keyup.13="onSearch()" :placeholder="placeholder">
- <span @click="onSearch()">搜索</span>
- <a @click="cancelSearch()">取消</a>
- <div class="main-search-header-controll clearfix">
- <div style="display: flex;align-items: center;justify-content: space-between;width:100%;">
- <div :class="ChooseTop === 'component' ? 'active' : ''" @click="setChangelistHander('component')"><a>型号</a></div>
- <div :class="ChooseTop === 'kind' ? 'active' : ''" @click="setChangelistHander('kind')"><a>物料名称</a></div>
- <div :class="ChooseTop === 'store' ? 'active' : ''" @click="setChangelistHander('store')"><a>卖家</a></div>
- <div :class="ChooseTop === 'brand' ? 'active' : ''" @click="setChangelistHander('brand')"><a>品牌</a></div>
- </div>
- </div>
- </div>
- <ul class="associate-list" v-show="associate.show">
- <li @click="onAssociateClick(similar)" v-for="similar in similarKeywords.result">
- <i class="icon-sousuo iconfont"></i>
- <span>{{Getsimilar(similar)}}</span>
- <!--<span v-if="ChooseTop === 'component'">{{similar.code}}</span>-->
- <!--<span v-else-if="ChooseTop === 'product'">{{similar}}</span>-->
- <!--<span v-else-if="ChooseTop === 'store'">{{similar}}</span>-->
- <!--<span v-else-if="ChooseTop === 'brand'">{{similar.nameEn}}</span>-->
- </li>
- <li @click="onAssociateClick(keyword)">查找“{{baseUtils.filterStringEllipsis(keyword, 30)}}”</li>
- </ul>
- <div class="hot-history" v-show="!associate.show" style="margin-top: 2.08rem">
- <div class="search-history" v-if="searchHistory && searchHistory.length > 0">
- <p>历史搜索<i class="iconfont icon-lajitong" @click="deleteHistory"></i></p>
- <ul>
- <li v-for="item in searchHistory" @click="onSearch(item.keyword)" v-if="item.keyword && item.keyword.trim().length">
- <a>{{item.keyword}}</a>
- </li>
- </ul>
- </div>
- <div class="search-hot">
- <img src="/images/mobile/@2x/home/hot-search.png" alt="">
- <ul>
- <li v-for="hotword in hotwords">
- <a :href="hotword.url" v-text="hotword.name"></a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'home',
- data () {
- return {
- keyword: '',
- associate: {
- show: false
- },
- searchType: 'product',
- showSearchType: false,
- ChooseTop: 'component'
- }
- },
- props: {
- hotwords: {
- type: Array,
- default () {
- return [
- {name: '深圳华商龙', url: 'https://mall.usoftchina.com/mobile/shop/worldshine'},
- {name: 'DSP1-DC5V-F', url: 'https://mall.usoftchina.com/mobile/brand/componentDetail/0900300200000669'},
- {name: 'Vishay', url: 'https://mall.usoftchina.com/mobile/brand/30327265e42a871be050007f01003d96'},
- {name: 'Panasonic', url: 'https://mall.usoftchina.com/mobile/brand/30327265e47d871be050007f01003d96'},
- {name: 'Taiyo Yuden', url: 'https://mall.usoftchina.com/mobile/brand/30327265e4be871be050007f01003d96'},
- {name: 'AE324FB5PN', url: 'https://mall.usoftchina.com/mobile/brand/componentDetail/0900502200684613'}
- ]
- }
- }
- },
- // filters: {
- // similarFilter: function ([key, keyword]) {
- // console.log(keyword)
- // let index = key.indexOf(keyword)
- // if (index !== -1) {
- // key = key.substring(0, index) + '<strong>' + key.substr(index, keyword.length) + '</strong>' + key.substring(index + keyword.length, key.length)
- // }
- // return key
- // }
- // },
- methods: {
- setChangelistHander(str) {
- this.ChooseTop = str
- if (!this.keyword) return
- this.$store.dispatch('searchKeywords', {keyword: this.keyword, type: this.ChooseTop})
- this.associate.show = true
- },
- onSearch (item) {
- if (item) {
- this.keyword = item
- }
- if (this.keyword) {
- this.$router.push(`/mobile/search/newkeycode?choosetype=${this.ChooseTop}&keyword=${encodeURIComponent(this.keyword)}`)
- }
- // if (item) {
- // this.keyword = item.keyword
- // if (item.type === 'SEARCH_STORE') {
- // this.$router.push('/mobile/shop?keyword=' + encodeURIComponent(this.keyword))
- // } else if (item.type === 'SEARCH_PRODUCT') {
- // this.$router.push('/mobile/search?w=' + encodeURIComponent(this.keyword))
- // }
- // } else {
- // if (this.keyword) {
- // if (this.searchType === 'product') {
- // this.$router.push('/mobile/search?w=' + encodeURIComponent(this.keyword))
- // } else if (this.searchType === 'store') {
- // this.$router.push('/mobile/shop?keyword=' + encodeURIComponent(this.keyword))
- // }
- // }
- // }
- },
- onChange () {
- if (!this.keyword) {
- this.associate.show = false
- this.$store.dispatch('resetSearchKeywords')
- } else {
- this.searchKeywords()
- }
- if (this.click_flag) {
- this.associate.show = false
- }
- },
- searchKeywords () {
- this.$store.dispatch('searchKeywords', {keyword: this.keyword, type: this.ChooseTop})
- this.associate.show = true
- },
- onAssociateClick (word) {
- if (this.ChooseTop === 'component') {
- this.keyword = word.code
- } else if (this.ChooseTop === 'kind') {
- this.keyword = word.nameCn
- } else if (this.ChooseTop === 'store') {
- this.keyword = word.name
- } else if (this.ChooseTop === 'brand') {
- this.keyword = word.nameEn
- }
- this.onSearch()
- },
- Getsimilar(word) {
- if (this.ChooseTop === 'component') {
- return word.code
- } else if (this.ChooseTop === 'kind') {
- return word.nameCn
- } else if (this.ChooseTop === 'store') {
- return word.name
- } else if (this.ChooseTop === 'brand') {
- return word.nameEn
- }
- },
- cancelSearch: function () {
- this.$emit('cancelSearchAction')
- },
- cancelFocus: function () {
- // document.getElementById('search-box').blur()
- },
- deleteHistory () {
- this.$http.delete('/search/searchHistory').then(response => {
- this.$store.dispatch('searchData/getSearchHistory')
- })
- },
- setSearchType (type, $event) {
- $event.stopPropagation()
- this.searchType = type
- this.setShowSearchType(false)
- this.associate.show = false
- },
- setShowSearchType (flag, e) {
- if (e) {
- e.stopPropagation()
- }
- this.showSearchType = flag
- }
- },
- created () {
- this.$store.dispatch('resetSearchKeywords')
- },
- mounted () {
- document.getElementById('search-box').focus()
- let height = window.innerHeight
- window.onresize = function () {
- if (window.innerHeight < height) {
- document.getElementById('main-search').style.bottom = (window.innerHeight - height) / (document.documentElement.clientWidth / 750) + 'rem'
- } else {
- document.getElementById('main-search').style.bottom = 0
- }
- }
- },
- watch: {
- 'keyword': function (val, oldVal) {
- let keywords = this.similarKeywords.data
- if (!keywords || !keywords.length) {
- this.onChange()
- }
- }
- },
- computed: {
- similarKeywords () {
- return this.$store.state.search.keywords.data
- },
- searchHistory () {
- return this.$store.state.searchData.searchHistory.searchHistory.data
- },
- placeholder() {
- if (this.ChooseTop === 'cmpcode') {
- return '请输入您要搜索的型号'
- } else if (this.ChooseTop === 'materiel') {
- return '请输入您要搜索的物料名称'
- } else if (this.ChooseTop === 'seller') {
- return '请输入您要搜索的卖家名称'
- } else if (this.ChooseTop === 'cmpbrand') {
- return '请输入您要搜索的品牌'
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @mixin overFlowHidden {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- @mixin lineHeight($value) {
- height: $value;
- line-height: $value;
- }
- .main-search {
- background: #fff;
- width: 100%;
- position: fixed;
- z-index: 1000;
- top: 0;
- bottom: 0;
- .main-search-header {
- position: absolute;
- background: #3e82f5;
- line-height: .88rem;
- margin-top: 0;
- z-index: 1;
- width: 100%;
- input {
- width: 4.88rem;
- height: .62rem;
- line-height: .62rem;
- font-size: .26rem;
- color: #333;
- margin-left: 0.3rem;
- /*padding-left: 1.26rem;*/
- border: .04rem solid #fff;
- background: #fff;
- outline: none;
- border-radius: 0;
- float: left;
- margin-top: .12rem;
- -webkit-appearance: none;
- border-top-left-radius: .14rem;
- border-bottom-left-radius: .14rem;
- }
- span {
- display: inline-block;
- width: 1.02rem;
- text-align: center;
- height: .62rem;
- line-height: .62rem;
- color: #366df3;
- font-size: .28rem;
- margin-left: .02rem;
- border-top-right-radius: .14rem;
- border-bottom-right-radius: .14rem;
- background: #fff;
- float: left;
- margin-top: .12rem;
- }
- a {
- font-size: .28rem;
- color: #fff;
- margin-left: .2rem;
- }
- .main-search-header-controll {
- background: #3e82f5;
- width: 5.9rem;
- margin-left: 0.3rem;
- div {
- @include lineHeight(0.66rem);
- font-size: 0.28rem;
- color: #fff;
- margin: 0;
- background: rgba(0,0,0,0);
- border-radius: 0;
- &.active a{
- color: #fff;
- border-bottom: 0.02rem solid #fff;
- }
- }
- }
- }
- .associate-list {
- position: absolute;
- width: 100%;
- background: #fff;
- top: 0.8rem;
- border: 1px solid #dcdcdc;
- z-index: 100;
- height: 100%;
- left: 0;
- bottom: 0;
- right: 0;
- li {
- height: 0.7rem;
- line-height: .9rem;
- margin: 0 .45rem;
- border-bottom: .04rem solid #f1f0f0;
- @include overFlowHidden();
- i {
- font-size: .36rem;
- margin-right: .24rem;
- color: #ddd;
- }
- span {
- color: #999;
- font-size: .28rem;
- line-height: .58rem;
- height: .58rem;
- display: inline-block;
- }
- &:active, &:hover {
- background: #eee;
- }
- &:last-child {
- text-align: center;
- font-size: .3rem;
- color: #3976f4;
- border-bottom: none;
- &:active, &:hover {
- background: #fff;
- }
- }
- }
- }
- .hot-history {
- .search-history {
- padding-left: .51rem;
- >p {
- font-size: .3rem;
- color: #333;
- i {
- font-size: .3rem;
- float: right;
- margin-right: 0.4rem;
- }
- }
- ul {
- text-align: left;
- margin-top: .26rem;
- li {
- display: inline-block;
- max-width: 2.83rem;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin: 0 .1rem .1rem 0;
- background: #f2f6ff;
- height: .56rem;
- line-height: .56rem;
- padding: 0 .12rem;
- a {
- font-size: .3rem;
- color: #666;
- }
- }
- }
- }
- .search-hot {
- text-align: center;
- margin-top: .3rem;
- >img {
- width: 2.56rem;
- height: .67rem;
- }
- ul {
- text-align: left;
- padding-left: .51rem;
- margin-top: .31rem;
- li {
- display: inline-block;
- /*max-width: 2.83rem;*/
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin: 0 .1rem .1rem 0;
- background: #fef1eb;
- height: .56rem;
- line-height: .56rem;
- padding: 0 .12rem;
- a {
- font-size: .3rem;
- color: #666;
- }
- &:nth-child(1) {
- a {
- color: #fc5708;
- }
- }
- }
- }
- }
- }
- }
- </style>
|