...
|
...
|
@@ -3,6 +3,7 @@ let method = require("../../utils/reuqest.js"); |
|
|
const util = require("../../utils/util.js");
|
|
|
Page({
|
|
|
data: {
|
|
|
Authorization: '', //判断用户是否登录
|
|
|
page: 1,
|
|
|
classifyId: "",
|
|
|
idx: 0, //商品规格索引
|
...
|
...
|
@@ -41,24 +42,26 @@ Page({ |
|
|
})
|
|
|
},
|
|
|
//获取定位
|
|
|
getLocation() {
|
|
|
let that = this;
|
|
|
wx.getLocation({
|
|
|
type: 'gcj02',
|
|
|
success(res) {
|
|
|
that.setData({
|
|
|
latitude: res.latitude,
|
|
|
longitude: res.longitude
|
|
|
})
|
|
|
that.location();
|
|
|
const speed = res.speed
|
|
|
const accuracy = res.accuracy
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// getLocation() {
|
|
|
// let that = this;
|
|
|
// wx.getLocation({
|
|
|
// type: 'gcj02',
|
|
|
// success(res) {
|
|
|
// that.setData({
|
|
|
// latitude: res.latitude,
|
|
|
// longitude: res.longitude
|
|
|
// })
|
|
|
// that.location();
|
|
|
// const speed = res.speed
|
|
|
// const accuracy = res.accuracy
|
|
|
// }
|
|
|
// })
|
|
|
// },
|
|
|
location() {
|
|
|
let that = this
|
|
|
console.log(that.data.latitude, '5555')
|
|
|
let str = that.data.latitude + ',' + that.data.longitude;
|
|
|
console.log(str, 'str')
|
|
|
method.getRequest("/goods/geocoder/v1/" + str, data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
that.setData({
|
...
|
...
|
@@ -156,22 +159,31 @@ Page({ |
|
|
})
|
|
|
},
|
|
|
addCart(e) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
this.setData({
|
|
|
showMask: true
|
|
|
})
|
|
|
method.getRequest("/goods/" + id, data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
this.setData({
|
|
|
goodsData: data.data,
|
|
|
stockNum: data.data.list[0].goodsStock
|
|
|
})
|
|
|
} else {
|
|
|
setTimeout(() => {
|
|
|
util.getUser()
|
|
|
}, 2000)
|
|
|
}
|
|
|
})
|
|
|
if (this.data.Authorization) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
this.setData({
|
|
|
showMask: true
|
|
|
})
|
|
|
method.getRequest("/goods/" + id, data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
this.setData({
|
|
|
goodsData: data.data,
|
|
|
stockNum: data.data.list[0].goodsStock
|
|
|
})
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '请先登录!',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
util.getUser()
|
|
|
}, 2000)
|
|
|
}
|
|
|
|
|
|
},
|
|
|
closeMask() {
|
|
|
this.setData({
|
...
|
...
|
@@ -243,32 +255,38 @@ Page({ |
|
|
},
|
|
|
//兑换
|
|
|
exchange(e) {
|
|
|
let jifenNum = e.currentTarget.dataset.integral;
|
|
|
let defaultSku = e.currentTarget.dataset.defaultSku;
|
|
|
wx.setStorageSync('defaultSku', e.currentTarget.dataset.defaultsku)
|
|
|
//获取用户积分
|
|
|
method.getRequest("/myUser/queryUserInfo", data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
this.setData({
|
|
|
integral: data.data.integral
|
|
|
})
|
|
|
if (jifenNum > this.data.integral) {
|
|
|
wx.showToast({
|
|
|
title: '您的积分目前不够兑换该商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return false
|
|
|
} else {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/integral-order/integral-order',
|
|
|
if (this.data.Authorization) {
|
|
|
let jifenNum = e.currentTarget.dataset.integral;
|
|
|
let defaultSku = e.currentTarget.dataset.defaultSku;
|
|
|
wx.setStorageSync('defaultSku', e.currentTarget.dataset.defaultsku)
|
|
|
//获取用户积分
|
|
|
method.getRequest("/myUser/queryUserInfo", data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
this.setData({
|
|
|
integral: data.data.integral
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
setTimeout(() => {
|
|
|
util.getUser()
|
|
|
}, 2000)
|
|
|
}
|
|
|
})
|
|
|
if (jifenNum > this.data.integral) {
|
|
|
wx.showToast({
|
|
|
title: '您的积分目前不够兑换该商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return false
|
|
|
} else {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/integral-order/integral-order',
|
|
|
})
|
|
|
}
|
|
|
} else {}
|
|
|
})
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '请先登录!',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
setTimeout(() => {
|
|
|
util.getUser()
|
|
|
}, 2000)
|
|
|
}
|
|
|
|
|
|
},
|
|
|
//商品详情
|
...
|
...
|
@@ -279,7 +297,26 @@ Page({ |
|
|
url: '/pages/product-detail/product-detail',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
//再次申请获取位置信息
|
|
|
openConfirm: function () {
|
|
|
wx.showModal({
|
|
|
content: '检测到您没打开定位权限,有些功能无法使用,是否去设置打开?',
|
|
|
confirmText: "确认",
|
|
|
cancelText: "取消",
|
|
|
success: function (res) {
|
|
|
console.log(res);
|
|
|
//点击“确认”时打开设置页面
|
|
|
if (res.confirm) {
|
|
|
console.log('用户点击确认')
|
|
|
wx.openSetting({
|
|
|
success: (res) => {}
|
|
|
})
|
|
|
} else {
|
|
|
console.log('用户点击取消')
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
...
|
...
|
@@ -329,23 +366,65 @@ Page({ |
|
|
}
|
|
|
wx.removeStorageSync("classifyIndex")
|
|
|
let that = this;
|
|
|
wx.getLocation({
|
|
|
type: 'gcj02',
|
|
|
success(res) {
|
|
|
that.setData({
|
|
|
latitude: res.latitude,
|
|
|
longitude: res.longitude
|
|
|
//判断用户是否登录
|
|
|
if (this.data.Authorization) {
|
|
|
// wx.getLocation({
|
|
|
// type: 'gcj02',
|
|
|
// success(res) {
|
|
|
// that.setData({
|
|
|
// latitude: res.latitude,
|
|
|
// longitude: res.longitude
|
|
|
// })
|
|
|
// that.location();
|
|
|
// const speed = res.speed
|
|
|
// const accuracy = res.accuracy
|
|
|
// },
|
|
|
// fail(errInfo) {
|
|
|
// console.info(errInfo)
|
|
|
// }
|
|
|
// })
|
|
|
}
|
|
|
//判断用户是否登录
|
|
|
if (wx.getStorageSync('Authorization') === '') {
|
|
|
this.setData({
|
|
|
Authorization: false
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
Authorization: true
|
|
|
})
|
|
|
//位置
|
|
|
wx.getLocation({
|
|
|
type: 'wgs84',
|
|
|
success: function (res) {
|
|
|
that.setData({
|
|
|
longitude: res.longitude,
|
|
|
latitude: res.latitude
|
|
|
})
|
|
|
that.location()
|
|
|
}
|
|
|
})
|
|
|
//判断是否获得了用户地理位置授权
|
|
|
if (that.data.latitude == undefined) {
|
|
|
wx.getSetting({
|
|
|
success: (res) => {
|
|
|
if (!res.authSetting['scope.userLocation'])
|
|
|
that.openConfirm()
|
|
|
}
|
|
|
})
|
|
|
that.location();
|
|
|
const speed = res.speed
|
|
|
const accuracy = res.accuracy
|
|
|
},
|
|
|
fail(errInfo) {
|
|
|
console.info(errInfo)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
}
|
|
|
if (that.data.latitude !== undefined) {
|
|
|
setTimeout(() => {
|
|
|
that.location()
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
},
|
|
|
open() {
|
|
|
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
...
|
...
|
|