Commit 3e5278e9 by 杨北旺

提交附近优惠

1 parent a495eae1
...@@ -46,6 +46,7 @@ Page({ ...@@ -46,6 +46,7 @@ Page({
wx.navigateTo({ wx.navigateTo({
url, url,
}) })
} },
}) })
import { env } from '~/api/env/index' import { env } from '~/api/env/index'
import mapApi from '~/utils/mapapi/mapapi'
const app = getApp()
Page({ Page({
data: { data: {
...@@ -24,9 +26,17 @@ Page({ ...@@ -24,9 +26,17 @@ Page({
onLoad() { onLoad() {
this.getAllMerchantList() this.getAllMerchantList()
let freecard = wx.p.storage.get('bindInfo')
if (freecard) {
let bingInfo = JSON.parse(decodeURIComponent(freecard))
const sid = bingInfo.data.sessionId
wx.p.cache.storageApi.setSessionId(sid)
this.handleFreeCard(bingInfo)
}
}, },
onShow() { onShow() {
let authComponent = this.selectComponent('#authorize')
if (authComponent) authComponent.check()
}, },
goMorePage() { goMorePage() {
...@@ -49,7 +59,7 @@ Page({ ...@@ -49,7 +59,7 @@ Page({
// 定位 // 定位
async getLocation() { async getLocation() {
try { try {
const res = await wx.p.$Track.getAddressInfo() const res = await this.getAddressInfo()
this.toGetCommodity(res.location.lat, res.location.lng, 1) this.toGetCommodity(res.location.lat, res.location.lng, 1)
this.setData({ this.setData({
currentAddress: res, currentAddress: res,
...@@ -62,44 +72,33 @@ Page({ ...@@ -62,44 +72,33 @@ Page({
}, },
// 获取附近优惠数据 // 获取附近优惠数据
toGetCommodity(lat, lng, page) { toGetCommodity(lat, lng, firstLoad) {
let {
pageParam,
loadingMore,
commodityList,
loadOver
} = this.data
let para = { let para = {
lat, lat,
lng, lng,
...pageParam ...app.globalData.goodsPageParam
}
if (loadOver) {
return
}
if (page) {
para.pageSize = 0
} }
wx.p.api.equityApi.lasteCommodity(para).then(res => { if (app.globalData.goodsLoaded || (firstLoad && app.globalData.goodsPageParam?.length)) {
if (!res) {
this.setData({ this.setData({
loadOver: true commodityList: app.globalData.goodsCommodityList,
}) })
return return
} }
para.pageOffset = para.pageSize
wx.p.api.equityApi.getLasteCommodity(para).then(res => {
if (!res?.data?.length) {
app.globalData.goodsLoaded = true
return
}
app.globalData.goodsPageParam.pageSize = res.pageOffset
let tempArr = [] let tempArr = []
res.forEach(item => { res.data.forEach(item => {
if (item.couponsGoodsList) {
tempArr.push(item) tempArr.push(item)
}
}) })
if (loadingMore) { app.globalData.goodsCommodityList = app.globalData.goodsCommodityList.concat(tempArr)
commodityList = commodityList.concat(tempArr) app.globalData.goodsLoaded = false
}
this.setData({ this.setData({
commodityList: loadingMore ? commodityList : tempArr, commodityList: app.globalData.goodsCommodityList,
loadingMore: false,
loadOver: false
}) })
}) })
}, },
...@@ -110,7 +109,17 @@ Page({ ...@@ -110,7 +109,17 @@ Page({
showAuth: true showAuth: true
}) })
}, },
onPullDownRefresh() {
this.getShopPackage()
this.toCheckMember()
app.globalData.goodsCommodityList = []
app.globalData.goodsPageParam.pageSize = 0
app.globalData.goodsLoaded = false
let { currentAddress } = this.data
if (!currentAddress) return
const { lat, lng } = currentAddress.location
this.toGetCommodity(lat, lng, false, 1)
},
onReachBottom() { onReachBottom() {
if (this.data.unauthorized) { if (this.data.unauthorized) {
return return
...@@ -118,19 +127,15 @@ Page({ ...@@ -118,19 +127,15 @@ Page({
if (!this.data.commodityList.length) { if (!this.data.commodityList.length) {
return return
} }
let { pageParam } = this.data let {
pageParam.pageSize++ currentAddress
this.setData( } = this.data
{ if (!currentAddress) return
pageParam, const {
loadingMore: true lat,
}, lng
() => { } = currentAddress.location
let { currentAddress } = this.data
const { lat, lng } = currentAddress.location
this.toGetCommodity(lat, lng) this.toGetCommodity(lat, lng)
}
)
}, },
getAllMerchantList() { getAllMerchantList() {
const { const {
...@@ -227,5 +232,70 @@ Page({ ...@@ -227,5 +232,70 @@ Page({
}, },
toPluginPage() { toPluginPage() {
wx.p.router.go('/packagePlugin/pages/index/index', { notIntercept: true }) wx.p.router.go('/packagePlugin/pages/index/index', { notIntercept: true })
},
async getAddressInfo() {
let addressInfo = wx.p.storage.get('address_info')
return new Promise(resolve => {
if (addressInfo && Date.now() - addressInfo.createTime < 2 * 60 * 1e3) resolve(addressInfo)
else
wx.getLocation({
type: 'gcj02'
}).then(({
latitude,
longitude
}) => {
mapApi.detailedAdrress([latitude, longitude]).then(detail => {
let info = {
...detail,
createTime: Date.now()
} }
resolve(info)
wx.p.storage.set('address_info', info)
})
})
})
},
// 处理免费领取权益页面带来的参数---弹框显示
handleFreeCard(bindInfo) {
wx.p.storage.rm('bindInfo')
const {
code,
errId,
message
} = bindInfo
if (code == 0) {
wx.showModal({
title: '提示',
content: '领取成功',
confirmText: '确定',
showCancel: false,
confirmColor: '#F13C3D'
})
} else if (code == -1 && errId == 20321) {
wx.showModal({
title: '提示',
content: message,
confirmText: '续费开通',
cancelText: '不用了',
confirmColor: '#F13C3D'
}).then(res => {
if (res.confirm) {
this.toBuyMember()
}
})
} else if (errId == 20320 || errId == 20322) {
wx.showModal({
title: '提示',
content: message,
confirmText: '确定',
showCancel: false,
confirmColor: '#F13C3D'
})
}
},
toBuyMember() {
wx.p.router.go('/packageSaveMoney/pages/open/open', {
notIntercept: true
})
},
}) })
\ No newline at end of file \ No newline at end of file
...@@ -40,3 +40,5 @@ ...@@ -40,3 +40,5 @@
</view> </view>
</view> </view>
</view> </view>
<authorize id="authorize" scopeType="userLocation" isShowCheck="{{false}}" bindfail="authFail" bindsuccess="authSuccess" show="{{showAuth}}"></authorize>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
...@@ -58,3 +58,4 @@ ...@@ -58,3 +58,4 @@
<image bind:tap="closeModal" class="close_icon" src="{{IMG_URL}}home/close_modal.png" /> <image bind:tap="closeModal" class="close_icon" src="{{IMG_URL}}home/close_modal.png" />
</view> </view>
</view> </view>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
...@@ -9,3 +9,4 @@ ...@@ -9,3 +9,4 @@
</view> </view>
<carOwner id="currentChannel_6" bindshowShoppingCar="showShoppingCarFn" merchantid="{{merchantId}}" channelID="{{currentChannel.id}}"></carOwner> <carOwner id="currentChannel_6" bindshowShoppingCar="showShoppingCarFn" merchantid="{{merchantId}}" channelID="{{currentChannel.id}}"></carOwner>
</view> </view>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
...@@ -140,3 +140,4 @@ ...@@ -140,3 +140,4 @@
</view> </view>
</view> </view>
</block> </block>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!