|
|
@ -1,14 +1,14 @@ |
|
|
var app = getApp(); |
|
|
var app = getApp(); |
|
|
import util from "../utils/util" |
|
|
import util from "../utils/util" |
|
|
// import userApi from "../utils/https/user.js";
|
|
|
// import userApi from "../utils/https/user.js";
|
|
|
const baseUrl = "https://test.api.cloud.sz-trip.com/api/"; |
|
|
// const baseUrl = "https://test.api.cloud.sz-trip.com/api/";
|
|
|
// const baseUrl = "https://api.cloud.sz-trip.com/api/";
|
|
|
const baseUrl = "https://api.cloud.sz-trip.com/api/"; |
|
|
const orders = ['','weight','distance','sale_number','sale_price','price']; |
|
|
const orders = ['', 'weight', 'distance', 'sale_number', 'sale_price', 'price']; |
|
|
//封装GET请求
|
|
|
//封装GET请求
|
|
|
function _get(url,data) { |
|
|
function _get(url, data) { |
|
|
//为了用户体验,加一个loading效果
|
|
|
//为了用户体验,加一个loading效果
|
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
url = baseUrl+url; |
|
|
url = baseUrl + url; |
|
|
// 如果有order
|
|
|
// 如果有order
|
|
|
// if(data && data.order){
|
|
|
// if(data && data.order){
|
|
|
// data.order = orders[data.order];
|
|
|
// data.order = orders[data.order];
|
|
|
@ -27,7 +27,7 @@ function _get(url,data) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: res.data.msg, |
|
|
title: res.data.msg, |
|
|
icon: "none", |
|
|
icon: "none", |
|
|
duration:2000 |
|
|
duration: 2000 |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
resolved(res.data); |
|
|
resolved(res.data); |
|
|
@ -42,7 +42,7 @@ function _get(url,data) { |
|
|
wx.request(obj) |
|
|
wx.request(obj) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
function back(){ |
|
|
function back() { |
|
|
const pages = getCurrentPages(); |
|
|
const pages = getCurrentPages(); |
|
|
if (pages.length <= 1) { |
|
|
if (pages.length <= 1) { |
|
|
wx.switchTab({ |
|
|
wx.switchTab({ |
|
|
@ -56,7 +56,7 @@ function back(){ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//封装POST请求
|
|
|
//封装POST请求
|
|
|
function _post(url,data={}) { |
|
|
function _post(url, data = {}) { |
|
|
//为了用户体验,加一个loading效果
|
|
|
//为了用户体验,加一个loading效果
|
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
url = baseUrl + url; |
|
|
url = baseUrl + url; |
|
|
@ -81,21 +81,21 @@ function _post(url,data={}) { |
|
|
// icon: "none",
|
|
|
// icon: "none",
|
|
|
// })
|
|
|
// })
|
|
|
// }
|
|
|
// }
|
|
|
if(url.indexOf('product/get_product_detail')!=-1){ |
|
|
if (url.indexOf('product/get_product_detail') != -1) { |
|
|
// 如果是产品详情的话 需要加埋点
|
|
|
// 如果是产品详情的话 需要加埋点
|
|
|
_post('browse/ProductStatistics',{ |
|
|
_post('browse/ProductStatistics', { |
|
|
uuid:wx.getStorageSync('uuid'), |
|
|
uuid: wx.getStorageSync('uuid'), |
|
|
product_id:res.data.data.id, |
|
|
product_id: res.data.data.id, |
|
|
product_name:res.data.data.title, |
|
|
product_name: res.data.data.title, |
|
|
type:res.data.data.type |
|
|
type: res.data.data.type |
|
|
}) |
|
|
}) |
|
|
util.pagePoint({ |
|
|
util.pagePoint({ |
|
|
event:'product_view', |
|
|
event: 'product_view', |
|
|
param:{ |
|
|
param: { |
|
|
type:res.data.data.type, |
|
|
type: res.data.data.type, |
|
|
id:res.data.data.id |
|
|
id: res.data.data.id |
|
|
} |
|
|
} |
|
|
},1) |
|
|
}, 1) |
|
|
} |
|
|
} |
|
|
resolved(res.data); |
|
|
resolved(res.data); |
|
|
} |
|
|
} |
|
|
@ -103,35 +103,35 @@ function _post(url,data={}) { |
|
|
rejected(res.data); |
|
|
rejected(res.data); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
fail: (err) => {wx.hideLoading();rejected(err)} |
|
|
fail: (err) => { wx.hideLoading(); rejected(err) } |
|
|
} |
|
|
} |
|
|
wx.request(obj) |
|
|
wx.request(obj) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
function user_post(url,data={},type){ |
|
|
function user_post(url, data = {}, type) { |
|
|
if(wx.getStorageSync('authCode')){ |
|
|
if (wx.getStorageSync('authCode')) { |
|
|
// 如果有授权码的话 用授权码去获取下用户信息
|
|
|
// 如果有授权码的话 用授权码去获取下用户信息
|
|
|
return new Promise((resolved,rejected)=>{ |
|
|
return new Promise((resolved, rejected) => { |
|
|
_post("/uservice/user/loginWithUserCenterAuthCode",{ |
|
|
_post("/uservice/user/loginWithUserCenterAuthCode", { |
|
|
auth_code:wx.getStorageSync('authCode') |
|
|
auth_code: wx.getStorageSync('authCode') |
|
|
}).then(res=>{ |
|
|
}).then(res => { |
|
|
wx.removeStorageSync('authCode') |
|
|
wx.removeStorageSync('authCode') |
|
|
if(res && res.data){ |
|
|
if (res && res.data) { |
|
|
wx.setStorageSync('jstrip_userid', res.data.id) |
|
|
wx.setStorageSync('jstrip_userid', res.data.id) |
|
|
wx.setStorageSync('jstrip_token', res.data.token) |
|
|
wx.setStorageSync('jstrip_token', res.data.token) |
|
|
wx.setStorageSync('jstrip_userInfo', res.data) |
|
|
wx.setStorageSync('jstrip_userInfo', res.data) |
|
|
} |
|
|
} |
|
|
user_post_new(url,data,type).then(res=>{ |
|
|
user_post_new(url, data, type).then(res => { |
|
|
resolved(res) |
|
|
resolved(res) |
|
|
}).catch(err=>{ |
|
|
}).catch(err => { |
|
|
rejected(err) |
|
|
rejected(err) |
|
|
}) |
|
|
}) |
|
|
}).catch(err=>{ |
|
|
}).catch(err => { |
|
|
wx.removeStorageSync('authCode') |
|
|
wx.removeStorageSync('authCode') |
|
|
user_post_new(url,data,type).then(res=>{ |
|
|
user_post_new(url, data, type).then(res => { |
|
|
resolved(res) |
|
|
resolved(res) |
|
|
}).catch(err=>{ |
|
|
}).catch(err => { |
|
|
rejected(err) |
|
|
rejected(err) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
@ -139,19 +139,19 @@ function user_post(url,data={},type){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return user_post_new(url,data,type) |
|
|
return user_post_new(url, data, type) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
function user_post_new(url,data={},type){ |
|
|
function user_post_new(url, data = {}, type) { |
|
|
console.log(type) |
|
|
console.log(type) |
|
|
var token = wx.getStorageSync("jstrip_token"),userId = wx.getStorageSync("jstrip_userid"); |
|
|
var token = wx.getStorageSync("jstrip_token"), userId = wx.getStorageSync("jstrip_userid"); |
|
|
//为了用户体验,加一个loading效果
|
|
|
//为了用户体验,加一个loading效果
|
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
wx.showLoading({ title: '加载中', mask: true }); |
|
|
url = baseUrl + url; |
|
|
url = baseUrl + url; |
|
|
var header = Object.assign({ |
|
|
var header = Object.assign({ |
|
|
token:token, |
|
|
token: token, |
|
|
userId:userId |
|
|
userId: userId |
|
|
},{ |
|
|
}, { |
|
|
'context-type': 'application/json' |
|
|
'context-type': 'application/json' |
|
|
}) |
|
|
}) |
|
|
// 如果有order
|
|
|
// 如果有order
|
|
|
@ -165,7 +165,7 @@ function user_post_new(url,data={},type){ |
|
|
return new Promise((resolved, rejected) => { |
|
|
return new Promise((resolved, rejected) => { |
|
|
// 判断是否登录
|
|
|
// 判断是否登录
|
|
|
// 没有登录就跳转到登录页面
|
|
|
// 没有登录就跳转到登录页面
|
|
|
if (!token || !userId){ |
|
|
if (!token || !userId) { |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
// 去登陆
|
|
|
// 去登陆
|
|
|
console.log("去登陆去登陆去登陆去登陆去登陆去登陆去登陆") |
|
|
console.log("去登陆去登陆去登陆去登陆去登陆去登陆去登陆") |
|
|
@ -177,12 +177,12 @@ function user_post_new(url,data={},type){ |
|
|
const obj = { |
|
|
const obj = { |
|
|
url, |
|
|
url, |
|
|
data, |
|
|
data, |
|
|
method: type?type:'POST', |
|
|
method: type ? type : 'POST', |
|
|
header: header, |
|
|
header: header, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
console.log(url,url.indexOf('team_order/apply_post')!=-1) |
|
|
console.log(url, url.indexOf('team_order/apply_post') != -1) |
|
|
if(url.indexOf('user/getJumpThirdAppCode')!=-1){ |
|
|
if (url.indexOf('user/getJumpThirdAppCode') != -1) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else if (res.data.code == 401) { |
|
|
else if (res.data.code == 401) { |
|
|
@ -192,7 +192,7 @@ function user_post_new(url,data={},type){ |
|
|
wx.removeStorageSync("jstrip_userInfo"); |
|
|
wx.removeStorageSync("jstrip_userInfo"); |
|
|
checkLogin(); |
|
|
checkLogin(); |
|
|
} |
|
|
} |
|
|
else if(res.data.code==4005){ |
|
|
else if (res.data.code == 4005) { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/user/verify/index', |
|
|
url: '/pages/user/verify/index', |
|
|
}) |
|
|
}) |
|
|
@ -200,33 +200,37 @@ function user_post_new(url,data={},type){ |
|
|
} |
|
|
} |
|
|
else if (res.data.code != 1 && res.data.msg) { |
|
|
else if (res.data.code != 1 && res.data.msg) { |
|
|
// 不出现提示语
|
|
|
// 不出现提示语
|
|
|
if(url.indexOf('actonline/video_act/getRaffle')!=-1 || url.indexOf('team_order/apply_post')!=-1 && type=='get'){ |
|
|
const noToast = [ |
|
|
|
|
|
'actonline/video_act/getRaffle', |
|
|
|
|
|
'getProductAllowancePrice' |
|
|
|
|
|
] |
|
|
|
|
|
if (noToast.indexOf(url) || url.indexOf('team_order/apply_post') != -1 && type == 'get') { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else if(url.indexOf('actonline/act_online/vote')!=-1 && res.data.code==0){ |
|
|
else if (url.indexOf('actonline/act_online/vote') != -1 && res.data.code == 0) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: res.data.msg, |
|
|
title: res.data.msg, |
|
|
icon: "none", |
|
|
icon: "none", |
|
|
duration:2000 |
|
|
duration: 2000 |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
else if(url.indexOf('actonline/act_online/vote')==-1){ |
|
|
else if (url.indexOf('actonline/act_online/vote') == -1) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: res.data.msg==='身份证号码错误'?'身份证和姓名不匹配':res.data.msg, |
|
|
title: res.data.msg === '身份证号码错误' ? '身份证和姓名不匹配' : res.data.msg, |
|
|
icon: "none", |
|
|
icon: "none", |
|
|
duration:2000 |
|
|
duration: 2000 |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if(res.statusCode == 200){ |
|
|
if (res.statusCode == 200) { |
|
|
if(url.indexOf('/order/create')!=-1 && res.data.code==1 && res.data.data){ |
|
|
if (url.indexOf('/order/create') != -1 && res.data.code == 1 && res.data.data) { |
|
|
// 下单成功
|
|
|
// 下单成功
|
|
|
wx.removeStorageSync('prizeId') |
|
|
wx.removeStorageSync('prizeId') |
|
|
if(res.data.data.pay_status==1){ |
|
|
if (res.data.data.pay_status == 1) { |
|
|
// 0元直接付款成功
|
|
|
// 0元直接付款成功
|
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url:"/pages/order/payresult/index?tid="+res.data.data.order_id |
|
|
url: "/pages/order/payresult/index?tid=" + res.data.data.order_id |
|
|
}) |
|
|
}) |
|
|
// util.gotoOrder(res.data.data)
|
|
|
// util.gotoOrder(res.data.data)
|
|
|
// // wx.navigateTo({
|
|
|
// // wx.navigateTo({
|
|
|
@ -235,38 +239,38 @@ function user_post_new(url,data={},type){ |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/order/pay/index?id='+res.data.data.order_id, |
|
|
url: '/pages/order/pay/index?id=' + res.data.data.order_id, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
if(wx.getStorageSync('order_from')){ |
|
|
if (wx.getStorageSync('order_from')) { |
|
|
util.pagePoint({ |
|
|
util.pagePoint({ |
|
|
event:wx.getStorageSync('order_from') |
|
|
event: wx.getStorageSync('order_from') |
|
|
},1) |
|
|
}, 1) |
|
|
} |
|
|
} |
|
|
wx.removeStorageSync('order_from') |
|
|
wx.removeStorageSync('order_from') |
|
|
} |
|
|
} |
|
|
else if(url.indexOf('/order/create')!=-1 && res.data.msg=='您有正在进行中或待支付的拼团,请查看拼团订单'){ |
|
|
else if (url.indexOf('/order/create') != -1 && res.data.msg == '您有正在进行中或待支付的拼团,请查看拼团订单') { |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/user/order/list', |
|
|
url: '/pages/user/order/list', |
|
|
}) |
|
|
}) |
|
|
}, 1000); |
|
|
}, 1000); |
|
|
} |
|
|
} |
|
|
if(url.indexOf('product/get_product_detail')!=-1){ |
|
|
if (url.indexOf('product/get_product_detail') != -1) { |
|
|
// 如果是产品详情的话 需要加埋点
|
|
|
// 如果是产品详情的话 需要加埋点
|
|
|
_post('browse/ProductStatistics',{ |
|
|
_post('browse/ProductStatistics', { |
|
|
uuid:wx.getStorageSync('uuid'), |
|
|
uuid: wx.getStorageSync('uuid'), |
|
|
product_id:res.data.data.id, |
|
|
product_id: res.data.data.id, |
|
|
product_name:res.data.data.title, |
|
|
product_name: res.data.data.title, |
|
|
type:res.data.data.type |
|
|
type: res.data.data.type |
|
|
}) |
|
|
}) |
|
|
util.pagePoint({ |
|
|
util.pagePoint({ |
|
|
event:'product_view', |
|
|
event: 'product_view', |
|
|
param:{ |
|
|
param: { |
|
|
type:res.data.data.type, |
|
|
type: res.data.data.type, |
|
|
id:res.data.data.id |
|
|
id: res.data.data.id |
|
|
} |
|
|
} |
|
|
},1) |
|
|
}, 1) |
|
|
} |
|
|
} |
|
|
resolved(res.data); |
|
|
resolved(res.data); |
|
|
} |
|
|
} |
|
|
@ -292,11 +296,11 @@ const set_logininfo = r => { |
|
|
if (getCurrentPages().length != 0) { |
|
|
if (getCurrentPages().length != 0) { |
|
|
//刷新当前页面的数据
|
|
|
//刷新当前页面的数据
|
|
|
let item = getCurrentPages()[getCurrentPages().length - 1]; |
|
|
let item = getCurrentPages()[getCurrentPages().length - 1]; |
|
|
if(item.route.indexOf('login')!=-1){ |
|
|
if (item.route.indexOf('login') != -1) { |
|
|
item = getCurrentPages()[getCurrentPages().length - 2]; |
|
|
item = getCurrentPages()[getCurrentPages().length - 2]; |
|
|
item.onLoad(item.__displayReporter.query) |
|
|
item.onLoad(item.__displayReporter.query) |
|
|
} |
|
|
} |
|
|
else if(item.route=='pages/index/index'){ |
|
|
else if (item.route == 'pages/index/index') { |
|
|
// 首页只可能去获取苏康码
|
|
|
// 首页只可能去获取苏康码
|
|
|
item.gotoSkm(); |
|
|
item.gotoSkm(); |
|
|
} |
|
|
} |
|
|
@ -309,7 +313,7 @@ const set_logininfo = r => { |
|
|
const checkLogin = () => { |
|
|
const checkLogin = () => { |
|
|
// 判断是否已经授权过
|
|
|
// 判断是否已经授权过
|
|
|
let page = getCurrentPages(); |
|
|
let page = getCurrentPages(); |
|
|
if(page[page.length-1].route!='pages/login/index') { |
|
|
if (page[page.length - 1].route != 'pages/login/index') { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/login/index', |
|
|
url: '/pages/login/index', |
|
|
}) |
|
|
}) |
|
|
@ -333,7 +337,7 @@ const checkLogin = () => { |
|
|
} |
|
|
} |
|
|
// r.data.isBind是false的时候去绑定手机号 该用户没有注册过
|
|
|
// r.data.isBind是false的时候去绑定手机号 该用户没有注册过
|
|
|
// 已经注册的用户返回userinfo
|
|
|
// 已经注册的用户返回userinfo
|
|
|
else if (r.data.isBindMobile === 0 && page[page.length-1].route!='pages/user/bindtel/index') { |
|
|
else if (r.data.isBindMobile === 0 && page[page.length - 1].route != 'pages/user/bindtel/index') { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid), |
|
|
url: '/pages/user/bindtel/index?regToken=' + encodeURIComponent(r.data.openid), |
|
|
}) |
|
|
}) |
|
|
@ -343,7 +347,7 @@ const checkLogin = () => { |
|
|
title: '网络请求失败', |
|
|
title: '网络请求失败', |
|
|
icon: 'none' |
|
|
icon: 'none' |
|
|
}) |
|
|
}) |
|
|
console.log(err,"666666") |
|
|
console.log(err, "666666") |
|
|
back() |
|
|
back() |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
@ -352,14 +356,14 @@ const checkLogin = () => { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
if(page[page.length-1].route!='pages/login/index') { |
|
|
if (page[page.length - 1].route != 'pages/login/index') { |
|
|
wx.navigateTo({ |
|
|
wx.navigateTo({ |
|
|
url: '/pages/login/index', |
|
|
url: '/pages/login/index', |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
fail:err=>{ |
|
|
fail: err => { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|