Parcourir la source

fix 增加门店定位

wzh il y a 3 mois
Parent
commit
516ee6905d
1 fichiers modifiés avec 33 ajouts et 2 suppressions
  1. 33 2
      pages/hexiao/ywy/add_retail.vue

+ 33 - 2
pages/hexiao/ywy/add_retail.vue

@@ -34,7 +34,7 @@
         />
       </view>
 
-      <view class="form-item">
+      <view class="form-item" style="position: relative">
         <text class="form-label">店铺地址</text>
         <input
             class="form-input"
@@ -42,6 +42,8 @@
             placeholder="请输入店铺地址"
             placeholder-class="placeholder"
         />
+        <uni-icons @click="getLocation" style="position: absolute;bottom:20px;right: 20px;z-index: 999" type="location-filled" size="30" color="#3c82f8"></uni-icons>
+
       </view>
 
       <view class="form-item">
@@ -68,12 +70,13 @@
 </template>
 
 <script>
-import {addStore, getRetailDetail, updateStore, uploadImage} from "@/api/hexiao";
+import {addStore, getRetailDetail, updateStore, uploadImage,parseLocation} from "@/api/hexiao";
 
 export default {
   data() {
     return {
       edit:false,
+      isLocating:false,
       // 表单数据
       formData: {
         photos: [],
@@ -108,6 +111,34 @@ export default {
       }
   },
   methods: {
+    getLocation() {
+      this.isLocating = true;
+      let self = this;
+      uni.getLocation({
+        type: 'gcj02', // 'wgs84' GPS坐标, 'gcj02' 国测局坐标
+        isHighAccuracy: true,
+        geocode: true, // 获取带有地址信息(仅App和H5支持)
+        success: (res) => {
+          console.log('当前位置信息:', res);
+          parseLocation(res.latitude, res.longitude).then(res=>{
+            if("Success" === res.data.message){
+              let formatted_addresses = res.data.result.formatted_addresses
+              self.formData.address = formatted_addresses.standard_address
+            }else{
+              uni.showToast({ title: '解析地址失败', icon: 'none' });
+            }
+
+          })
+        },
+        fail: (err) => {
+          uni.showToast({ title: '获取位置失败', icon: 'none' });
+          console.error(err);
+        },
+        complete: () => {
+          this.isLocating = false;
+        }
+      });
+    },
     // 提交表单
     async submitForm() {
       if(this.$refs.files.files.length === 0){