1
0
Переглянути джерело

小程序详情分享前端修改,以及地图切换修改

hyq 6 роки тому
батько
коміт
99a7cd3218

+ 2 - 2
wx-mall/config/api.js

@@ -30,7 +30,7 @@ module.exports = {
     GoodsList: NewApiRootUrl + 'goods/list',  //获得商品列表
     GoodsCategory: NewApiRootUrl + 'goods/category',  //获得分类数据
     GoodsCategoryBrand: NewApiRootUrl + 'goods/brand',  //获得分类品牌数据
-    GoodsDetail: NewApiRootUrl + 'goods/detail',  //获得商品的详情
+    GoodsDetail: NewApiRootUrl + 'goods/details',  //获得商品的详情
     GoodsHot: NewApiRootUrl + 'goods/hot',  //热门
     GoodsRelated: NewApiRootUrl + 'goods/related',  //商品详情页的关联商品(大家都在看)
     GoodsCrashList: NewApiRootUrl + 'goodscrash/list',  //搭配减价
@@ -49,7 +49,7 @@ module.exports = {
     CartUpdate: NewApiRootUrl + 'cart/update', // 更新购物车的商品
     CartDelete: NewApiRootUrl + 'cart/delete', // 删除购物车的商品
     CartChecked: NewApiRootUrl + 'cart/checked', // 选择或取消选择商品
-    CartGoodsCount: NewApiRootUrl + 'cart/goodscount', // 获取购物车商品件数
+    CartGoodsCount: NewApiRootUrl + 'cart/goodscounts', // 获取购物车商品件数
     CartCheckout: NewApiRootUrl + 'cart/checkout', // 下单前信息确认
     CartCouponList: NewApiRootUrl + 'cart/checkedCouponList', // 选择用户可用优惠券
     GetFootCart: NewApiRootUrl + 'cart/getFootCart', // 底部购物车显示

+ 11 - 11
wx-mall/pages/cart/cart.wxml

@@ -46,12 +46,12 @@
           <view class="item" wx:for="{{cartGoods00}}" wx:if="{{item.goodsBizType == 00}}" wx:key="{{item.id}}">
             <view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}"  data-goods-Biz-Type="00" data-goods-Id="{{item.goods_id}}" data-checked="{{item.checked}}"></view>
             <view class="cart-goods">
-              <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+              <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                 <image class="img" src="{{item.list_pic_url}}"></image>
               </navigator>
               <view class="info">
                 <view class="t">
-                  <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+                  <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                     <text class="name">{{item.goods_name}}</text>
                   </navigator>
                   <view class="goods-do">
@@ -86,12 +86,12 @@
           <view class="item" wx:for="{{cartGoods02}}" wx:if="{{item.goodsBizType == 02}}" wx:key="{{item.id}}">
             <view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}" data-goods-Biz-Type="00" data-goods-Id="{{item.goods_id}}" data-checked="{{item.checked}}"></view>
             <view class="cart-goods">
-              <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+              <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                 <image class="img" src="{{item.list_pic_url}}"></image>
               </navigator>
               <view class="info">
                 <view class="t">
-                  <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+                  <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                     <text class="name">{{item.goods_name}}</text>
                   </navigator>
                   <view class="goods-do">
@@ -127,12 +127,12 @@
           <view class="item" wx:for="{{cartGoods10}}" wx:if="{{item.goodsBizType == 10}}" wx:key="{{item.id}}">
             <view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}" data-goods-Biz-Type="00" data-goods-Id="{{item.goods_id}}" data-checked="{{item.checked}}"></view>
             <view class="cart-goods">
-              <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+              <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                 <image class="img" src="{{item.list_pic_url}}"></image>
               </navigator>
               <view class="info">
                 <view class="t">
-                  <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+                  <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                     <text class="name">{{item.goods_name}}</text>
                   </navigator>
                   <view class="goods-do">
