From bbc2b008fd15f94d20aeea6b91ee4baa8d2c3ce6 Mon Sep 17 00:00:00 2001 From: cheng.xu Date: Tue, 24 Sep 2019 11:11:09 +0800 Subject: [PATCH] 加入购物车 --- pages/goods/goodsInfo/goodsInfo.js | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- pages/goods/goodsInfo/goodsInfo.wxml | 2 +- 2 files changed, 94 insertions(+), 44 deletions(-) diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index 811cd1f..96576a4 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -225,6 +225,7 @@ Page({ region_name:"门店分类",//区域的名字 is_gps:1, open_ind_store:0,//哪里打开的门店列表的控制属性 + default_store:{},//创建添加默认门店地址的对象 }, //------初始化加载---------- @@ -232,7 +233,7 @@ Page({ wx.setNavigationBarTitle({ title: "商品详情",}) var ee = this, that=ee,th=ee, gid = t.goods_id; - + //---获取手机地址坐标-- //--如果tg_id是空的话,分享回来-- if (gid == undefined || gid == null || gid == "") { @@ -242,8 +243,8 @@ Page({ //----获取系统参数----- getApp().getConfig2(function (e) { - ee.setData({bconfig:e}); - + ee.setData({bconfig:e}); + if (e.categoryset.indexOf("," + 1 + ",") != -1) { ee.setData({ is_show_pl: 1 }); } if (e.categoryset.indexOf("," + 3 + ",") != -1) { ee.setData({ is_show_pp: 1 }); } if (e.categoryset.indexOf("," + 2 + ",") != -1) { ee.setData({ is_show_gb: 1 }); } @@ -283,31 +284,7 @@ Page({ }) - if (e.is_sort_storage) { - wx.getLocation({ - type: 'wgs84', - success: function (res) { - th.data.lat = res.latitude; - th.data.lon = res.longitude; - th.data.is_get_local_ok = 1; - }, - fail: function (res) { - if (res.errCode == 2) { - th.setData({ is_gps: 0 }); - if (th.data.is_gps == 0) { - s.showWarning("请开启GPS定位", null, 3800000, !1); - } - - } else { - th.setData({ is_gps: "3" }); - } - - th.data.is_get_local_ok = 1; - } - }) - } else { - th.data.is_get_local_ok = 1; - } + }, @@ -458,6 +435,9 @@ Page({ this.data.is_timer=1; var ee = this,gid = this.data.gid,i=getApp().request; + + this.wait_for_store_config(); + i.get("/api/weshop/goods/get/" + o.stoid + "/" + ee.data.gid, { failRollback: !0, success: function(t) { @@ -578,6 +558,8 @@ Page({ }); this.data.enterAddressPage && (this.data.enterAddressPage = !1); + + }, enterAddress: function() { this.data.enterAddressPage = !0, wx.navigateTo({ @@ -2752,7 +2734,7 @@ Page({ var th=this; var ind=ee.currentTarget.dataset.ind; var bconfig = th.data.bconfig; - console.log("男士水水水水水", bconfig); + if (bconfig.is_sort_storage){ wx.getLocation({ type: 'wgs84', @@ -2769,7 +2751,7 @@ Page({ if (res.errCode == 2) { th.setData({ is_gps: 0 }); if (th.data.is_gps == 0) { - s.showWarning("请开启GPS定位", null, 25000, !1); + getApp().confirmBox("请开启GPS定位", null, 25000, !1); } } else { th.setData({ is_gps: "3" }); @@ -2827,29 +2809,22 @@ close_popup:function(e){ sure_pick:function (e) { var th=this; var item=null; var openindstore = e.currentTarget.dataset.openindstore; - console.log("加入购物车 还是立即购买,商品主页", openindstore); if (openindstore == 1) { - console.log("加入购物车 ", openindstore); + th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else if (openindstore == 2) { - console.log("立即购买 ", openindstore); + th.setData({ openSpecModal: !0, openSpecModal_ind: openindstore, }); } else { - console.log("商品主页", openindstore); + th.setData({ store: 0, choice_sort_store: 0, sort_store: 0 }) } - - - - - - if(th.data.choice_sort_store==0 ){ var index=th.data.fir_pick_index; if(th.data.is_show_sto_cat==1){ @@ -2866,8 +2841,29 @@ close_popup:function(e){ }, //把选择的门店设置成默认的门店def_pick - set_def_pick:function () { - var th=this; var item=null; + set_def_pick:function (e) { + var th = this; var item = null; + var openindstore = e.currentTarget.dataset.openindstore; + if (openindstore == 1) { + + th.setData({ + openSpecModal: !0, + openSpecModal_ind: openindstore, + store: 0, choice_sort_store: 0, sort_store: 0 + }); + } else if (openindstore == 2) { + + th.setData({ + openSpecModal: !0, + openSpecModal_ind: openindstore, + store: 0, choice_sort_store: 0, sort_store: 0 + }); + } else { + th.setData({ + store: 0, choice_sort_store: 0, sort_store: 0 + }) + } + if(th.data.choice_sort_store==0 ){ var index=th.data.fir_pick_index; if(th.data.is_show_sto_cat==1){ @@ -2879,8 +2875,62 @@ close_popup:function(e){ var index=th.data.sec_pick_index; item=th.data.sec_sto.s_arr[index]; } + + var store_id=o.stoid; + var user_id = getApp().globalData.user_id; + var pickup_id = item.pickup_id; + + getApp().request.put('/api/weshop/users/save',{ + data: { store_id, user_id, pickup_id}, + success:function(res){ + if (res.code!=-1){ + s.showWarning("设置门店地址成功", null, 500, !1); + }else{ + s.showWarning("设置默认门店地址失败", null, 500, !1); + } + + } + }); + th.setData({ + def_pick_store: item, sto_sele_name: item.pickup_name, + sto_sele_id: item.pickup_id, sto_sele_distr: item.distr_type, store: 0, choice_sort_store: 0 + }); - } + }, + + wait_for_store_config:function(){ + var th=this; + var t_time=setInterval(function(){ + if (th.data.bconfig==null) false; + var e = th.data.bconfig; + if (e.is_sort_storage) { + wx.getLocation({ + type: 'wgs84', + success: function (res) { + th.data.lat = res.latitude; + th.data.lon = res.longitude; + th.data.is_get_local_ok = 1; + }, + fail: function (res) { + if (res.errCode == 2) { + th.setData({ is_gps: 0 }); + if (th.data.is_gps == 0) { + getApp().confirmBox("请开启GPS定位", null, 10000, !1); + } + } else { + th.setData({ is_gps: "3" }); + } + + th.data.is_get_local_ok = 1; + } + }) + } else { + th.data.is_get_local_ok = 1; + } + clearInterval(t_time); + },500) + } + }); \ No newline at end of file diff --git a/pages/goods/goodsInfo/goodsInfo.wxml b/pages/goods/goodsInfo/goodsInfo.wxml index b11c4dd..15a13fd 100644 --- a/pages/goods/goodsInfo/goodsInfo.wxml +++ b/pages/goods/goodsInfo/goodsInfo.wxml @@ -1154,7 +1154,7 @@ 确定 - 设为默认 + 设为默认 -- libgit2 0.21.4