1
0
Selaa lähdekoodia

选择门店修改

dq 6 vuotta sitten
vanhempi
commit
3e8490db29
3 muutettua tiedostoa jossa 80 lisäystä ja 21 poistoa
  1. 65 17
      wx-mall/pages/map/map.js
  2. 2 1
      wx-mall/pages/map/map.wxml
  3. 13 3
      wx-mall/pages/map/map.wxss

+ 65 - 17
wx-mall/pages/map/map.js

@@ -13,7 +13,9 @@ Page({
     longitude: "",
     // 标记点 当前位置
     markers: [],
-    isShow: true,
+    nearStoreList: [],
+    isShow: false,
+    storeId: "",
     storeName: "",
     storeAddress: "",
     distance: ""
@@ -23,33 +25,29 @@ Page({
     this.mapCtx = wx.createMapContext('myMap');
     this.mapCtx.moveToLocation();
 
+    let nearStoreList = wx.getStorageSync('nearStoreList') ? JSON.parse(wx.getStorageSync('nearStoreList')) : [];
+    this.setData({
+      nearStoreList: nearStoreList
+    })
   
     let that = this;
     util.getLocation((lng, lat) => {
       util.request(api.NearbyList, { longitude: lng, latitude: lat }).then((res) => {
         let markers = [];
-        let marker = {
-          iconPath: "/static/images/myAddress.png",
-          id: 0,
-          latitude: lat,
-          longitude: lng,
-          width: 35,
-          height: 35,
-          clickable: true,
-          
-        };
-        markers.push(marker);
-
         let nlist = res.data;
-        for (var i = 1; i <= nlist.length; i++) {
+        for (var i = 0; i < nlist.length; i++) {
           let marker = {
             iconPath: "/static/images/address.png",
             id: i,
-            latitude: nlist[i-1].latitude,
-            longitude: nlist[i-1].longitude,
+            latitude: nlist[i].latitude,
+            longitude: nlist[i].longitude,
             width: 35,
             height: 35,
-            clickable: true
+            clickable: true,
+            storeId: nlist[i].id,
+            storeName: nlist[i].storeName,
+            storeAddress: nlist[i].storeAddress,
+            distance: nlist[i].distance
           };
           markers.push(marker);
         }
@@ -77,5 +75,55 @@ Page({
   onUnload: function () {
     // 页面关闭
 
+  },
+  markersClick: function(res) {
+    console.log(res);
+    let that = this;
+    if (res.markerId == 0) {
+      that.setData({
+        isShow: false
+      });
+      return;
+    }
+
+    let marker = that.data.markers[res.markerId];
+    that.setData({
+      isShow: true,
+      storeId: marker.storeId,
+      storeName: marker.storeName,
+      storeAddress: marker.storeAddress,
+      distance: marker.distance
+    });
+  },
+  chooseStore(e) {
+    console.log(e.currentTarget.id)
+    let storeId = e.currentTarget.id;
+
+    let that = this;
+    util.request(api.ChooseStoreId, { storeId: storeId }, 'POST').then(function (res) {
+      if (res.errno === 0) {
+        wx.setStorageSync('storeId', storeId);
+        var item = "";
+        for (var i = 0; i < that.data.nearStoreList.length; i++) {
+          if (storeId == that.data.nearStoreList[i].id) {
+            item = that.data.nearStoreList[i];
+            wx.setStorageSync('storeVo', JSON.stringify(item));
+          }
+        }
+        var pages = getCurrentPages();
+        var currPage = pages[pages.length - 1];  //当前页面
+        var prevPage = pages[pages.length - 2]; //上一个页面
+
+        //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
+        prevPage.setData({
+          storeName: item.storeName
+        })
+        prevPage.getIndexData();
+        prevPage.enableActivity();
+        prevPage.getGroupData();
+
+        wx.navigateBack()
+      }
+    })
   }
 })

+ 2 - 1
wx-mall/pages/map/map.wxml

@@ -1,9 +1,10 @@
 <view class="map_container">
-  <map class="map" longitude="{{longitude}}" latitude="{{latitude}}" markers='{{markers}}' show-location bindmarkertap='getInfo'>
+  <map class="map" longitude="{{longitude}}" latitude="{{latitude}}" markers='{{markers}}' show-location bindmarkertap='markersClick'>
       <cover-view class="map-tab-bar map-foot {{isShow ? '' : 'map-hide'}}">
         <cover-view class="map-storeName">{{storeName}}</cover-view>
         <cover-view class="map-storeAddress">{{storeAddress}}</cover-view>
         <cover-view class="map-distance">距离当前定位地址{{distance}}米</cover-view>
+        <button id="{{storeId}}" bindtap='chooseStore'>确定</button>
       </cover-view>
   </map>
 </view>

+ 13 - 3
wx-mall/pages/map/map.wxss

@@ -30,17 +30,27 @@
 .map-foot {
   top: auto;
   bottom: 0;
-  padding: 0 10px;
+  padding: 10px 10px;
 }
 
-.map-name {
+.map-storeName {
   height: 80rpx;
   line-height: 80rpx;
   font-size: 35rpx;
   overflow: hidden;
 }
 
-.map-address {
+.map-storeAddress {
+  height: auto;
+  width: 700rpx;
+  display: block;
+  white-space: pre-line;
+  line-height: 45rpx;
+  font-size: 25rpx;
+  overflow: hidden;
+}
+
+.map-distance {
   height: 60rpx;
   line-height: 60rpx;
   font-size: 25rpx;