|
|
@@ -34,7 +34,7 @@
|
|
|
<view class="tui-input" v-if="form.province">{{ form.province + '-' + form.city }}</view>
|
|
|
<view class="tui-placeholder" v-else>请选择城市</view>
|
|
|
</view>
|
|
|
- <view class="city-locate-btn" @click.stop="openNearbyAddress">
|
|
|
+ <view class="city-locate-btn" @click.stop="locateCity">
|
|
|
<image class="city-locate-icon" src="/static/images/common/localposition.png" mode="aspectFit"></image>
|
|
|
</view>
|
|
|
</tui-list-cell>
|
|
|
@@ -301,12 +301,27 @@ export default {
|
|
|
}
|
|
|
this.modifyShow()
|
|
|
},
|
|
|
- async openNearbyAddress() {
|
|
|
- if (this.locating) {
|
|
|
+ fillCityFromNearby(first) {
|
|
|
+ if (!first) {
|
|
|
return false
|
|
|
}
|
|
|
+ if (first.province) {
|
|
|
+ this.form.province = first.province
|
|
|
+ }
|
|
|
+ if (first.city) {
|
|
|
+ this.form.city = first.city
|
|
|
+ }
|
|
|
+ if (first.district) {
|
|
|
+ this.form.dist = first.district
|
|
|
+ }
|
|
|
+ this.modifyShow()
|
|
|
+ },
|
|
|
+ async loadNearbyAddressList(fillCity) {
|
|
|
+ if (this.locating) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
this.locating = true
|
|
|
- uni.showLoading({ title: '定位中', mask: true })
|
|
|
+ uni.showLoading({ title: fillCity ? '定位中' : '加载中', mask: true })
|
|
|
try {
|
|
|
await this.ensureAppLocationPermission()
|
|
|
const location = await this.getDeviceLocation()
|
|
|
@@ -316,35 +331,34 @@ export default {
|
|
|
locationType: location.locationType || 'gcj02'
|
|
|
})
|
|
|
if (res.code != 1 || !res.data || !res.data.list || res.data.list.length === 0) {
|
|
|
- this.$msg('未获取到附近地址,请手动填写')
|
|
|
- return false
|
|
|
+ if (fillCity) {
|
|
|
+ this.$msg('未获取到位置,请手动选择城市')
|
|
|
+ }
|
|
|
+ return []
|
|
|
}
|
|
|
const list = res.data.list
|
|
|
- const first = list[0]
|
|
|
- if (first) {
|
|
|
- if (first.province) {
|
|
|
- this.form.province = first.province
|
|
|
- }
|
|
|
- if (first.city) {
|
|
|
- this.form.city = first.city
|
|
|
- }
|
|
|
- if (first.district) {
|
|
|
- this.form.dist = first.district
|
|
|
- }
|
|
|
- this.modifyShow()
|
|
|
+ if (fillCity) {
|
|
|
+ this.fillCityFromNearby(list[0])
|
|
|
}
|
|
|
this.addressInitialList = list
|
|
|
- this.showRegion = true
|
|
|
- return true
|
|
|
+ return list
|
|
|
} catch (err) {
|
|
|
- console.log('openNearbyAddress fail', err)
|
|
|
- this.$msg((err && err.message) ? err.message : '定位失败,请手动填写')
|
|
|
- return false
|
|
|
+ console.log('loadNearbyAddressList fail', err)
|
|
|
+ if (fillCity) {
|
|
|
+ this.$msg((err && err.message) ? err.message : '定位失败,请手动填写')
|
|
|
+ }
|
|
|
+ return []
|
|
|
} finally {
|
|
|
this.locating = false
|
|
|
uni.hideLoading()
|
|
|
}
|
|
|
},
|
|
|
+ async locateCity() {
|
|
|
+ const list = await this.loadNearbyAddressList(true)
|
|
|
+ if (list.length > 0) {
|
|
|
+ this.$msg('已定位到当前城市')
|
|
|
+ }
|
|
|
+ },
|
|
|
cancelAutoMobile() {
|
|
|
this.$util.confirmModal({
|
|
|
content: '取消后将清空已获取的手机号,需重新填写并验证,是否确认?',
|
|
|
@@ -497,6 +511,12 @@ export default {
|
|
|
this.$msg('请先选择城市或点击定位图标')
|
|
|
return false
|
|
|
}
|
|
|
+ this.openAddressSelector()
|
|
|
+ },
|
|
|
+ async openAddressSelector() {
|
|
|
+ if (!this.addressInitialList || this.addressInitialList.length === 0) {
|
|
|
+ await this.loadNearbyAddressList(false)
|
|
|
+ }
|
|
|
this.showRegion = true
|
|
|
},
|
|
|
changeAreaFn(e) {
|