|
|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
<view class="list-wrap">
|
|
|
<ListScrollView
|
|
|
+ v-if="locationReady"
|
|
|
ref="listScroll"
|
|
|
:api="api"
|
|
|
:init="initParams"
|
|
|
@@ -62,7 +63,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import prepaidApi, { getMerchantId } from '@/api/memberPrepaid.js'
|
|
|
+ import prepaidApi, { getMerchantId, getMerchantLocation, formatStoreDistance } from '@/api/memberPrepaid.js'
|
|
|
import ListScrollView from '@/components/list-scroll-view/index.vue'
|
|
|
|
|
|
const DEFAULT_LOGO = '/static/index/shop.png'
|
|
|
@@ -79,27 +80,48 @@
|
|
|
confirmVisible: false,
|
|
|
pendingDelete: null,
|
|
|
deleting: false,
|
|
|
+ longitude: null,
|
|
|
+ latitude: null,
|
|
|
+ locationReady: false,
|
|
|
api: {
|
|
|
url: `${BASE}/store/shared/page`,
|
|
|
method: 'GET'
|
|
|
},
|
|
|
initParams: {
|
|
|
merchantId: getMerchantId()
|
|
|
- },
|
|
|
- _listReady: false
|
|
|
+ }
|
|
|
};
|
|
|
},
|
|
|
onShow() {
|
|
|
this.confirmVisible = false;
|
|
|
this.pendingDelete = null;
|
|
|
this.refreshEnabled();
|
|
|
- this.initParams = { merchantId: getMerchantId() };
|
|
|
- // 首次由 ListScrollView 自动加载;从添加页返回时刷新
|
|
|
- if (this._listReady && this.$refs.listScroll && this.$refs.listScroll.mescroll) {
|
|
|
- this.$refs.listScroll.reloadList(this.initParams);
|
|
|
- } else {
|
|
|
- this._listReady = true;
|
|
|
- }
|
|
|
+ this.ensureLocation()
|
|
|
+ .then((loc) => {
|
|
|
+ this.initParams = {
|
|
|
+ merchantId: getMerchantId(),
|
|
|
+ longitude: loc.longitude,
|
|
|
+ latitude: loc.latitude
|
|
|
+ };
|
|
|
+ if (this.locationReady && this.$refs.listScroll && this.$refs.listScroll.mescroll) {
|
|
|
+ this.$refs.listScroll.reloadList(this.initParams);
|
|
|
+ } else {
|
|
|
+ // 等经纬度就绪后再挂载列表,避免无坐标请求一次
|
|
|
+ this.locationReady = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ this.initParams = { merchantId: getMerchantId() };
|
|
|
+ uni.showToast({
|
|
|
+ title: (err && err.message) || '获取门店位置失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ if (this.locationReady && this.$refs.listScroll && this.$refs.listScroll.mescroll) {
|
|
|
+ this.$refs.listScroll.reloadList(this.initParams);
|
|
|
+ } else {
|
|
|
+ this.locationReady = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
methods: {
|
|
|
formatRating(item) {
|
|
|
@@ -126,6 +148,19 @@
|
|
|
distance: formatStoreDistance(item)
|
|
|
};
|
|
|
},
|
|
|
+ ensureLocation() {
|
|
|
+ if (this.longitude != null && this.latitude != null) {
|
|
|
+ return Promise.resolve({
|
|
|
+ longitude: this.longitude,
|
|
|
+ latitude: this.latitude
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return getMerchantLocation().then((loc) => {
|
|
|
+ this.longitude = loc.longitude;
|
|
|
+ this.latitude = loc.latitude;
|
|
|
+ return loc;
|
|
|
+ });
|
|
|
+ },
|
|
|
afterFetch(result) {
|
|
|
const records = Array.isArray(result.records)
|
|
|
? result.records
|