Commit 3e5278e9 by 杨北旺

提交附近优惠

1 parent a495eae1
......@@ -46,6 +46,7 @@ Page({
wx.navigateTo({
url,
})
}
},
})
import { env } from '~/api/env/index'
import mapApi from '~/utils/mapapi/mapapi'
const app = getApp()
Page({
data: {
......@@ -24,9 +26,17 @@ Page({
onLoad() {
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() {
let authComponent = this.selectComponent('#authorize')
if (authComponent) authComponent.check()
},
goMorePage() {
......@@ -49,7 +59,7 @@ Page({
// 定位
async getLocation() {
try {
const res = await wx.p.$Track.getAddressInfo()
const res = await this.getAddressInfo()
this.toGetCommodity(res.location.lat, res.location.lng, 1)
this.setData({
currentAddress: res,
......@@ -62,44 +72,33 @@ Page({
},
// 获取附近优惠数据
toGetCommodity(lat, lng, page) {
let {
pageParam,
loadingMore,
commodityList,
loadOver
} = this.data
toGetCommodity(lat, lng, firstLoad) {
let para = {
lat,
lng,
...pageParam
...app.globalData.goodsPageParam
}
if (loadOver) {
if (app.globalData.goodsLoaded || (firstLoad && app.globalData.goodsPageParam?.length)) {
this.setData({
commodityList: app.globalData.goodsCommodityList,
})
return
}
if (page) {
para.pageSize = 0
}
wx.p.api.equityApi.lasteCommodity(para).then(res => {
if (!res) {
this.setData({
loadOver: true
})
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 = []
res.forEach(item => {
if (item.couponsGoodsList) {
tempArr.push(item)
}
res.data.forEach(item => {
tempArr.push(item)
})
if (loadingMore) {
commodityList = commodityList.concat(tempArr)
}
app.globalData.goodsCommodityList = app.globalData.goodsCommodityList.concat(tempArr)
app.globalData.goodsLoaded = false
this.setData({
commodityList: loadingMore ? commodityList : tempArr,
loadingMore: false,
loadOver: false
commodityList: app.globalData.goodsCommodityList,
})
})
},
......@@ -110,7 +109,17 @@ Page({
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() {
if (this.data.unauthorized) {
return
......@@ -118,19 +127,15 @@ Page({
if (!this.data.commodityList.length) {
return
}
let { pageParam } = this.data
pageParam.pageSize++
this.setData(
{
pageParam,
loadingMore: true
},
() => {
let { currentAddress } = this.data
const { lat, lng } = currentAddress.location
this.toGetCommodity(lat, lng)
}
)
let {
currentAddress
} = this.data
if (!currentAddress) return
const {
lat,
lng
} = currentAddress.location
this.toGetCommodity(lat, lng)
},
getAllMerchantList() {
const {
......@@ -214,9 +219,9 @@ Page({
icon: item.equityIcon,
...item
})
})
}
this.setData({
foodMenuList,
......@@ -227,5 +232,70 @@ Page({
},
toPluginPage() {
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
......@@ -39,4 +39,6 @@
<view style="height:400rpx"></view>
</view>
</view>
</view>
\ No newline at end of file
</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
......@@ -57,4 +57,5 @@
<image class="max_cover" src="{{IMG_URL}}home/{{urlName}}.png" show-menu-by-longpress="{{true}}" />
<image bind:tap="closeModal" class="close_icon" src="{{IMG_URL}}home/close_modal.png" />
</view>
</view>
\ No newline at end of file
</view>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file
......@@ -8,4 +8,5 @@
<glsx-image webp custom-class="bg" src="mall/bg.png"></glsx-image>
</view>
<carOwner id="currentChannel_6" bindshowShoppingCar="showShoppingCarFn" merchantid="{{merchantId}}" channelID="{{currentChannel.id}}"></carOwner>
</view>
\ No newline at end of file
</view>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ No newline at end of file
......@@ -139,4 +139,5 @@
</view>
</view>
</view>
</block>
\ No newline at end of file
</block>
<glsx-privacy appletName="车生活助手"></glsx-privacy>
\ 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!