|
|
// pages/choosecountry/choosecountry.js
|
|
|
'use strict';
|
|
|
import { API_HOST, SERVICE_HOST } from '../../libs/config';
|
|
|
import { GET, POST } from '../../libs/request';
|
|
|
import { getVerifyKey, bindAction, decodePhoneNumber, getUnionID, decodeUnionId, openAuthorizeSettings} from '../../utils/login';
|
|
|
|
|
|
|
|
|
let CHOOSED_COUNTRY_ID = 'CHOOSED_COUNTRY_ID'
|
|
|
let CHOOSED_COUNTRY_NAME = 'CHOOSED_COUNTRY_NAME'
|
|
|
let app = getApp();
|
|
|
const {extend,Toast} = require('../../vendors/zanui/index');
|
|
|
|
|
|
Page(extend({},Toast,{
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
country_name:'中国',
|
|
|
country_area:'86',
|
|
|
phoneNum:'',
|
|
|
verifyBtnText:'获取验证码',
|
|
|
counting:false,
|
|
|
verifyCode:'',
|
|
|
hasUnionID:'',
|
|
|
inviteCode: '',
|
|
|
h5back:'',
|
|
|
graphicsCodeSwitch: false,
|
|
|
graphicsCodeUrl: '',
|
|
|
tipText:'Yoho!Family账号可登录YOHO!旗下所有应用(含:Yoho!Buy有货、Yoho!Now、mars、BLK、Yoho!Store)',
|
|
|
graphicsCodeElement: [
|
|
|
{
|
|
|
// position: '0px 0px',
|
|
|
dataVal: 0,
|
|
|
},
|
|
|
{
|
|
|
// position: '-80px 0px',
|
|
|
dataVal: 0,
|
|
|
},
|
|
|
{
|
|
|
// position: '-160px 0px',
|
|
|
dataVal: 0,
|
|
|
},
|
|
|
{
|
|
|
// position: '-240px 0px',
|
|
|
dataVal: 0,
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
// console.log("options",options)
|
|
|
var inviteCode = options.inviteCode ? options.inviteCode : '';
|
|
|
var h5back = options.h5back ? options.h5back:'';
|
|
|
this.setData({
|
|
|
hasUnionID: app.globalData.WXUnion_ID !== null && app.globalData.WXUnion_ID !== '' && app.globalData.WXUnion_ID !== undefined ? true:false,
|
|
|
inviteCode,
|
|
|
h5back,
|
|
|
})
|
|
|
new app.WeToast();
|
|
|
|
|
|
this.fetchImageCheck_SwitchOn();
|
|
|
},
|
|
|
|
|
|
onShow: function () {
|
|
|
let that = this;
|
|
|
wx.getStorage({
|
|
|
key: CHOOSED_COUNTRY_ID,
|
|
|
success: function (res) {
|
|
|
if (res.data.length>0) {
|
|
|
// console.log(res.data)
|
|
|
that.setData({ country_area: res.data});
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
wx.getStorage({
|
|
|
key: CHOOSED_COUNTRY_NAME,
|
|
|
success: function (res) {
|
|
|
if (res.data.length > 0) {
|
|
|
// console.log(res.data)
|
|
|
that.setData({ country_name : res.data});
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
|
fetchImageCheck_SwitchOn: function (event) {
|
|
|
let app = getApp();
|
|
|
let that = this;
|
|
|
let udid = app && app.globalData && app.globalData.udid ? app.globalData.udid : '';
|
|
|
var timeStamp = Date.parse(new Date());
|
|
|
|
|
|
let param = {
|
|
|
fromPage: 'bindPhoneNumber',
|
|
|
}
|
|
|
GET(API_HOST +'/smart/way', param)
|
|
|
.then(data => {
|
|
|
let graphicsCodeSwitch = data.data;
|
|
|
let graphicsCodeUrl = API_HOST + '/passport/img-check' + '?business_line=miniapp' + '&udid=' + udid + '&fromPage=' + 'bindPhoneNumber' + '&timeStamp=' + timeStamp;
|
|
|
that.setData({
|
|
|
graphicsCodeSwitch,
|
|
|
graphicsCodeUrl,
|
|
|
})
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
},
|
|
|
|
|
|
// calcPosition: function (i, dataVal) {
|
|
|
// let positionX, positionY;
|
|
|
// let index = i;
|
|
|
// let count = parseInt(dataVal, 10) + 1;
|
|
|
// let unit = 'px';
|
|
|
// positionX = -index * 80 + unit;
|
|
|
// positionY = -count * 80 + unit;
|
|
|
// return [positionX, positionY].join(' ');
|
|
|
// },
|
|
|
|
|
|
didSelectImage: function (e) {
|
|
|
let index = e.currentTarget.dataset.itemindex;
|
|
|
let graphicsCodeElement = this.data.graphicsCodeElement;
|
|
|
let elem = graphicsCodeElement[index];
|
|
|
let dataVal = (parseInt(elem.dataVal)) % 4 + 1;
|
|
|
// let position = this.calcPosition(index, elem.dataVal);
|
|
|
// elem.position = position;
|
|
|
elem.dataVal = dataVal;
|
|
|
this.setData({graphicsCodeElement});
|
|
|
},
|
|
|
|
|
|
update: function (event) {
|
|
|
var timeStamp = Date.parse(new Date());
|
|
|
let udid = app && app.globalData && app.globalData.udid ? app.globalData.udid : '';
|
|
|
let graphicsCodeUrl = API_HOST + '/passport/img-check' + '?business_line=miniapp' + '&udid=' + udid + '&fromPage=' + 'bindPhoneNumber' + '&timeStamp=' + timeStamp;
|
|
|
console.log(graphicsCodeUrl)
|
|
|
this.setData({
|
|
|
graphicsCodeUrl,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 新的授权方式
|
|
|
*/
|
|
|
getUserInfo: function (e) {
|
|
|
var that = this;
|
|
|
if (e.detail.errMsg === 'getUserInfo:ok') {
|
|
|
decodeUnionId(app.getWechatThirdSession(), e, function (response) {
|
|
|
if (response.isHaveUnionID) {
|
|
|
that.setData({
|
|
|
hasUnionID: true,
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
openAuthorizeSettings(function (response) {
|
|
|
if (response.isHaveUnionID) {
|
|
|
that.setData({
|
|
|
hasUnionID: true,
|
|
|
})
|
|
|
};
|
|
|
if (response.succeed === true) {
|
|
|
} else {
|
|
|
// console.log("根据unionid没有查询到uid,需要再次点击授权getPhoneNumber")
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
getPhoneNumber: function (e) {
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
// console.log(e)
|
|
|
// console.log(e.detail.errMsg)
|
|
|
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
|
|
decodePhoneNumber(e.detail.iv, e.detail.encryptedData, '', function (result) {
|
|
|
// console.log('!!!!result', result)
|
|
|
if (result.code != 200) {
|
|
|
that.wetoast.toast({
|
|
|
title: result.message,
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1000
|
|
|
});
|
|
|
} else {
|
|
|
if(result.succeed){
|
|
|
//如果是从h5页面唤起,则重新用webview 打开h5链接;其他页面直接返回上一层
|
|
|
if (that.data.h5back){
|
|
|
wx.setStorageSync('h5backReload', that.data.h5back);
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
});
|
|
|
}else{
|
|
|
if (result.is_register){
|
|
|
that.showZanToast({
|
|
|
title: '欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收', success: function () {
|
|
|
let prePage = getCurrentPages();
|
|
|
that.newCustomerStorage();
|
|
|
if (prePage.length > 1 && prePage[prePage.length - 2].bindPhoneNumComplete != undefined) {
|
|
|
prePage[prePage.length - 2].bindPhoneNumComplete();
|
|
|
}
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
}
|
|
|
}, 1500);
|
|
|
} else {
|
|
|
let prePage = getCurrentPages();
|
|
|
that.newCustomerStorage();
|
|
|
if (prePage.length > 1 && prePage[prePage.length - 2].bindPhoneNumComplete != undefined) {
|
|
|
prePage[prePage.length - 2].bindPhoneNumComplete();
|
|
|
}
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
// let needBind = true;
|
|
|
// that.setData({ needBind });
|
|
|
// that.loginAndRegisterTapped(true);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
chooseCountry:function(){
|
|
|
wx.navigateTo({
|
|
|
url: '/pagesSecond/pages/choosecountry/choosecountry',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
getVerifyCode:function() {
|
|
|
let that = this
|
|
|
if (that.data.counting) {
|
|
|
return;
|
|
|
}
|
|
|
that.data.counting = true;
|
|
|
|
|
|
if (that.data.phoneNum == "" || that.data.phoneNum == undefined || that.data.phoneNum == null) {
|
|
|
that.wetoast.toast({
|
|
|
title: "手机号不能为空",
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1500
|
|
|
});
|
|
|
|
|
|
that.data.counting = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let fromPage = 'bindPhoneNumber';
|
|
|
let degrees = '';
|
|
|
for (var i = 0; i < that.data.graphicsCodeElement.length; i++) {
|
|
|
let item = that.data.graphicsCodeElement[i];
|
|
|
let dataVal = item.dataVal;
|
|
|
if (i == 0){
|
|
|
degrees = dataVal + ','
|
|
|
} else if (i == that.data.graphicsCodeElement.length - 1){
|
|
|
degrees = degrees + '' + dataVal;
|
|
|
} else {
|
|
|
degrees = degrees + '' + dataVal + ',';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
getVerifyKey(that.data.phoneNum, that.data.country_area, fromPage, degrees, function (result) {
|
|
|
let self = that
|
|
|
// console.log('result',result)
|
|
|
if (result.message && result.message != '')
|
|
|
self.wetoast.toast({
|
|
|
title: result.message,
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1500
|
|
|
});
|
|
|
if (result.succeed) {
|
|
|
|
|
|
that.fetchImageCheck_SwitchOn();
|
|
|
|
|
|
let countDownNumb = 60;
|
|
|
let timer = setInterval(function () {
|
|
|
countDownNumb--;
|
|
|
if (countDownNumb < 0) {
|
|
|
self.setData({
|
|
|
verifyBtnText: "重新发送",
|
|
|
counting: false,
|
|
|
})
|
|
|
clearInterval(timer);
|
|
|
} else {
|
|
|
self.setData({
|
|
|
verifyBtnText: countDownNumb + "s",
|
|
|
counting: true,
|
|
|
})
|
|
|
}
|
|
|
}, 1000);
|
|
|
// if (callBackFun)
|
|
|
// callBackFun(result);
|
|
|
}
|
|
|
else {
|
|
|
self.setData({
|
|
|
counting: false,
|
|
|
})
|
|
|
// if (callBackFun)
|
|
|
// callBackFun(result);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
phoneInputChanged:function (e) {
|
|
|
let that = this
|
|
|
that.setData({
|
|
|
phoneNum: e.detail.value
|
|
|
})
|
|
|
|
|
|
that.setData({
|
|
|
disabledClass: that.data.phoneNum && that.data.verifyCode ? "" : "disabled"
|
|
|
})
|
|
|
},
|
|
|
|
|
|
verifyCodeInputChanged:function (e) {
|
|
|
let that = this
|
|
|
that.setData({
|
|
|
verifyCode: e.detail.value,
|
|
|
});
|
|
|
|
|
|
that.setData({
|
|
|
disabledClass: that.data.phoneNum && that.data.verifyCode ? "" : "disabled"
|
|
|
})
|
|
|
},
|
|
|
|
|
|
verifyBtnAction:function(){
|
|
|
let that = this;
|
|
|
let app = getApp()
|
|
|
|
|
|
this.setData({
|
|
|
hasUnionID: app.globalData.WXUnion_ID !== null && app.globalData.WXUnion_ID !== '' && app.globalData.WXUnion_ID !== undefined ? true : false,
|
|
|
})
|
|
|
if (wx.getSetting){
|
|
|
wx.getSetting({
|
|
|
success: (res) => {
|
|
|
// console.log("userInfo:", res.authSetting["scope.userInfo"])
|
|
|
if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
|
|
|
wx.showModal({
|
|
|
title: '',
|
|
|
content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
|
|
|
confirmText: "去开启",
|
|
|
confirmColor: "#000000",
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
wx.openSetting({
|
|
|
success: (res) => {
|
|
|
// console.log(res.authSetting["scope.userInfo"])
|
|
|
if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
|
|
|
getUnionID(app.getWechatThirdSession(), function (response) {
|
|
|
if (response.succeed === true) {
|
|
|
let that = this
|
|
|
if (that.data.h5back) {
|
|
|
wx.setStorageSync('h5backReload', that.data.h5back);
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
}else{
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
|
|
|
bindBtnAction:function (needBind, callBackFun) {
|
|
|
let that = this
|
|
|
// console.log('phoneNumber,verifyCode', that.data.phoneNum, that.data.verifyCode)
|
|
|
if (!that.data.phoneNum) {
|
|
|
that.wetoast.toast({
|
|
|
title: '请输入有效手机号',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1500
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!that.data.verifyCode) {
|
|
|
that.wetoast.toast({
|
|
|
title: '请输入有效验证码',
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1500
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
bindAction(that.data.phoneNum, that.data.verifyCode, that.data.country_area, that.data.inviteCode, function (result) {
|
|
|
// console.log("result:",result)
|
|
|
if (result.message)
|
|
|
that.wetoast.toast({
|
|
|
title: result.message,
|
|
|
titleClassName: 'wetoast-title',
|
|
|
duration: 1500
|
|
|
});
|
|
|
|
|
|
if (result.succeed) {
|
|
|
//新人toast提示
|
|
|
if (result.is_register) {
|
|
|
that.showZanToast({ title:'欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收',success: function(){
|
|
|
that.redirectAction();
|
|
|
}},1500);
|
|
|
} else {
|
|
|
that.redirectAction();
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面跳转
|
|
|
*/
|
|
|
redirectAction: function() {
|
|
|
let that = this;
|
|
|
if (that.data.h5back) {
|
|
|
wx.setStorageSync('h5backReload', that.data.h5back);
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
} else {
|
|
|
let prePage = getCurrentPages();
|
|
|
that.newCustomerStorage();
|
|
|
if (prePage.length > 1 && prePage[prePage.length - 2].bindPhoneNumComplete != undefined) {
|
|
|
prePage[prePage.length - 2].bindPhoneNumComplete();
|
|
|
}
|
|
|
|
|
|
// console.log("currentPage:", getCurrentPages())
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 新人楼层标示newCustomer
|
|
|
newCustomerStorage: function() {
|
|
|
try {
|
|
|
wx.setStorage({
|
|
|
key:"newCustomer",
|
|
|
data:true
|
|
|
})
|
|
|
} catch (e) {
|
|
|
// console.error(e);
|
|
|
}
|
|
|
}
|
|
|
})) |
|
|
\ No newline at end of file |
...
|
...
|
|