@@ -168,12 +168,12 @@
           <view class="item" wx:for="{{cartGoods11}}" wx:if="{{item.goodsBizType == 11}}" wx:key="{{item.id}}">
             <view class="checkbox {{item.checked ? 'checked' : ''}}" bindtap="checkedItem" data-item-index="{{index}}" data-goods-Biz-Type="00" data-goods-Id="{{item.goods_id}}" data-checked="{{item.checked}}"></view>
             <view class="cart-goods">
-              <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+              <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                 <image class="img" src="{{item.list_pic_url}}"></image>
               </navigator>
               <view class="info">
                 <view class="t">
-                  <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+                  <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                     <text class="name">{{item.goods_name}}</text>
                   </navigator>
                   <view class="goods-do">
@@ -215,12 +215,12 @@
           <view class="item" wx:for="{{validCartList}}" wx:key="{{item.id}}">
             <view class="shixiao">失效</view>
             <view class="cart-goods">
-              <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+              <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                 <image class="img" src="{{item.list_pic_url}}"></image>
               </navigator>
               <view class="info">
                 <view class="t">
-                  <navigator url="/pages/goods/goods?id={{item.goods_id}}">
+                  <navigator url="/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}">
                     <text class="name" style='color:rgba(87, 86, 86, 0.63);'>{{item.goods_name}} {{null==item.goods_specification_name_value?"":item.goods_specification_name_value}}</text>
                   </navigator>
                 </view>
@@ -245,7 +245,7 @@
       </view>
       <view class="b">
         <block wx:for="{{footprintList}}" wx:for-index="iindex" wx:for-item="iitem" wx:key="unique">
-          <navigator wx:if="{{iitem.retail_price > 0}}" class="item {{iindex % 2 == 0 ? 'item-b' : '' }}" url="../goods/goods?id={{iitem.goods_id}}">
+          <navigator wx:if="{{iitem.retail_price > 0}}" class="item {{iindex % 2 == 0 ? 'item-b' : '' }}" url="../goods/goods?id={{iitem.goods_id}}&&storeId={{item.storeId}}">
             <image class="img2" src="{{iitem.list_pic_url}}" ></image>
             <text class="name">{{iitem.name}}</text>
             <view class="price" data-goods-id="{{iitem.goods_id}}" catchtap='addCart' >¥{{iitem.retail_price}}

+ 3 - 3
wx-mall/pages/catalog/catalog.wxml

@@ -125,7 +125,7 @@
 
         <!-- 商品开始 -->
         <view class="item" wx:for="{{goodsList}}" wx:for-index="index" wx:for-item="item" wx:key="{{item.id}}">
-          <navigator url="/pages/goods/goods?id={{item.id}}">
+          <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
             <view class="left">
               <image class="img" wx:if="{{item.list_pic_url}}" src="{{item.list_pic_url}}"></image>
             </view>
@@ -133,14 +133,14 @@
           <!-- 文字开始 -->
           <view class="right">
             <view class="text">
-            <navigator url="/pages/goods/goods?id={{item.id}}">
+            <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
               <text class="name" bindtap="bindtapGoodsDetail" data-item-id="{{filterDiscount != 2?item.id:item.group_id}}">{{item.name?item.name:""}}</text>
               <text class="desc" bindtap="bindtapGoodsDetail" data-item-id="{{filterDiscount != 2?item.id:item.group_id}}">{{item.goods_brief?item.goods_brief:""}}</text>
             </navigator>
 
             <!-- 描述开始 -->
             <view class="goods-do">
-              <navigator url="/pages/goods/goods?id={{item.id}}">
+              <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
                 <text class="price">{{item.retail_price?"¥"+item.retail_price:"¥0"}}</text>
                 <text class="org-price line-through">{{item.market_price?"¥"+item.market_price:""}}</text>
               </navigator>

+ 1 - 1
wx-mall/pages/category/category.wxml

