diff --git a/README.md b/README.md
index 240a316c..908e8182 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,5 @@
# 微信小程序商城
-微信小程序商城,微信小程序微店,长期维护版本;
-
-# 接口和后台
-本商城采用的是 云接口和后台 ,注册账号,直接配置即可完成接口和后台的对接
-
-[https://www.it120.cc/info/wxapp/314](https://www.it120.cc/info/wxapp/314)。
+微信小程序商城,微信小程序微店,长期维护版本,欢迎大家踊跃提交贡献代码;
## 参与开发
diff --git a/pages/index/index.js b/pages/index/index.js
index 78ad52ed..c8da0eac 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -15,7 +15,10 @@ Page({
activeCategoryId: 0,
goods:[],
scrollTop:"0",
- loadingMoreHidden:true
+ loadingMoreHidden:true,
+
+ hasNoCoupons:true,
+ coupons: []
},
tabClick: function (e) {
@@ -97,7 +100,7 @@ Page({
that.getGoodsList(0);
}
})
-
+ that.getCoupons ();
},
getGoodsList: function (categoryId) {
if (categoryId == 0) {
@@ -130,5 +133,71 @@ Page({
});
}
})
+ },
+ getCoupons: function () {
+ var that = this;
+ wx.request({
+ url: 'https://api.it120.cc/' + app.globalData.subDomain + '/discounts/coupons',
+ data: {
+ type: ''
+ },
+ success: function (res) {
+ if (res.data.code == 0) {
+ that.setData({
+ hasNoCoupons: false,
+ coupons: res.data.data
+ });
+ }
+ }
+ })
+ },
+ gitCoupon : function (e) {
+ var that = this;
+ wx.request({
+ url: 'https://api.it120.cc/' + app.globalData.subDomain + '/discounts/fetch',
+ data: {
+ id: e.currentTarget.dataset.id,
+ token: app.globalData.token
+ },
+ success: function (res) {
+ if (res.data.code == 20001 || res.data.code == 20002) {
+ wx.showModal({
+ title: '错误',
+ content: '来晚了',
+ showCancel: false
+ })
+ return;
+ }
+ if (res.data.code == 20003) {
+ wx.showModal({
+ title: '错误',
+ content: '你领过了,别贪心哦~',
+ showCancel: false
+ })
+ return;
+ }
+ if (res.data.code == 20004) {
+ wx.showModal({
+ title: '错误',
+ content: '已过期~',
+ showCancel: false
+ })
+ return;
+ }
+ if (res.data.code == 0) {
+ wx.showToast({
+ title: '领取成功,赶紧去下单吧~',
+ icon: 'success',
+ duration: 2000
+ })
+ } else {
+ wx.showModal({
+ title: '错误',
+ content: res.data.msg,
+ showCancel: false
+ })
+ }
+ }
+ })
}
})
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index a6ba6d61..d0173815 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -16,9 +16,8 @@
-
-
+
{{item.name}}
@@ -26,6 +25,16 @@
+
+
+
+ ¥ {{item.moneyMax}}元
+ 本店满 {{item.moneyHreshold}} 元使用
+ {{item.dateEnd}} 前有效
+ 领取 {{item.dateEndDays}} 天内有效
+
+
+
diff --git a/pages/index/index.wxss b/pages/index/index.wxss
index 0cb5150a..8406ec7f 100644
--- a/pages/index/index.wxss
+++ b/pages/index/index.wxss
@@ -45,6 +45,7 @@ swiper-item image {
white-space: nowrap;
display: flex;
height: 88rpx;
+ width: 100%;
background-color: #fff;
}
::-webkit-scrollbar {
@@ -125,4 +126,31 @@ swiper-item image {
position: fixed;
top: 0;
left: 0;
+}
+.coupons{
+ margin-top:10rpx;
+ width: 100%;
+ height: 140rpx;
+ overflow: hidden;
+}
+.coupons-scroll{
+ display: flex;
+ white-space: nowrap;
+ height: 140rpx;
+ width: 100%;
+ background-color: #fff;
+}
+.coupons-item{
+ width:240rpx;
+ height: 120rpx;
+ margin: 10rpx;
+ padding-top: 20rpx;
+ padding-left: 15rpx;
+ background-color: #f1a83b;
+ box-sizing: content-box;
+ font-size: 20rpx;
+ line-height: 35rpx;
+ overflow: hidden;
+ color: #fff;
+ display: inline-block;
}
\ No newline at end of file
diff --git a/pages/to-pay-order/index.js b/pages/to-pay-order/index.js
index eef1fd5e..ebb78ed2 100644
--- a/pages/to-pay-order/index.js
+++ b/pages/to-pay-order/index.js
@@ -10,7 +10,12 @@ Page({
yunPrice:0,
allGoodsAndYunPrice:0,
goodsJsonStr:"",
- orderType:"" //订单类型,购物车下单或立即支付下单,默认是购物车,
+ orderType:"", //订单类型,购物车下单或立即支付下单,默认是购物车,
+
+ hasNoCoupons: true,
+ coupons: [],
+ youhuijine:0, //优惠券金额
+ curCoupon:null // 当前选择使用的优惠券
},
onShow : function () {
var that = this;
@@ -31,7 +36,7 @@ Page({
that.setData({
goodsList: shopList,
});
- that.initShippingAddress();
+ that.initShippingAddress();
},
onLoad: function (e) {
@@ -84,6 +89,9 @@ Page({
postData.mobile = that.data.curAddressData.mobile;
postData.code = that.data.curAddressData.code;
}
+ if (that.data.curCoupon) {
+ postData.couponId = that.data.curCoupon.id;
+ }
wx.request({
@@ -125,17 +133,16 @@ Page({
token:app.globalData.token
},
success: (res) =>{
- console.log(res.data)
if (res.data.code == 0) {
that.setData({
curAddressData:res.data.data
});
- that.processYunfei();
}else{
that.setData({
curAddressData: null
});
}
+ that.processYunfei();
}
})
},
@@ -151,7 +158,7 @@ Page({
if (carShopBean.logistics) {
isNeedLogistics = 1;
}
- allGoodsPrice += carShopBean.price * carShopBean.number
+ allGoodsPrice += carShopBean.price * carShopBean.number;
var goodsJsonStrTmp = '';
if (i > 0) {
@@ -160,13 +167,7 @@ Page({
goodsJsonStrTmp += '{"goodsId":' + carShopBean.goodsId + ',"number":' + carShopBean.number + ',"propertyChildIds":"' + carShopBean.propertyChildIds + '","logisticsType":0}';
goodsJsonStr += goodsJsonStrTmp;
- if (carShopBean.logistics) {
- if (carShopBean.logistics.isFree){
- //包邮情况
- that.setData({
- allGoodsAndYunPrice: parseFloat(allGoodsPrice.toFixed(2))
- });
- }else{
+ if (carShopBean.logistics && !carShopBean.logistics.isFree) {
// 计算应付运费金额
let districtId = that.getDistrictId(that.data.curAddressData, that.data.curAddressData.districtId);
wx.request({
@@ -204,10 +205,9 @@ Page({
numberLeft = numberLeft - addNumber;
amountLogistics = amountLogistics + addAmount;
}
- let yunPrice = that.data.yunPrice + amountLogistics;
+ that.data.yunPrice = that.data.yunPrice + amountLogistics;
that.setData({
- yunPrice: parseFloat(yunPrice.toFixed(2)),
- allGoodsAndYunPrice: parseFloat((allGoodsPrice + yunPrice).toFixed(2)),
+ yunPrice: parseFloat((that.data.yunPrice).toFixed(2))
});
}
if (carShopBean.logistics.feeType == 1) {
@@ -219,25 +219,30 @@ Page({
leftWeight = leftWeight - addNumber;
amountLogistics = amountLogistics + addAmount;
}
- let yunPrice = that.data.yunPrice + amountLogistics;
+ that.data.yunPrice = that.data.yunPrice + amountLogistics;
that.setData({
- yunPrice: parseFloat(yunPrice.toFixed(2)),
- allGoodsAndYunPrice: parseFloat((allGoodsPrice + yunPrice).toFixed(2)),
+ yunPrice: parseFloat((that.data.yunPrice).toFixed(2))
});
}
}
})
- // 计算运费结束
- }
+ // 计算运费结束
}
}
goodsJsonStr += "]";
+ console.log("isNeedLogistics:" + isNeedLogistics);
+ console.log("allGoodsPrice:" + parseFloat(allGoodsPrice.toFixed(2)));
+ console.log("goodsJsonStr:" + goodsJsonStr);
+ console.log("yunPrice:" + that.data.yunPrice);
that.setData({
isNeedLogistics: isNeedLogistics,
allGoodsPrice: parseFloat(allGoodsPrice.toFixed(2)),
+ allGoodsAndYunPrice: parseFloat((allGoodsPrice + that.data.yunPrice).toFixed(2)),
+ yunPrice: that.data.yunPrice,
goodsJsonStr: goodsJsonStr
});
+ that.getMyCoupons();
},
addAddress: function () {
wx.navigateTo({
@@ -248,5 +253,43 @@ Page({
wx.navigateTo({
url:"/pages/select-address/index"
})
+ },
+ getMyCoupons: function () {
+ var that = this;
+ wx.request({
+ url: 'https://api.it120.cc/' + app.globalData.subDomain + '/discounts/my',
+ data: {
+ token: app.globalData.token,
+ status:0
+ },
+ success: function (res) {
+ if (res.data.code == 0) {
+ var coupons = res.data.data.filter(entity => {
+ return entity.moneyHreshold <= that.data.allGoodsAndYunPrice;
+ });
+ if (coupons.length > 0) {
+ that.setData({
+ hasNoCoupons: false,
+ coupons: coupons
+ });
+ }
+ }
+ }
+ })
+ },
+ bindChangeCoupon: function (e) {
+ const selIndex = e.detail.value[0] - 1;
+ if (selIndex == -1) {
+ this.setData({
+ youhuijine: 0,
+ curCoupon:null
+ });
+ return;
+ }
+ console.log("selIndex:" + selIndex);
+ this.setData({
+ youhuijine: this.data.coupons[selIndex].money,
+ curCoupon: this.data.coupons[selIndex]
+ });
}
})
diff --git a/pages/to-pay-order/index.wxml b/pages/to-pay-order/index.wxml
index 0ded4c6b..dbd9341b 100644
--- a/pages/to-pay-order/index.wxml
+++ b/pages/to-pay-order/index.wxml
@@ -40,6 +40,19 @@
+
+
+ 选择使用优惠券
+
+
+
+
+ 不使用优惠券
+ {{item.money}}元 {{item.name}}
+
+
+
+
商品金额
@@ -49,14 +62,14 @@
运费
+ ¥ {{yunPrice}}
-
- 应付总额
- ¥ {{allGoodsAndYunPrice}}
+
+ 优惠券
+ - ¥ {{youhuijine}}
- 合计:¥ {{allGoodsAndYunPrice}}
+ 合计:¥ {{allGoodsAndYunPrice - youhuijine}}