Authored by 张文文

首页搜索框悬浮 reviewd by lea.guo

1 <template> 1 <template>
2 <LayoutApp class="yohoufo-channel-page" :show-back="true" :hide-header="hideHeader" :title="title" :no-safe-area="true"> 2 <LayoutApp class="yohoufo-channel-page" :show-back="true" :hide-header="hideHeader" :title="title" :no-safe-area="true">
  3 + <div class="wrapper-search" :class="{'hidden': !isFixSearch}">
  4 + <div class="search-header" @click="goSearch">
  5 + <div class="search-img"></div>
  6 + <input class="search-input" type="search" disabled="true" :placeholder="defaultSearchWord || '搜索商品名称或货号'"/>
  7 + </div>
  8 + </div>
  9 +
3 <div class="fixed-nav scroll-nav-wrap" :class="{'hidden': !isShow}" v-if="navList.length"> 10 <div class="fixed-nav scroll-nav-wrap" :class="{'hidden': !isShow}" v-if="navList.length">
4 <ScrollNav :list="navList" :current="active" @transfer="getIndex"></ScrollNav> 11 <ScrollNav :list="navList" :current="active" @transfer="getIndex"></ScrollNav>
5 </div> 12 </div>
@@ -11,7 +18,7 @@ @@ -11,7 +18,7 @@
11 @pulling-up="onPullingUp" > 18 @pulling-up="onPullingUp" >
12 <div ref="body"> 19 <div ref="body">
13 <div ref="topSource" class="channel-html"> 20 <div ref="topSource" class="channel-html">
14 - <div class="search-header middle" @click="goSearch"> 21 + <div ref="searchSource" class="search-header middle" @click="goSearch">
15 <div class="search-img"></div> 22 <div class="search-img"></div>
16 <input class="search-input" type="search" disabled="true" :placeholder="defaultSearchWord || '搜索商品名称或货号'"/> 23 <input class="search-input" type="search" disabled="true" :placeholder="defaultSearchWord || '搜索商品名称或货号'"/>
17 </div> 24 </div>
@@ -22,8 +29,7 @@ @@ -22,8 +29,7 @@
22 <TwoBanner :list="item.data" :ref="index" :PAGE_URL="PAGE_URL" :key="index" v-if="item.template_name == 'twoPicture'"/> 29 <TwoBanner :list="item.data" :ref="index" :PAGE_URL="PAGE_URL" :key="index" v-if="item.template_name == 'twoPicture'"/>
23 </template> 30 </template>
24 </div> 31 </div>
25 - <!-- <div ref="scrollNav" :class="['scroll-nav-wrap',isShow?'fixed':'']" v-if="navList.length"> -->  
26 - <div ref="scrollNav" class="scroll-nav-wrap" v-if="navList.length"> 32 + <div ref="scrollNav" class="scroll-nav-wrap" v-if="navList.length">
27 <ScrollNav :list="navList" :current="active" @transfer="getIndex"></ScrollNav> 33 <ScrollNav :list="navList" :current="active" @transfer="getIndex"></ScrollNav>
28 </div> 34 </div>
29 <div class="list-wrap" :style="listStyle"> 35 <div class="list-wrap" :style="listStyle">
@@ -46,7 +52,6 @@ import TwoBanner from './components/twoBanner'; @@ -46,7 +52,6 @@ import TwoBanner from './components/twoBanner';
46 import Hot from './components/hot'; 52 import Hot from './components/hot';
47 import ScrollNav from './components/scrollNav'; 53 import ScrollNav from './components/scrollNav';
48 import ProductList from '../../list/components/productList'; 54 import ProductList from '../../list/components/productList';
49 -import { setTimeout } from 'timers';  
50 import UfoNoItem from '../../../components/ufo-no-item'; 55 import UfoNoItem from '../../../components/ufo-no-item';
51 56
52 const { mapState, mapActions } = createNamespacedHelpers('home/channel'); 57 const { mapState, mapActions } = createNamespacedHelpers('home/channel');
@@ -70,6 +75,7 @@ export default { @@ -70,6 +75,7 @@ export default {
70 navTop: 0, 75 navTop: 0,
71 navHeight: 0, 76 navHeight: 0,
72 isShow: false, 77 isShow: false,
  78 + isFixSearch: false,
73 total: 0, 79 total: 0,
74 active: 0, 80 active: 0,
75 yasHeight: 0, 81 yasHeight: 0,
@@ -128,7 +134,6 @@ export default { @@ -128,7 +134,6 @@ export default {
128 listStyle() { 134 listStyle() {
129 return { 135 return {
130 minHeight: this.total + 'px', 136 minHeight: this.total + 'px',
131 - // marginTop: this.isShow? this.navHeight +'px' : 0  
132 }; 137 };
133 } 138 }
134 }, 139 },
@@ -149,9 +154,8 @@ export default { @@ -149,9 +154,8 @@ export default {
149 this.fetchChannelList(); 154 this.fetchChannelList();
150 } 155 }
151 this.init(); 156 this.init();
152 - // this.getAllInboxCatInfo();  
153 157
154 - this.fetchDefaultSearchWord() 158 + this.fetchDefaultSearchWord();
155 159
156 this.PAGE_URL = window.location.href; 160 this.PAGE_URL = window.location.href;
157 161
@@ -172,7 +176,7 @@ export default { @@ -172,7 +176,7 @@ export default {
172 // 初始化 选中类目 176 // 初始化 选中类目
173 const [firstNav] = this.navList; 177 const [firstNav] = this.navList;
174 178
175 - if(firstNav) { 179 + if (firstNav) {
176 const {url = ''} = firstNav; 180 const {url = ''} = firstNav;
177 181
178 this.selectedCategory = queryString.parse(url); 182 this.selectedCategory = queryString.parse(url);
@@ -220,7 +224,6 @@ export default { @@ -220,7 +224,6 @@ export default {
220 } 224 }
221 if (scrollY) { // 滚动时 225 if (scrollY) { // 滚动时
222 if (scrollHeight + scrollY > eleTop && item.template_name === 'guessLike') { 226 if (scrollHeight + scrollY > eleTop && item.template_name === 'guessLike') {
223 - // console.log('guessLike report')  
224 item.data.forEach((val, i) => { 227 item.data.forEach((val, i) => {
225 reportParams = {...val.reportParams, PAGE_URL: this.PAGE_URL}; 228 reportParams = {...val.reportParams, PAGE_URL: this.PAGE_URL};
226 this.homeYasParams.push(reportParams); 229 this.homeYasParams.push(reportParams);
@@ -228,7 +231,6 @@ export default { @@ -228,7 +231,6 @@ export default {
228 231
229 } 232 }
230 if (scrollY < (eleTop + eleHeight) && item.template_name !== 'guessLike') { 233 if (scrollY < (eleTop + eleHeight) && item.template_name !== 'guessLike') {
231 - // console.log(item.template_name)  
232 let reportMoreParams = {}; 234 let reportMoreParams = {};
233 235
234 item.data.forEach((val, i) => { 236 item.data.forEach((val, i) => {
@@ -264,24 +266,25 @@ export default { @@ -264,24 +266,25 @@ export default {
264 // console.log(this.homeYasParams) 266 // console.log(this.homeYasParams)
265 this.$store.dispatch('reportYas', { 267 this.$store.dispatch('reportYas', {
266 params: { 268 params: {
267 - param: {DATA:this.homeYasParams}, 269 + param: {DATA: this.homeYasParams},
268 appop: 'XY_UFO_SHOW_EVENT' 270 appop: 'XY_UFO_SHOW_EVENT'
269 } 271 }
270 }); 272 });
271 }, 273 },
272 reportTabYas() { 274 reportTabYas() {
273 let guessLikeTabParams = this.listYasParams; 275 let guessLikeTabParams = this.listYasParams;
  276 +
274 delete guessLikeTabParams.I_INDEX; 277 delete guessLikeTabParams.I_INDEX;
  278 +
275 // 防止重复上报 279 // 防止重复上报
276 - if(this.guessLikeId !== guessLikeTabParams.TAB_ID) {  
277 - this.guessLikeId = guessLikeTabParams.TAB_ID  
278 - console.log('guesslisttab',guessLikeTabParams) 280 + if (this.guessLikeId !== guessLikeTabParams.TAB_ID) {
  281 + this.guessLikeId = guessLikeTabParams.TAB_ID;
279 this.$store.dispatch('reportYas', { 282 this.$store.dispatch('reportYas', {
280 - params: {  
281 - param: guessLikeTabParams,  
282 - appop: 'XY_UFO_MAIN_EVENT'  
283 - }  
284 - }); 283 + params: {
  284 + param: guessLikeTabParams,
  285 + appop: 'XY_UFO_MAIN_EVENT'
  286 + }
  287 + });
285 } 288 }
286 }, 289 },
287 async guessLikeListParams(params) { 290 async guessLikeListParams(params) {
@@ -301,8 +304,10 @@ export default { @@ -301,8 +304,10 @@ export default {
301 this.active = Number(index); 304 this.active = Number(index);
302 this.isShow && this.$refs.scroll.scrollTo(this.navTop); 305 this.isShow && this.$refs.scroll.scrollTo(this.navTop);
303 await this.guessLikeListParams({index, ...params}); 306 await this.guessLikeListParams({index, ...params});
  307 +
304 // tab点击 308 // tab点击
305 - this.reportTabYas() 309 + this.reportTabYas();
  310 +
306 // 商品列表曝光 311 // 商品列表曝光
307 this.productList.list.length > 0 && this.listScrollY > 0 && this.$refs.product && this.$refs.product.yasShowEvent(this.yasHeight); 312 this.productList.list.length > 0 && this.listScrollY > 0 && this.$refs.product && this.$refs.product.yasShowEvent(this.yasHeight);
308 }, 313 },
@@ -326,8 +331,10 @@ export default { @@ -326,8 +331,10 @@ export default {
326 this.scrollY = -y; 331 this.scrollY = -y;
327 332
328 if (this.navTop) { 333 if (this.navTop) {
329 - this.isShow = (this.scrollY >= this.$refs.topSource.offsetHeight); 334 + this.isShow = (this.scrollY >= this.$refs.topSource.offsetHeight - 32);
330 } 335 }
  336 +
  337 + this.isFixSearch = (this.scrollY >= this.$refs.searchSource.offsetHeight);
331 }, 338 },
332 async refreshProductList(index) { 339 async refreshProductList(index) {
333 let str = get(get(this.navList, `[${index}].url`, '').split('?'), '[1]', ''); 340 let str = get(get(this.navList, `[${index}].url`, '').split('?'), '[1]', '');
@@ -386,27 +393,25 @@ export default { @@ -386,27 +393,25 @@ export default {
386 let {data} = result; 393 let {data} = result;
387 394
388 if (result.code === 200) { 395 if (result.code === 200) {
389 -  
390 data.endReached = (data.page === data.page_total) && (data.page_size !== 1) || !data.page_total; 396 data.endReached = (data.page === data.page_total) && (data.page_size !== 1) || !data.page_total;
391 -  
392 } 397 }
393 398
394 if (typeof data === 'object' && Object.keys(data).length) { 399 if (typeof data === 'object' && Object.keys(data).length) {
395 for (let key in data) { 400 for (let key in data) {
396 - if (key === 'product_list') {  
397 - list.list = data.page > 1 ? list.list.concat(data.product_list) : data.product_list;  
398 - } else {  
399 - list[key] = data[key];  
400 - }  
401 - if (!data.product_list) {  
402 - this.productList.list = []; 401 + if (data.hasOwnProperty(key)) {
  402 + if (key === 'product_list') {
  403 + list.list = data.page > 1 ? list.list.concat(data.product_list) : data.product_list;
  404 + } else {
  405 + list[key] = data[key];
  406 + }
  407 + if (!data.product_list) {
  408 + this.productList.list = [];
  409 + }
403 } 410 }
404 } 411 }
405 this.productList = list; 412 this.productList = list;
406 -  
407 } 413 }
408 } catch (e) { 414 } catch (e) {
409 - // console.log(e);  
410 if (this.productList.page <= 1) { 415 if (this.productList.page <= 1) {
411 this.productList.list = []; 416 this.productList.list = [];
412 } 417 }
@@ -458,6 +463,7 @@ export default { @@ -458,6 +463,7 @@ export default {
458 display: none; 463 display: none;
459 } 464 }
460 } 465 }
  466 +
461 .scroll-nav-wrap { 467 .scroll-nav-wrap {
462 position: relative; 468 position: relative;
463 background-color: #fefefe; 469 background-color: #fefefe;
@@ -465,6 +471,7 @@ export default { @@ -465,6 +471,7 @@ export default {
465 &.fixed-nav { 471 &.fixed-nav {
466 width: 100%; 472 width: 100%;
467 position: absolute; 473 position: absolute;
  474 + top: 64px;
468 z-index: 10; 475 z-index: 10;
469 overflow: hidden; 476 overflow: hidden;
470 } 477 }
@@ -487,16 +494,6 @@ export default { @@ -487,16 +494,6 @@ export default {
487 .channel-html { 494 .channel-html {
488 padding: 20px 24px 0; 495 padding: 20px 24px 0;
489 496
490 - // &:before {  
491 - // content: "";  
492 - // width: 520px;  
493 - // height: 28px;  
494 - // background-image: url("~statics/image/channel/service-info.png");  
495 - // background-size: 100% 100%;  
496 - // margin: 10px auto 20px;  
497 - // display: block;  
498 - // }  
499 -  
500 &:after { 497 &:after {
501 content: ""; 498 content: "";
502 width: 100%; 499 width: 100%;
@@ -520,18 +517,29 @@ export default { @@ -520,18 +517,29 @@ export default {
520 margin: 0 auto; 517 margin: 0 auto;
521 } 518 }
522 } 519 }
  520 +
523 .yohoufo-channel-page { 521 .yohoufo-channel-page {
524 /deep/ .cube-pullup-wrapper { 522 /deep/ .cube-pullup-wrapper {
525 background: #f2f2f2; 523 background: #f2f2f2;
526 } 524 }
527 } 525 }
  526 +
528 /deep/ .cube-scroll-nav-bar-item_active { 527 /deep/ .cube-scroll-nav-bar-item_active {
529 &:after { 528 &:after {
530 width: 16px; 529 width: 16px;
531 - // left: 50%;  
532 transform: translateX(-10px) 530 transform: translateX(-10px)
533 } 531 }
534 } 532 }
  533 +
  534 +.wrapper-search {
  535 + background: #fff;
  536 + padding: 0 24px;
  537 + width: 100%;
  538 + position: absolute;
  539 + z-index: 10;
  540 + overflow: hidden;
  541 +}
  542 +
535 .search-header { 543 .search-header {
536 height: 64px; 544 height: 64px;
537 background: #f5f5f5; 545 background: #f5f5f5;
@@ -561,6 +569,7 @@ input::-webkit-input-placeholder { @@ -561,6 +569,7 @@ input::-webkit-input-placeholder {
561 .middle { 569 .middle {
562 margin: 0 10px; 570 margin: 0 10px;
563 } 571 }
  572 +
564 .search-img { 573 .search-img {
565 width: 28px; 574 width: 28px;
566 height: 28px; 575 height: 28px;
@@ -568,9 +577,11 @@ input::-webkit-input-placeholder { @@ -568,9 +577,11 @@ input::-webkit-input-placeholder {
568 background: url(~statics/image/list/searchPage_icon@3x.png) no-repeat; 577 background: url(~statics/image/list/searchPage_icon@3x.png) no-repeat;
569 background-size: cover; 578 background-size: cover;
570 } 579 }
  580 +
571 .class-a { 581 .class-a {
572 padding-top: 104px; 582 padding-top: 104px;
573 } 583 }
  584 +
574 .hidden { 585 .hidden {
575 visibility: hidden; 586 visibility: hidden;
576 opacity: 0; 587 opacity: 0;