@@ -64,7 +64,7 @@
     <view class="b">
       <block wx:for="{{goodsList}}" wx:for-index="iindex" wx:for-item="iitem" wx:key="unique">
         <view class="item {{iindex % 2 == 0 ? 'item-b' : '' }}">
-         <navigator url="../goods/goods?id={{iitem.id}}&&currentIndex={{navIndex}}">
+         <navigator url="../goods/goods?id={{iitem.id}}&&currentIndex={{navIndex}}&&storeId={{item.storeId}}">
             <image class="img" src="{{iitem.list_pic_url}}"></image>
             <text class="name">{{iitem.name}}</text>
           </navigator>

+ 33 - 21
wx-mall/pages/goods/goods.js

@@ -43,7 +43,9 @@ Page({
     imgHiddenName: false,
     page: 1,
     size: 4,
-    detailContent: ''
+    detailContent: '',
+    storeId: '',
+    detailStoreId: ''
   },
   toggleNav() {
     this.setData({
@@ -70,8 +72,9 @@ Page({
     }, 350)
     let that = this;
     const regex = new RegExp('<img', 'gi');
+    console.log('分享的storeId'+ wx.getStorageSync('storeId'))
     util.request(api.GoodsDetail, { id: that.data.id, referrer: this.data.referrer, 
-      merchSn: wx.getStorageSync('merchSn') }).then(function (res) {
+      merchSn: wx.getStorageSync('merchSn'), storeId: wx.getStorageSync('storeId') }).then(function (res) {
       if (res.errno === 0) {
         that.setData({
           goods: res.data.info,
@@ -87,7 +90,8 @@ Page({
           cartNumber: res.data.cartNumber,
           defaultFreight: res.data.defaultFreight,
           checkedSpecText: res.data.specificationList[0].valueList[0].value,
-          detailContent: that.escape2Html(res.data.info.goods_desc).replace(regex, `<img style="width: 100%;"`)
+          detailContent: that.escape2Html(res.data.info.goods_desc).replace(regex, `<img style="width: 100%;"`),
+          detailStoreId:res.data.info.storeId
         });
 
         if (res.data.userHasCollect == 1) {
@@ -183,19 +187,16 @@ Page({
   onLoad: function (options) {
     // 页面初始化 options为页面跳转所带来的参数
     this.setData({
-      id: parseInt(options.id)
+      id: parseInt(options.id),
+      storeId: options.storeId
       // id: 1181000
     });
-    var that = this;
-    this.getGoodsInfo();
-    util.request(api.CartGoodsCount).then(function (res) {
-      if (res.errno === 0) {
-        that.setData({
-          cartGoodsCount: res.data.cartTotal.goodsCount
-        });
 
-      }
-    });
+    if(options.storeId){
+      wx.setStorageSync('storeId', options.storeId);
+      wx.setStorageSync('isShare', 'true');
+    }
+    console.log('分享的storeId1:' + wx.getStorageSync('storeId'))
     var that = this;
     //  高度自适应
     wx.getSystemInfo({
@@ -269,6 +270,15 @@ Page({
             wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
             wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
             that.reLoad();
+
+            that.getGoodsInfo();
+            util.request(api.CartGoodsCount, { storeId: wx.getStorageSync('storeId') }).then(function (res) {
+              if (res.errno === 0) {
+                that.setData({
+                  cartGoodsCount: res.data.cartTotal.goodsCount
+                });
+              }
+            });
           }
         });
       }
@@ -387,10 +397,11 @@ Page({
         util.showErrorToast('库存不足');
         //找不到对应的product信息,提示没有库存
         return false;
-      }
+      } 
+      // console.log(that.data.productList)
       // //根据选中的规格,判断是否有对应的sku信息
       let checkedProduct = goodsUtil.getCheckedProductItem(goodsUtil.getCheckedSpecKey(that), that);
-      console.log(checkedProduct)
+      // console.log(goodsUtil.getCheckedSpecKey(that))
       if (!checkedProduct || checkedProduct.length <= 0) {
         wx.showToast({
           title: '库存不足',
@@ -399,7 +410,6 @@ Page({
         //找不到对应的product信息,提示没有库存
         return false;
       }
-
       //验证库存
       // if (checkedProduct.goods_number < this.data.number) {
       //   //找不到对应的product信息,提示没有库存
@@ -458,13 +468,15 @@ Page({
   onShareAppMessage: function () {
     var that = this;
     // console.log("url:" + that.data.goods.list_pic_url);
-    // var userId = wx.getStorageSync('userId');
-    // console.log("userId:" + userId);
+    var userId = wx.getStorageSync('userId');
+    console.log("userId:" + userId);
+    console.log("detailStoreId:" + that.data.detailStoreId);
+
     return {
-      title: '商业版',
-      desc: null != that.data.goods.name ? that.data.goods.name : "商业版",
+      title: '商品详情',
+      desc: null != that.data.goods.name ? that.data.goods.name : "商品详情",
       imageUrl: that.data.goods.list_pic_url,
-      path: '/pages/goods/goods?id=' + that.data.id + '&&referrer=' + wx.getStorageSync('userId'),
+      path: '/pages/goods/goods?id=' + that.data.id + '&&referrer=' + wx.getStorageSync('userId') + '&&storeId=' + that.data.detailStoreId,
       success: function (res) {
         console.log("转发成功");
         // 转发成功

+ 4 - 4
wx-mall/pages/goods/goods.wxml

@@ -129,14 +129,14 @@
       <image class="i" src="../../static/images/address_right.png" background-size="cover"></image>
     </view>
 
-    <view class="crash-goods" wx:if="{{crashList.length > 0}}" bindtap="hideSwitchAttrPop">
+    <!-- <view class="crash-goods" wx:if="{{crashList.length > 0}}" bindtap="hideSwitchAttrPop">
       <view class="h">
         <view class="line"></view>
         <text class="title">搭配减价</text>
       </view>
       <view class="b">
         <view class="item" wx:for="{{crashList}}" wx:key="{{item.id}}">
-          <navigator url="/pages/goods/goods?id={{item.goods_crash_id}}">
+          <navigator url="/pages/goods/goods?id={{item.goods_crash_id}}&&storeId={{item.storeId}}">
             <image class="img" src="{{item.list_pic_url}}" background-size="cover"></image>
             <text class="name">{{item.name}}</text>
           </navigator>
@@ -148,7 +148,7 @@
           </view>
         </view>
       </view>
-    </view>
+    </view> -->
 
     <!--<view class="section-nav section-act">
       <view class="t">
@@ -239,7 +239,7 @@
       </view>
       <view class="b">
         <view class="item" wx:for="{{relatedGoods}}" wx:key="{{item.id}}">
-          <navigator url="/pages/goods/goods?id={{item.id}}">
+          <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
             <image class="img" src="{{item.list_pic_url}}"></image>
             <text class="name">{{item.name}}</text>
             <view class="price">¥{{item.retail_price}}

+ 1 - 1
wx-mall/pages/hotGoods/hotGoods.wxml

@@ -81,7 +81,7 @@
       <block wx:for="{{goodsList}}" wx:for-index="iindex" wx:for-item="iitem" wx:key="unique">
         <view class="item {{iindex % 2 == 0 ? 'item-b' : '' }}">
 
-          <navigator url="../goods/goods?id={{iitem.id}}">
+          <navigator url="../goods/goods?id={{iitem.id}}&&storeId={{item.storeId}}">
             <image class="img" src="{{iitem.list_pic_url}}" ></image>
             <text class="name">{{iitem.name}}</text>
           </navigator>

+ 14 - 3
wx-mall/pages/index/index.js

@@ -114,17 +114,27 @@ Page({
   onLoad: function (options) {
     let that = this;
     wx.setStorageSync("navUrl", "/pages/index/index");
-    // options.scene = 38;
+    // options.scene = 42;
+
     if (options.scene) {
+      console.log("have scene");
       var scene = decodeURIComponent(options.scene);
       console.log("scene is ", scene);
       that.setData({
         storeId: scene
       });
       wx.setStorageSync('storeId', scene);
+      wx.removeStorageSync('isShare');//扫码进入的小程序则清除是否分享缓存
     } else {
-      wx.removeStorageSync('storeId');
-      console.log("no scene");
+      console.log("wx.getStorageSync('isShare')"+wx.getStorageSync('isShare'));
+      if (wx.getStorageSync('isShare')) {//是否分享过商品,有数据则分享过;从首页进入页面则没有分享过,从详情页进入则分享过
+        console.log('是分享进入首页门店id:' + wx.getStorageSync('storeId')+',从商品也获取的缓存')
+        console.log('是分享进入首页:' + wx.getStorageSync('isShare'))
+      } else {
+        wx.removeStorageSync('storeId');
+        console.log('不是分享进入首页门店id:【' + wx.getStorageSync('storeId')+'】,获取最近门店')
+        console.log('不是分享进入首页:' + wx.getStorageSync('isShare'))
+      }
     }
   },
   onReady: function () {
@@ -224,6 +234,7 @@ Page({
     util.getLocation((lng, lat) => {
       wx.setStorageSync('location', JSON.stringify({ lng, lat }));
       let storeId = wx.getStorageSync('storeId');
+      console.log('查询门店id:' + storeId)
       util.request(api.NearbyList, { longitude: lng, latitude: lat, storeId: storeId, thirdPartyMerchCode: '' }).then((res) => {
         let nlist = res.data;
         // wx.removeStorageSync('nearStoreList');

+ 2 - 2
wx-mall/pages/index/index.wxml

@@ -167,13 +167,13 @@
     <view class="b">
       <view class="item" wx:for="{{hotGoods}}" wx:for-index="index" wx:for-item="item" wx:key="{{item.id}}">
         <view class="c">
-          <navigator url="/pages/goods/goods?id={{item.id}}">
+          <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
             <image class="img" src="{{item.list_pic_url}}" mode="aspectFill"></image>
           </navigator>
         </view>
         <view class="right">
           <view class="text">
-            <navigator url="/pages/goods/goods?id={{item.id}}">
+            <navigator url="/pages/goods/goods?id={{item.id}}&&storeId={{item.storeId}}">
               <text class="name">{{item.name?item.name:""}}</text>
               <text class="desc">{{item.goods_brief?item.goods_brief:""}}</text>
             </navigator>

+ 1 - 1
wx-mall/pages/ucenter/orderDetail/orderDetail.wxml

@@ -75,7 +75,7 @@
             <text class="num fr">x{{item.number}}</text>
             <text class="price fr">¥{{item.retail_price}}</text>
           </view>
-          <navigator open-type='navigate' wx:if = '{{currentStoreId == orderInfo.store_id && (orderInfo.orderBizType ==00 || orderInfo.orderBizType == 11)}}' url='/pages/goods/goods?id={{item.goods_id}}'>
+          <navigator open-type='navigate' wx:if = '{{currentStoreId == orderInfo.store_id && (orderInfo.orderBizType ==00 || orderInfo.orderBizType == 11)}}' url='/pages/goods/goods?id={{item.goods_id}}&&storeId={{item.storeId}}'>
             <image class="order-image" src="{{item.list_pic_url}}"></image>
             <text class="name">{{item.goods_name}}</text>
             <text class="num fr">x{{item.number}}</text>

+ 1 - 1
wx-mall/project.config.json

@@ -11,7 +11,7 @@
 	"compileType": "miniprogram",
 	"libVersion": "2.6.2",
 	"appid": "wxb6b30b1b14ee502a",
-	"projectname": "kmall-mp",
+	"projectname": "wx-mall",
 	"condition": {
 		"search": {
 			"current": -1,