更新优化定位, 推荐商品

This commit is contained in:
weipengfei 2023-12-05 10:29:47 +08:00
parent c6a95fd7e2
commit 4b1d003905
3 changed files with 81 additions and 64 deletions

View File

@ -5,13 +5,14 @@
<view class="site-box flex_a_c_j_sb" :style="{ opacity: backColor }"> <view class="site-box flex_a_c_j_sb" :style="{ opacity: backColor }">
<view <view
:class="['place_wrapper', 'flex_a_c', isFshow ? 'sitebox' : '']" :class="['place_wrapper', 'flex_a_c', isFshow ? 'sitebox' : '']"
@click="selectLocation" @click="changeMap"
> >
<view <view
:class="['iconfont', 'icon-weizhi', isFshow ? 'sitebox' : '']" :class="['iconfont', 'icon-weizhi', isFshow ? 'sitebox' : '']"
style="margin-left: 20rpx" style="margin-left: 20rpx"
> >
</view> </view>
<view class="town_name">{{ street||'定位中' }}</view>
</view> </view>
<navigator <navigator
url="/pages/chat/customer_list/index?type=0" url="/pages/chat/customer_list/index?type=0"
@ -706,57 +707,61 @@ export default {
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
this.isshow = false this.isshow = false
uni.showToast({ // uni.showToast({
title: err, // title: err,
icon: 'none' // icon: 'none'
}) // })
this.uniLocation();
}) })
} }
else uni.getLocation({ else this.uniLocation();
type: 'wgs84', },
timeout: '1000', uniLocation(){
success: (res) => { uni.getLocation({
type: 'wgs84',
timeout: '1000',
success: (res) => {
console.log('定位成功', res); console.log('定位成功', res);
this.isshow = false this.isshow = false
let latitude, longitude; let latitude, longitude;
latitude = res.latitude.toString(); latitude = res.latitude.toString();
longitude = res.longitude.toString(); longitude = res.longitude.toString();
this.$store.commit('setLocation', { this.$store.commit('setLocation', {
lat: res.latitude.toFixed(6), lat: res.latitude.toFixed(6),
long: res.longitude.toFixed(6), long: res.longitude.toFixed(6),
}); });
getGeocoder({ getGeocoder({
lat: latitude, lat: latitude,
long: longitude long: longitude
}).then(res => { }).then(res => {
let town = res.data.address_reference.town.title let town = res.data.address_reference.town.title
let street_id = res.data.address_reference.town.id let street_id = res.data.address_reference.town.id
this.street = res.data.address_reference.town.title this.street = res.data.address_reference.town.title
this.$nextTick(() => { this.$nextTick(() => {
this.$bus.$emit('value-updated', this.street + ',' + this.$bus.$emit('value-updated', this.street + ',' +
street_id); street_id);
}) })
}).catch(err => { }).catch(err => {
this.isshow = false this.isshow = false
uni.showToast({ uni.showToast({
title: err, title: err,
icon: 'none' icon: 'none'
}) })
this.street = '定位失败' this.street = '定位失败'
}) })
}, },
fail: (err) => { fail: (err) => {
console.log(err); console.log(err);
uni.setStorageSync("RejectTarget", true) uni.setStorageSync("RejectTarget", true)
this.isshow = false this.isshow = false
this.street = '定位失败' this.street = '定位失败'
Toast('定位失败,请检查定位权限是否开启') Toast('定位失败,请检查定位权限是否开启')
} }
}); });
}, },
/** /**
* 设置手机通知权限 * 设置手机通知权限

View File

@ -308,7 +308,7 @@
page: 1, page: 1,
limit: 10, limit: 10,
order: 'location', order: 'location',
merchant_category_id: '', //id merchant_category_id: '', ///id
category_id: '', //id category_id: '', //id
type_id: '', type_id: '',
street_id: '', street_id: '',
@ -738,7 +738,7 @@
this.status = "loading" this.status = "loading"
this.loading = true this.loading = true
let rqData = { let rqData = {
keyword: this.storeParam.keyword, // keyword: this.storeParam.keyword,
page: this.storeParam.page, page: this.storeParam.page,
limit: 10, limit: 10,
order: this.storeParam.order, order: this.storeParam.order,
@ -746,7 +746,7 @@
type_id: this.storeParam.type_id, type_id: this.storeParam.type_id,
credit_buy: this.credit_buy, credit_buy: this.credit_buy,
} }
rqData.street_id = this.storeParam.street_id // rqData.street_id = this.storeParam.street_id
if (this.latitude) { if (this.latitude) {
rqData.location = this.latitude + ',' + this.longitude rqData.location = this.latitude + ',' + this.longitude
} }

View File

@ -4,10 +4,10 @@
<view v-if="isFshow"> <view v-if="isFshow">
<view class="site-box flex_a_c_j_sb" :style="{'opacity':backColor}"> <view class="site-box flex_a_c_j_sb" :style="{'opacity':backColor}">
<view :class="['place_wrapper','flex_a_c',isFshow?'sitebox':'']" @click="selectLocation"> <view :class="['place_wrapper','flex_a_c',isFshow?'sitebox':'']" @click="changeMap">
<view :class="['iconfont','icon-weizhi',isFshow?'sitebox':'']" style="margin-left: 20rpx;"> <view :class="['iconfont','icon-weizhi',isFshow?'sitebox':'']" style="margin-left: 20rpx;">
</view> </view>
<view class="town_name">{{street}}</view> <view class="town_name">{{ street||'定位中' }}</view>
</view> </view>
<navigator url="/pages/chat/customer_list/index?type=0" hover-class="none"> <navigator url="/pages/chat/customer_list/index?type=0" hover-class="none">
<view :class="['iconfont','icon-xiaoxi',isFshow?'sitebox':'']" style="color:#fff;"></view> <view :class="['iconfont','icon-xiaoxi',isFshow?'sitebox':'']" style="color:#fff;"></view>
@ -207,6 +207,7 @@
import { import {
Toast Toast
} from '@/libs/uniApi' } from '@/libs/uniApi'
import { data } from '../../uni_modules/uview-ui/libs/mixin/mixin';
export default { export default {
components: { components: {
mTabbar, mTabbar,
@ -241,12 +242,12 @@
where: { where: {
category_id: 0, category_id: 0,
page: 1, page: 1,
limit: 6 limit: 10
}, },
where2: { where2: {
category_id: 0, category_id: 0,
page: 1, page: 1,
limit: 6 limit: 10
}, },
currentItemId: 69, // 0 || 69 currentItemId: 69, // 0 || 69
@ -272,9 +273,13 @@
} }
}, },
onPullDownRefresh() { onPullDownRefresh() {
this.loadend = false;
this.loading = false;
this.list(true, this.street_id); this.list(true, this.street_id);
this.Area() this.Area()
uni.stopPullDownRefresh() this.$u.sleep(1000).then(()=>{
uni.stopPullDownRefresh()
})
}, },
onShow() {}, onShow() {},
onLoad() { onLoad() {
@ -362,18 +367,18 @@
}, },
// //
list(isPage, id) { list(isPage=false, id) {
// if(!id) return that.list2(true, ''); // , // if(!id) return that.list2(true, ''); // ,
let that = this; let that = this;
if (that.loadend) return; if (that.loadend&&!isPage) return;
if (that.loading) return; if (that.loading&&!isPage) return;
if (isPage === true) { if (isPage === true) {
that.$set(that, 'productList', []); that.$set(that, 'productList', []);
that.$set(that, 'where', { that.$set(that, 'where', {
category_id: 0, category_id: 0,
page: 1, page: 1,
limit: 6 limit: 10
}) })
} }
that.$set(that, 'productList2', []); that.$set(that, 'productList2', []);
@ -389,7 +394,7 @@
}).then(res => { }).then(res => {
// console.log(222) // console.log(222)
let list = res.data.list; let list = res.data.list;
if (list.length == 0 && that.productList.length == 0 && that.where.page == 1) { if (res.data.count == 0 && isPage) {
that.list2(true, ''); that.list2(true, '');
} }
let productList = that.$util.SplitArray(list, that.productList); let productList = that.$util.SplitArray(list, that.productList);
@ -407,29 +412,30 @@
}); });
}, },
list2(isPage, id) { list2(isPage=false, id) {
let that = this; let that = this;
if (that.loadend2) return;
if (that.loading2) return; if (that.loadend2&&!isPage) return;
if (that.loading2&&!isPage) return;
if (isPage === true) { if (isPage === true) {
that.$set(that, 'productList2', []); that.$set(that, 'productList2', []);
that.$set(that, 'where2', { that.$set(that, 'where2', {
category_id: 0, category_id: 0,
page: 1, page: 1,
limit: 6 limit: 10
}) })
} }
that.$set(that, 'productList', []); that.$set(that, 'productList', []);
that.loading2 = true; that.loading2 = true;
that.loadTitle2 = ''; that.loadTitle2 = '';
spuRecommend({ let query = {
page: that.where2.page, page: that.where2.page,
limit: that.where2.limit, limit: that.where2.limit,
location: this.latitude + ',' + this.longitude };
}).then(res => { if(this.latitude&&this.longitude) query.location = this.latitude + ',' + this.longitude
// console.log(222) spuRecommend(query).then(res => {
let list = res.data.list; let list = res.data.list;
let productList = that.$util.SplitArray(list, that.productList2); let productList = that.$util.SplitArray(list, that.productList2);
let loadend = list.length < that.where2.limit; let loadend = list.length < that.where2.limit;
@ -604,7 +610,7 @@
if (uni.getStorageSync('RejectTarget')) return; if (uni.getStorageSync('RejectTarget')) return;
if (uni.getStorageSync('loction') == true) { if (uni.getStorageSync('loction') == true) {
this.isshow = false this.isshow = false
this.list2(true, '') this.list(true, '')
} else { } else {
this.isshow = true this.isshow = true
uni.setStorageSync('loction', true); uni.setStorageSync('loction', true);
@ -711,8 +717,14 @@
this.$set(this.where, 'page', 1) this.$set(this.where, 'page', 1)
this.$set(this.where2, 'page', 1) this.$set(this.where2, 'page', 1)
this.$set(this, 'productList', []); this.$set(this, 'productList', []);
this.list(true, this.street_id) uni.pageScrollTo({
this.$bus.$emit('value-updated', e.value[1].name + ',' + e.value[1].code); scrollTop: 0, // px
duration: 200 // 300ms ms
});
this.$nextTick(()=>{
this.list(true, this.street_id);
});
this.$bus.$emit('value-updated', e.street.name + ',' + e.street.code);
}) })
} }
}) })