Authored by 肖亚东

首页逻辑修改 — review by 黄敬囿

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode, getResourceCode,getHomeContentCode} from '../../utils/home'; 2 import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode, getResourceCode,getHomeContentCode} from '../../utils/home';
3 import { shouldDiscardTap, getGoodDetailParam, getImageUrl, formatImageUrl,getGuangType, getYHStorageSync} from '../../utils/util'; 3 import { shouldDiscardTap, getGoodDetailParam, getImageUrl, formatImageUrl,getGuangType, getYHStorageSync} from '../../utils/util';
4 import homeService from './indexService.js' 4 import homeService from './indexService.js'
  5 +import { JUMP_BRAND, JUMP_DETAIL, JUMP_PRODUCTPOOL} from './indexService.js'
5 import { parseProductListData } from '../../utils/productListUtil'; 6 import { parseProductListData } from '../../utils/productListUtil';
6 import router from '../../router/index.js' 7 import router from '../../router/index.js'
7 8
@@ -18,6 +19,7 @@ let CHANNEL = "gender_channel" @@ -18,6 +19,7 @@ let CHANNEL = "gender_channel"
18 19
19 Page({ 20 Page({
20 data: { 21 data: {
  22 + lastTapTimeStamp: 0,
21 currentDate:null, 23 currentDate:null,
22 selectedChannel: 'boy', 24 selectedChannel: 'boy',
23 homelist:[], 25 homelist:[],
@@ -42,7 +44,7 @@ Page({ @@ -42,7 +44,7 @@ Page({
42 } 44 }
43 }, 45 },
44 }, 46 },
45 - onLoad: function () { 47 + onLoad: function (e) {
46 this.getLastChannel(); 48 this.getLastChannel();
47 this.fetchNewHomeData(); 49 this.fetchNewHomeData();
48 50
@@ -62,6 +64,60 @@ Page({ @@ -62,6 +64,60 @@ Page({
62 }); 64 });
63 this.showIndexDialog(); 65 this.showIndexDialog();
64 } 66 }
  67 +
  68 + let jumpType = e.jumpType;
  69 + if (jumpType == JUMP_BRAND) {
  70 + let brandId = e.brandId;
  71 + let brandName = e.brandName;
  72 + if (brandId != '' && brandName != '')
  73 + tt.navigateTo({
  74 + url: '../goodsList/brand?brandId=' + brandId + '&brandName=' + brandName + '&page_name=' + 'home' + '&page_param=' + ''
  75 + });
  76 + } else if (jumpType == JUMP_DETAIL) {
  77 + let productSkn = e.productSkn;
  78 + if (productSkn != '') {
  79 + tt.navigateTo({
  80 + url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + ''
  81 + });
  82 + }
  83 + } else if (jumpType == JUMP_PRODUCTPOOL) {
  84 + let productPool = e.productPool;
  85 + if (productPool != '') {
  86 + tt.navigateTo({
  87 + url: '../goodsList/productPool?productPool=' + productPool + '&page_name=' + 'home' + '&page_param=' + ''
  88 + });
  89 + }
  90 + }
  91 + },
  92 +
  93 + onShareAppMessage: function (res) {
  94 + let param = {
  95 + FROM: res.from,
  96 + SHARE_RESUIL: 0,
  97 + TITLE: 'Yoho!Buy有货-潮流购物逛不停',
  98 + PATH: '/pages/index/index',
  99 + }
  100 +
  101 + // 用户点击右上角分享
  102 + return {
  103 + title: param.TITLE, // 分享标题
  104 + desc: '精选1400+全球潮流品牌,明星潮牌和新锐原创品牌每日上新,100%正品行货。', // 分享描述
  105 + path: param.PATH, // 分享路径
  106 + success: function (res) {
  107 + // param.SHARE_RESUIL = 1
  108 + // logEvent(YB_SHARE_RESULT_L, param);
  109 + },
  110 + fail: function (res) {
  111 + // param.SHARE_RESUIL = 2
  112 + // logEvent(YB_SHARE_RESULT_L, param);
  113 + }
  114 + }
  115 + },
  116 +
  117 + onPullDownRefresh: function () {
  118 + tt.stopPullDownRefresh();
  119 + this.getLastChannel();
  120 + this.fetchNewHomeData(true);
65 }, 121 },
66 122
67 //获取新首页数据 123 //获取新首页数据
@@ -86,10 +142,11 @@ Page({ @@ -86,10 +142,11 @@ Page({
86 // union_id: app.globalData.WXUnion_ID || this.getStorage('unionID') 142 // union_id: app.globalData.WXUnion_ID || this.getStorage('unionID')
87 } 143 }
88 144
  145 + let that = this;
89 homeService.getHomeFloorlist(params) 146 homeService.getHomeFloorlist(params)
90 .then(json => { 147 .then(json => {
91 148
92 - this.setLoadingHomeData(false); 149 + that.setLoadingHomeData(false);
93 150
94 if (json && json.code && json.code == 200) { 151 if (json && json.code && json.code == 200) {
95 let homeList = json.data.list; 152 let homeList = json.data.list;
@@ -102,17 +159,17 @@ Page({ @@ -102,17 +159,17 @@ Page({
102 duration: 1500 159 duration: 1500
103 }); 160 });
104 } 161 }
105 - let newChannels = this.data.newChannels; 162 + let newChannels = that.data.newChannels;
106 let currentData = newChannels[channel]; 163 let currentData = newChannels[channel];
107 currentData.data = homeList; 164 currentData.data = homeList;
108 newChannels[channel] = currentData; 165 newChannels[channel] = currentData;
109 166
110 - this.setData({ 167 + that.setData({
111 newChannels: newChannels 168 newChannels: newChannels
112 }) 169 })
113 - this.setHomeList(force); 170 + that.setHomeList(force);
114 } else { 171 } else {
115 - this.setHomeList(force); 172 + that.setHomeList(force);
116 tt.showToast({ 173 tt.showToast({
117 title: json.message, 174 title: json.message,
118 icon: 'none', 175 icon: 'none',
@@ -121,8 +178,8 @@ Page({ @@ -121,8 +178,8 @@ Page({
121 } 178 }
122 }) 179 })
123 .catch(error => { 180 .catch(error => {
124 - this.setLoadingHomeData(false);  
125 - this.setHomeList(force); 181 + that.setLoadingHomeData(false);
  182 + that.setHomeList(force);
126 183
127 tt.showToast({ 184 tt.showToast({
128 title: error.message, 185 title: error.message,
@@ -237,27 +294,63 @@ Page({ @@ -237,27 +294,63 @@ Page({
237 * 首页资源位dialog 294 * 首页资源位dialog
238 */ 295 */
239 showIndexDialog: function(){ 296 showIndexDialog: function(){
240 - // var app = getApp();  
241 - // let that = this;  
242 - // let content_code = "0ddd512196d6eb4a571dc3281e0b2692";  
243 -  
244 - // let param = {  
245 - // content_code,  
246 - // }  
247 - // GET(API_HOST + '/operations/api/v5/resource/get', param).then(json => {  
248 - // // console.log(json);  
249 - // if (json && json.code && json.code == 200 && json.data[0] && json.data[0].data[0] && json.data[0].data[0].url){  
250 - // this.setStorage('pretimestamp', Date.parse(that.data.currentDate));  
251 - // that.setData({  
252 - // dialogSrc: formatImageUrl(json.data[0].data[0].src, 340 * app.globalData.systemInfo.pixelRatio, 340 * app.globalData.systemInfo.pixelRatio,2),  
253 - // dialogUrl: json.data[0].data[0].url,  
254 - // });  
255 - // that.setStorage('pretimestamp', Date.parse(that.data.currentDate));  
256 - // that.dialog.showDialog();  
257 - // }  
258 - // }).catch(error => { }); 297 + var app = getApp();
  298 + let that = this;
  299 + homeService.getIndexDialog({})
  300 + .then(json => {
  301 + // console.log(json);
  302 + if (json && json.code && json.code == 200 && json.data[0] && json.data[0].data[0] && json.data[0].data[0].url){
  303 + that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
  304 + that.setData({
  305 + dialogSrc: formatImageUrl(json.data[0].data[0].src, 340 * app.globalData.systemInfo.pixelRatio, 340 * app.globalData.systemInfo.pixelRatio,2),
  306 + dialogUrl: json.data[0].data[0].url,
  307 + });
  308 + that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
  309 + that.dialog.showDialog();
  310 + }
  311 + }).catch(error => { });
259 }, 312 },
260 313
  314 + /*
  315 + 首次点击,判断是否是新人(默认是新人):
  316 + (1)是新人,弹框授权,跳链接 (2)不是新人,显示提示,不跳转
  317 + */
  318 + getPhoneNumber: function (e) {
  319 + if (this.getStorage('newCustomer')) {
  320 + this.jumpByRuleEvent(e);
  321 + return;
  322 + }
  323 + if (e.detail.errMsg === 'getPhoneNumber:ok') {
  324 + decodePhoneNumber(e.detail.iv, e.detail.encryptedData, '', (result) => {
  325 + if (result.code === 200) { // 首次授权的新人
  326 + //新注册用户
  327 + if (result.is_register){
  328 + that.showZanToast({
  329 + title:'欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收',success: function() {
  330 + // 新人楼层标示newCustomer
  331 + this.setStorage('newCustomer', true);
  332 + this.jumpByRuleEvent(e);
  333 + }},1500);
  334 + } else {
  335 + // 新人楼层标示newCustomer
  336 + this.setStorage('newCustomer', true);
  337 + this.jumpByRuleEvent(e);
  338 + }
  339 + } else { // 不是新人,提示
  340 + tt.showModal({
  341 + title: '提示',
  342 + content: '活动仅限新用户参加',
  343 + showCancel: false
  344 + });
  345 + }
  346 + })
  347 + } else { // 取消手机号授权
  348 + tt.navigateTo({
  349 + url: '../bindPhoneNumber/bindPhoneNumber',
  350 + })
  351 + }
  352 +},
  353 +
261 //获取上次切换的频道 默认显示上次频道 354 //获取上次切换的频道 默认显示上次频道
262 getLastChannel: function () { 355 getLastChannel: function () {
263 let lastChannel = getYHStorageSync(CHANNEL,'index'); 356 let lastChannel = getYHStorageSync(CHANNEL,'index');
@@ -333,10 +426,12 @@ Page({ @@ -333,10 +426,12 @@ Page({
333 }, 426 },
334 427
335 jumpToYohood:function(event){ 428 jumpToYohood:function(event){
336 - // jumpByUrl("https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018&openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"title\":\"YOHOOD2018\",\"share_id\":5381,\"url\":\"https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018\"}}")  
337 - // this.setData({  
338 - // channelSelect: false  
339 - // }); 429 +
  430 + router.goUrl("https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018&openby:yohobuy={\"action\":\"go.h5\",\"params\":{\"title\":\"YOHOOD2018\",\"share_id\":5381,\"url\":\"https://ad.yoho.cn/html5/2018/yohood/index.html?share_id=5381&title=YOHOOD2018\"}}");
  431 +
  432 + this.setData({
  433 + channelSelect: false
  434 + });
340 }, 435 },
341 436
342 //formId上报 437 //formId上报
@@ -371,6 +466,44 @@ Page({ @@ -371,6 +466,44 @@ Page({
371 }) 466 })
372 }, 467 },
373 468
  469 + scanCodeTapped() {
  470 +
  471 + tt.scanCode({
  472 + success: (res) => {
  473 + let url = res.path;
  474 +
  475 + if (url) {
  476 + url = url.indexOf('page/subPackage') !== -1 ? '/' + url : url.replace(/pages/g, "..");
  477 + tt.navigateTo({
  478 + url: url,
  479 + });
  480 + } else {
  481 + let hasOpenby = url.indexOf('openby:yohobuy=');
  482 +
  483 + url = res.result;
  484 +
  485 + if (hasOpenby < 0) {
  486 + if (url.startsWith('https://m.yohobuy.com/product') || url.startsWith('http://m.yohobuy.com/product') || url.startsWith('https://o.yohobuy.com/mp') || url.startsWith('https://o.yohobuy.com/mp')) {
  487 + tt.navigateTo({
  488 + url: '/pages/goodsDetail/goodsDetail?q=' + url
  489 + });
  490 + } else if (url.startsWith('https://m.yohobuy.com/shop') || url.startsWith('http://m.yohobuy.com/shop')) {
  491 + tt.navigateTo({
  492 + url: '/pages/goodsList/brandStore?q=' + url
  493 + });
  494 + }
  495 + } else {
  496 + router.goUrl(url);
  497 + }
  498 + }
  499 +
  500 + logEvent(YB_SCAN_CODE_SUCCESS, {
  501 + PAGE_PATH: url,
  502 + });
  503 + }
  504 + })
  505 + },
  506 +
374 // 清除storage 507 // 清除storage
375 removeStorage: function(key) { 508 removeStorage: function(key) {
376 try { 509 try {
@@ -390,12 +523,6 @@ Page({ @@ -390,12 +523,6 @@ Page({
390 } catch (e) { 523 } catch (e) {
391 // console.error(e); 524 // console.error(e);
392 } 525 }
393 - },  
394 -  
395 - onPullDownRefresh: function () {  
396 - tt.stopPullDownRefresh();  
397 - this.getLastChannel();  
398 - this.fetchNewHomeData(true);  
399 - }, 526 + }
400 527
401 }) 528 })
1 import api from '../../common/api.js'; 1 import api from '../../common/api.js';
2 import { getGoodDetailParam,getImageUrl } from '../../utils/util'; 2 import { getGoodDetailParam,getImageUrl } from '../../utils/util';
3 3
  4 +export const JUMP_BRAND = 'go.brand';
  5 +export const JUMP_DETAIL = 'go.detail';
  6 +export const JUMP_PRODUCTPOOL = 'go.poollist';
  7 +
4 export function getHomeFloorlist(params) { 8 export function getHomeFloorlist(params) {
5 return api.get({ 9 return api.get({
6 url: '/operations/api/v5/resource/home', 10 url: '/operations/api/v5/resource/home',
@@ -24,6 +28,17 @@ export function getProductlist(params) { @@ -24,6 +28,17 @@ export function getProductlist(params) {
24 }); 28 });
25 } 29 }
26 30
  31 +// 首页轮播图
  32 +export function getIndexDialog(params) {
  33 + return api.get({
  34 + url: '/operations/api/v5/resource/get',
  35 + data: {
  36 + ...params,
  37 + content_code: "0ddd512196d6eb4a571dc3281e0b2692",
  38 + },
  39 +});
  40 +}
  41 +
27 export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, listImageHeight){ 42 export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, listImageHeight){
28 let newList=[]; 43 let newList=[];
29 let index = 1; 44 let index = 1;
@@ -145,5 +160,6 @@ export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, l @@ -145,5 +160,6 @@ export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, l
145 export default { 160 export default {
146 getHomeFloorlist, 161 getHomeFloorlist,
147 parseHomeList, 162 parseHomeList,
148 - getProductlist 163 + getProductlist,
  164 + getIndexDialog
149 }; 165 };
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 <view class="view-splite clearfix"> 56 <view class="view-splite clearfix">
57 </view> 57 </view>
58 58
59 - <view class='address-back-view'style='border-top:0' bindtap='couponTapAction'> 59 + <!-- <view class='address-back-view'style='border-top:0' bindtap='couponTapAction'>
60 <view class='address-left-back-view'> 60 <view class='address-left-back-view'>
61 <view class="left-icon-image"> 61 <view class="left-icon-image">
62 <image src="../../images/yhq-ic@2x.png" class="icon-image"></image> 62 <image src="../../images/yhq-ic@2x.png" class="icon-image"></image>
@@ -79,7 +79,7 @@ @@ -79,7 +79,7 @@
79 79
80 <view class='arrow-text' style='margin-right:20rpx'>{{infoNum.yoho_coin_num?infoNum.yoho_coin_num:0}}个</view> 80 <view class='arrow-text' style='margin-right:20rpx'>{{infoNum.yoho_coin_num?infoNum.yoho_coin_num:0}}个</view>
81 81
82 - </view> 82 + </view> -->
83 83
84 <view class='address-back-view' style='border-top:0;border-bottom:0' bindtap='navToAddressManagerPage'> 84 <view class='address-back-view' style='border-top:0;border-bottom:0' bindtap='navToAddressManagerPage'>
85 <view class='address-left-back-view'> 85 <view class='address-left-back-view'>
@@ -103,24 +103,9 @@ @@ -103,24 +103,9 @@
103 103
104 <image class='arrow-image' src='../../images/arrow_right@2x.png'></image> 104 <image class='arrow-image' src='../../images/arrow_right@2x.png'></image>
105 </view> 105 </view>
106 - <view class='address-back-view' style='border-bottom:0' tt:if="{{isWechatService}}">  
107 - <view class='address-left-back-view'>  
108 - <view class="left-icon-image">  
109 - <image src="../../images/tt@2x.png" class="icon-image"></image>  
110 - </view>  
111 - <view class="address-title">潮流顾问专属分享</view>  
112 - </view>  
113 - <text class="arrow-text">分享</text>  
114 - <image class='arrow-image' src='../../images/arrow_right@2x.png'></image>  
115 - <button open-type="share" class="share-btn" plain="true" hover-class="none" id="wxRedPacket"></button>  
116 - </view> 106 +
117 <view class="view-splite clearfix"/> 107 <view class="view-splite clearfix"/>
118 - <!-- 猜你喜欢标题 -->  
119 - <!-- <view class="sectionContainer">  
120 - <view class="sectionLine"></view>  
121 - <view class="sectionTitle">猜你喜欢</view>  
122 - <view class="sectionLine"></view>  
123 - </view> --> 108 +
124 <view class='titleContainer'> 109 <view class='titleContainer'>
125 <view class='titleLine'></view> 110 <view class='titleLine'></view>
126 <view class='titleDesc'> 猜你喜欢</view> 111 <view class='titleDesc'> 猜你喜欢</view>
@@ -132,17 +117,6 @@ @@ -132,17 +117,6 @@
132 <productListCell item="{{item}}" page-name="{{current_page_name}}"></productListCell> 117 <productListCell item="{{item}}" page-name="{{current_page_name}}"></productListCell>
133 </block> 118 </block>
134 </view> 119 </view>
135 -  
136 - <view class="my-service" style="display:none">  
137 - <view class="service-type clearfix">  
138 - <text class="service-text">更多优质服务,您可以选择:\n1.关注微信服务号“ YOHOBUY有货”咨询在线客服\n2.拨打 400-889-9646 电话客服</text>  
139 - </view>  
140 - </view>  
141 </view> 120 </view>
142 </view> 121 </view>
143 </scroll-view> 122 </scroll-view>
144 -<!-- <quickNavigation id="quickNavigation" isShowIndicator="{{isShowIndicator}}" isShowShopCart="{{true}}" isShowMenu="{{false}}" marginBottom="{{50}}" bind:backToTop="backToTop"></quickNavigation>  
145 -<import src="../../vendors/toast/wetoast.wxml" />  
146 -<template is="wetoast" data="{{...__wetoast__}}" />  
147 -<import src="../../vendors/zanui/toast/index.wxml"/>  
148 -<template is="zan-toast" data="{{zanToast}}"/> -->