Authored by 肖亚东

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

... ... @@ -2,6 +2,7 @@
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode, getResourceCode,getHomeContentCode} from '../../utils/home';
import { shouldDiscardTap, getGoodDetailParam, getImageUrl, formatImageUrl,getGuangType, getYHStorageSync} from '../../utils/util';
import homeService from './indexService.js'
import { JUMP_BRAND, JUMP_DETAIL, JUMP_PRODUCTPOOL} from './indexService.js'
import { parseProductListData } from '../../utils/productListUtil';
import router from '../../router/index.js'
... ... @@ -18,6 +19,7 @@ let CHANNEL = "gender_channel"
Page({
data: {
lastTapTimeStamp: 0,
currentDate:null,
selectedChannel: 'boy',
homelist:[],
... ... @@ -42,7 +44,7 @@ Page({
}
},
},
onLoad: function () {
onLoad: function (e) {
this.getLastChannel();
this.fetchNewHomeData();
... ... @@ -62,6 +64,60 @@ Page({
});
this.showIndexDialog();
}
let jumpType = e.jumpType;
if (jumpType == JUMP_BRAND) {
let brandId = e.brandId;
let brandName = e.brandName;
if (brandId != '' && brandName != '')
tt.navigateTo({
url: '../goodsList/brand?brandId=' + brandId + '&brandName=' + brandName + '&page_name=' + 'home' + '&page_param=' + ''
});
} else if (jumpType == JUMP_DETAIL) {
let productSkn = e.productSkn;
if (productSkn != '') {
tt.navigateTo({
url: '../goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + 'home' + '&page_param=' + ''
});
}
} else if (jumpType == JUMP_PRODUCTPOOL) {
let productPool = e.productPool;
if (productPool != '') {
tt.navigateTo({
url: '../goodsList/productPool?productPool=' + productPool + '&page_name=' + 'home' + '&page_param=' + ''
});
}
}
},
onShareAppMessage: function (res) {
let param = {
FROM: res.from,
SHARE_RESUIL: 0,
TITLE: 'Yoho!Buy有货-潮流购物逛不停',
PATH: '/pages/index/index',
}
// 用户点击右上角分享
return {
title: param.TITLE, // 分享标题
desc: '精选1400+全球潮流品牌,明星潮牌和新锐原创品牌每日上新,100%正品行货。', // 分享描述
path: param.PATH, // 分享路径
success: function (res) {
// param.SHARE_RESUIL = 1
// logEvent(YB_SHARE_RESULT_L, param);
},
fail: function (res) {
// param.SHARE_RESUIL = 2
// logEvent(YB_SHARE_RESULT_L, param);
}
}
},
onPullDownRefresh: function () {
tt.stopPullDownRefresh();
this.getLastChannel();
this.fetchNewHomeData(true);
},
//获取新首页数据
... ... @@ -86,10 +142,11 @@ Page({
// union_id: app.globalData.WXUnion_ID || this.getStorage('unionID')
}
let that = this;
homeService.getHomeFloorlist(params)
.then(json => {
this.setLoadingHomeData(false);
that.setLoadingHomeData(false);
if (json && json.code && json.code == 200) {
let homeList = json.data.list;
... ... @@ -102,17 +159,17 @@ Page({
duration: 1500
});
}
let newChannels = this.data.newChannels;
let newChannels = that.data.newChannels;
let currentData = newChannels[channel];
currentData.data = homeList;
newChannels[channel] = currentData;
this.setData({
that.setData({
newChannels: newChannels
})
this.setHomeList(force);
that.setHomeList(force);
} else {
this.setHomeList(force);
that.setHomeList(force);
tt.showToast({
title: json.message,
icon: 'none',
... ... @@ -121,8 +178,8 @@ Page({
}
})
.catch(error => {
this.setLoadingHomeData(false);
this.setHomeList(force);
that.setLoadingHomeData(false);
that.setHomeList(force);
tt.showToast({
title: error.message,
... ... @@ -237,27 +294,63 @@ Page({
* 首页资源位dialog
*/
showIndexDialog: function(){
// var app = getApp();
// let that = this;
// let content_code = "0ddd512196d6eb4a571dc3281e0b2692";
// let param = {
// content_code,
// }
// GET(API_HOST + '/operations/api/v5/resource/get', param).then(json => {
// // console.log(json);
// if (json && json.code && json.code == 200 && json.data[0] && json.data[0].data[0] && json.data[0].data[0].url){
// this.setStorage('pretimestamp', Date.parse(that.data.currentDate));
// that.setData({
// dialogSrc: formatImageUrl(json.data[0].data[0].src, 340 * app.globalData.systemInfo.pixelRatio, 340 * app.globalData.systemInfo.pixelRatio,2),
// dialogUrl: json.data[0].data[0].url,
// });
// that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
// that.dialog.showDialog();
// }
// }).catch(error => { });
var app = getApp();
let that = this;
homeService.getIndexDialog({})
.then(json => {
// console.log(json);
if (json && json.code && json.code == 200 && json.data[0] && json.data[0].data[0] && json.data[0].data[0].url){
that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
that.setData({
dialogSrc: formatImageUrl(json.data[0].data[0].src, 340 * app.globalData.systemInfo.pixelRatio, 340 * app.globalData.systemInfo.pixelRatio,2),
dialogUrl: json.data[0].data[0].url,
});
that.setStorage('pretimestamp', Date.parse(that.data.currentDate));
that.dialog.showDialog();
}
}).catch(error => { });
},
/*
首次点击,判断是否是新人(默认是新人):
(1)是新人,弹框授权,跳链接 (2)不是新人,显示提示,不跳转
*/
getPhoneNumber: function (e) {
if (this.getStorage('newCustomer')) {
this.jumpByRuleEvent(e);
return;
}
if (e.detail.errMsg === 'getPhoneNumber:ok') {
decodePhoneNumber(e.detail.iv, e.detail.encryptedData, '', (result) => {
if (result.code === 200) { // 首次授权的新人
//新注册用户
if (result.is_register){
that.showZanToast({
title:'欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收',success: function() {
// 新人楼层标示newCustomer
this.setStorage('newCustomer', true);
this.jumpByRuleEvent(e);
}},1500);
} else {
// 新人楼层标示newCustomer
this.setStorage('newCustomer', true);
this.jumpByRuleEvent(e);
}
} else { // 不是新人,提示
tt.showModal({
title: '提示',
content: '活动仅限新用户参加',
showCancel: false
});
}
})
} else { // 取消手机号授权
tt.navigateTo({
url: '../bindPhoneNumber/bindPhoneNumber',
})
}
},
//获取上次切换的频道 默认显示上次频道
getLastChannel: function () {
let lastChannel = getYHStorageSync(CHANNEL,'index');
... ... @@ -333,10 +426,12 @@ Page({
},
jumpToYohood:function(event){
// 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\"}}")
// this.setData({
// channelSelect: false
// });
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\"}}");
this.setData({
channelSelect: false
});
},
//formId上报
... ... @@ -371,6 +466,44 @@ Page({
})
},
scanCodeTapped() {
tt.scanCode({
success: (res) => {
let url = res.path;
if (url) {
url = url.indexOf('page/subPackage') !== -1 ? '/' + url : url.replace(/pages/g, "..");
tt.navigateTo({
url: url,
});
} else {
let hasOpenby = url.indexOf('openby:yohobuy=');
url = res.result;
if (hasOpenby < 0) {
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')) {
tt.navigateTo({
url: '/pages/goodsDetail/goodsDetail?q=' + url
});
} else if (url.startsWith('https://m.yohobuy.com/shop') || url.startsWith('http://m.yohobuy.com/shop')) {
tt.navigateTo({
url: '/pages/goodsList/brandStore?q=' + url
});
}
} else {
router.goUrl(url);
}
}
logEvent(YB_SCAN_CODE_SUCCESS, {
PAGE_PATH: url,
});
}
})
},
// 清除storage
removeStorage: function(key) {
try {
... ... @@ -390,12 +523,6 @@ Page({
} catch (e) {
// console.error(e);
}
},
onPullDownRefresh: function () {
tt.stopPullDownRefresh();
this.getLastChannel();
this.fetchNewHomeData(true);
},
}
})
... ...
import api from '../../common/api.js';
import { getGoodDetailParam,getImageUrl } from '../../utils/util';
export const JUMP_BRAND = 'go.brand';
export const JUMP_DETAIL = 'go.detail';
export const JUMP_PRODUCTPOOL = 'go.poollist';
export function getHomeFloorlist(params) {
return api.get({
url: '/operations/api/v5/resource/home',
... ... @@ -24,6 +28,17 @@ export function getProductlist(params) {
});
}
// 首页轮播图
export function getIndexDialog(params) {
return api.get({
url: '/operations/api/v5/resource/get',
data: {
...params,
content_code: "0ddd512196d6eb4a571dc3281e0b2692",
},
});
}
export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, listImageHeight){
let newList=[];
let index = 1;
... ... @@ -145,5 +160,6 @@ export function parseHomeList(json, windowWidth, windowHeight, listImageWidth, l
export default {
getHomeFloorlist,
parseHomeList,
getProductlist
getProductlist,
getIndexDialog
};
... ...
... ... @@ -56,7 +56,7 @@
<view class="view-splite clearfix">
</view>
<view class='address-back-view'style='border-top:0' bindtap='couponTapAction'>
<!-- <view class='address-back-view'style='border-top:0' bindtap='couponTapAction'>
<view class='address-left-back-view'>
<view class="left-icon-image">
<image src="../../images/yhq-ic@2x.png" class="icon-image"></image>
... ... @@ -79,7 +79,7 @@
<view class='arrow-text' style='margin-right:20rpx'>{{infoNum.yoho_coin_num?infoNum.yoho_coin_num:0}}个</view>
</view>
</view> -->
<view class='address-back-view' style='border-top:0;border-bottom:0' bindtap='navToAddressManagerPage'>
<view class='address-left-back-view'>
... ... @@ -103,24 +103,9 @@
<image class='arrow-image' src='../../images/arrow_right@2x.png'></image>
</view>
<view class='address-back-view' style='border-bottom:0' tt:if="{{isWechatService}}">
<view class='address-left-back-view'>
<view class="left-icon-image">
<image src="../../images/tt@2x.png" class="icon-image"></image>
</view>
<view class="address-title">潮流顾问专属分享</view>
</view>
<text class="arrow-text">分享</text>
<image class='arrow-image' src='../../images/arrow_right@2x.png'></image>
<button open-type="share" class="share-btn" plain="true" hover-class="none" id="wxRedPacket"></button>
</view>
<view class="view-splite clearfix"/>
<!-- 猜你喜欢标题 -->
<!-- <view class="sectionContainer">
<view class="sectionLine"></view>
<view class="sectionTitle">猜你喜欢</view>
<view class="sectionLine"></view>
</view> -->
<view class='titleContainer'>
<view class='titleLine'></view>
<view class='titleDesc'> 猜你喜欢</view>
... ... @@ -128,21 +113,10 @@
<!--猜你喜欢列表-->
<view class="likeContainer">
<block tt:for="{{recommdData}}" tt:key="{{index}}">
<productListCell item="{{item}}" page-name="{{current_page_name}}"></productListCell>
</block>
</view>
<view class="my-service" style="display:none">
<view class="service-type clearfix">
<text class="service-text">更多优质服务,您可以选择:\n1.关注微信服务号“ YOHOBUY有货”咨询在线客服\n2.拨打 400-889-9646 电话客服</text>
</view>
<block tt:for="{{recommdData}}" tt:key="{{index}}">
<productListCell item="{{item}}" page-name="{{current_page_name}}"></productListCell>
</block>
</view>
</view>
</view>
</scroll-view>
<!-- <quickNavigation id="quickNavigation" isShowIndicator="{{isShowIndicator}}" isShowShopCart="{{true}}" isShowMenu="{{false}}" marginBottom="{{50}}" bind:backToTop="backToTop"></quickNavigation>
<import src="../../vendors/toast/wetoast.wxml" />
<template is="wetoast" data="{{...__wetoast__}}" />
<import src="../../vendors/zanui/toast/index.wxml"/>
<template is="zan-toast" data="{{zanToast}}"/> -->
\ No newline at end of file
... ...