18016688350 4 years ago
parent
commit
2dd82bce72
7 changed files with 78 additions and 26 deletions
  1. 6 0
      app.json
  2. 1 1
      pages/login/index.wxml
  3. 34 11
      pages/store/add.js
  4. 1 1
      pages/store/add.wxml
  5. 34 11
      pages/store/edit.js
  6. 1 1
      pages/store/edit.wxml
  7. 1 1
      project.config.json

+ 6 - 0
app.json

@@ -95,5 +95,11 @@
     "scope.userLocation": {
       "desc": "你的位置信息将用于小程序位置接口的效果展示"
     }
+  },
+  "plugins": {
+    "chooseLocation": {
+      "version": "1.0.9",
+      "provider": "wx76a9a06e5b4e693e"
+    }
   }
 }

+ 1 - 1
pages/login/index.wxml

@@ -2,7 +2,7 @@
   <view class="tui-bg-box">
     <image src="../../static/images/my/bg_login.png" class="tui-bg-img"></image>
     <image src="../../static/images/my/mengguo192.png" class="tui-photo"></image>
-    <view class="tui-login-name">梦果</view>
+    <view class="tui-login-name">梦果售货机</view>
   </view>
   <form bindsubmit="login">
     <view class="tui-login-from">

+ 34 - 11
pages/store/add.js

@@ -2,8 +2,28 @@ const utils = require('../../utils/util')
 const form = require('../../utils/formValidation')
 const util = require('../../utils/util.js');
 const app = getApp();
+const chooseLocation = requirePlugin('chooseLocation');
 Page({
+  // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
+  onShow () {
+    const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
+    console.log(location)
+    if(location!=null){
+      console.log("")
+      this.setData({
+        ["storeInfo.storeAddress"]: location.name,
+        ["storeInfo.latitude"]: location.latitude,
+        ["storeInfo.longitude"]: location.longitude,
+      });
+
+    }
+
 
+  },
+  onUnload () {
+    // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
+    chooseLocation.setLocation(null);
+  },
   /**
    * 页面的初始数据
    */
@@ -51,12 +71,6 @@ Page({
 
   },
 
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
-
-  },
 
   /**
    * 生命周期函数--监听页面隐藏
@@ -65,12 +79,7 @@ Page({
 
   },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
 
-  },
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
@@ -181,4 +190,18 @@ Page({
       [name]: _this.data[name]
     });
   },
+  //选择地图
+  selectMap(){
+    const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
+    const referer = '梦果宝盒'; //调用插件的app的名称
+    const location = JSON.stringify({
+      latitude: 39.89631551,
+      longitude: 116.323459711
+    });
+    const category = '生活服务,娱乐休闲';
+    
+    wx.navigateTo({
+      url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
+    });
+  }
 })

+ 1 - 1
pages/store/add.wxml

@@ -52,7 +52,7 @@
     <tui-list-cell hover="{{false}}">
       <view class="tui-line-cell">
         <view class="tui-title">详细地址:</view>
-        <input placeholder-class="phcolor" class="tui-input" name="storeAddress" placeholder="请输入所在地区" catchinput="inputedit" data-name="storeInfo.storeAddress"/>
+        <input placeholder-class="phcolor" bindtap="selectMap" class="tui-input" name="storeAddress" placeholder="请输入所在地区" catchinput="inputedit" value="{{storeInfo.storeAddress}}" data-name="storeInfo.storeAddress"/>
       </view>
     </tui-list-cell>
 

+ 34 - 11
pages/store/edit.js

@@ -3,8 +3,28 @@ const utils = require('../../utils/util')
 const form = require('../../utils/formValidation')
 const util = require('../../utils/util.js');
 const app = getApp();
+const chooseLocation = requirePlugin('chooseLocation');
 Page({
+  // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象
+  onShow () {
+    const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
+    console.log(location)
+    if(location!=null){
+      console.log("")
+      this.setData({
+        ["storeInfo.storeAddress"]: location.name,
+        ["storeInfo.latitude"]: location.latitude,
+        ["storeInfo.longitude"]: location.longitude,
+      });
+
+    }
+
 
+  },
+  onUnload () {
+    // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
+    chooseLocation.setLocation(null);
+  },
   /**
    * 页面的初始数据
    */
@@ -56,12 +76,7 @@ Page({
 
   },
 
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
 
-  },
 
   /**
    * 生命周期函数--监听页面隐藏
@@ -70,12 +85,6 @@ Page({
 
   },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
-
-  },
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
@@ -216,4 +225,18 @@ Page({
       [name]: _this.data[name]
     });
   },
+    //选择地图
+    selectMap(){
+      const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key
+      const referer = '梦果宝盒'; //调用插件的app的名称
+      const location = JSON.stringify({
+        latitude: 39.89631551,
+        longitude: 116.323459711
+      });
+      const category = '生活服务,娱乐休闲';
+      
+      wx.navigateTo({
+        url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}`
+      });
+    }
 })

+ 1 - 1
pages/store/edit.wxml

@@ -53,7 +53,7 @@
     <tui-list-cell hover="{{false}}">
       <view class="tui-line-cell">
         <view class="tui-title">详细地址:</view>
-        <input placeholder-class="phcolor" class="tui-input" name="storeAddress" placeholder="请输入所在地区" catchinput="inputedit" value="{{storeInfo.storeAddress}}" data-name="storeInfo.storeAddress"/>
+        <input placeholder-class="phcolor" class="tui-input"  bindtap="selectMap" name="storeAddress" placeholder="请输入所在地区" catchinput="inputedit" value="{{storeInfo.storeAddress}}" data-name="storeInfo.storeAddress"/>
       </view>
     </tui-list-cell>
 

+ 1 - 1
project.config.json

@@ -37,7 +37,7 @@
   },
   "compileType": "miniprogram",
   "libVersion": "2.14.4",
-  "appid": "wx788fbe16a4cdacdc",
+  "appid": "wxc42df73f9710a566",
   "projectname": "mg-vending-machine-applets-manage",
   "debugOptions": {
     "hidedInDevtools": []