Skip to content

Commit

Permalink
add user coupons
Browse files Browse the repository at this point in the history
  • Loading branch information
gooking committed Aug 16, 2017
1 parent 6db0c0f commit 177ff10
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 34 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# 微信小程序商城
微信小程序商城,微信小程序微店,长期维护版本;

# 接口和后台
本商城采用的是 云接口和后台 ,注册账号,直接配置即可完成接口和后台的对接

[https://www.it120.cc/info/wxapp/314](https://www.it120.cc/info/wxapp/314)
微信小程序商城,微信小程序微店,长期维护版本,欢迎大家踊跃提交贡献代码;

## 参与开发

Expand Down
73 changes: 71 additions & 2 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ Page({
activeCategoryId: 0,
goods:[],
scrollTop:"0",
loadingMoreHidden:true
loadingMoreHidden:true,

hasNoCoupons:true,
coupons: []
},

tabClick: function (e) {
Expand Down Expand Up @@ -97,7 +100,7 @@ Page({
that.getGoodsList(0);
}
})

that.getCoupons ();
},
getGoodsList: function (categoryId) {
if (categoryId == 0) {
Expand Down Expand Up @@ -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
})
}
}
})
}
})
13 changes: 11 additions & 2 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@
</block>
</view>
</view>

<view class="type-container">
<scroll-view class="type-navbar" scroll-x="true" style="width: 100%">
<scroll-view class="type-navbar" scroll-x="true">
<view class="type-box" wx:for-items="{{categories}}">
<view id="{{item.id}}" class="type-navbar-item {{activeCategoryId == item.id ? 'type-item-on' : ''}}" bindtap="tabClick">
{{item.name}}
</view>
</view>
</scroll-view>
</view>
<view class="coupons" hidden="{{hasNoCoupons}}">
<scroll-view class="coupons-scroll" scroll-x="true">
<view class="coupons-item" wx:for-items="{{coupons}}" wx:for-index="idx" bindtap="gitCoupon" data-id="{{item.id}}">
<view style="font-size: 30rpx"> ¥ {{item.moneyMax}}元 </view>
<view> 本店满 {{item.moneyHreshold}} 元使用 </view>
<view wx:if="{{item.dateEndType == 0}}"> {{item.dateEnd}} 前有效 </view>
<view wx:if="{{item.dateEndType == 1}}"> 领取 {{item.dateEndDays}} 天内有效 </view>
</view>
</scroll-view>
</view>
<view class="goods-container">
<view class="goods-box" wx:for-items="{{goods}}" wx:key="{{index}}" bindtap="toDetailsTap" data-id="{{item.id}}">
<view class="img-box">
Expand Down
28 changes: 28 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ swiper-item image {
white-space: nowrap;
display: flex;
height: 88rpx;
width: 100%;
background-color: #fff;
}
::-webkit-scrollbar {
Expand Down Expand Up @@ -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;
}
83 changes: 63 additions & 20 deletions pages/to-pay-order/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ Page({
yunPrice:0,
allGoodsAndYunPrice:0,
goodsJsonStr:"",
orderType:"" //订单类型,购物车下单或立即支付下单,默认是购物车,
orderType:"", //订单类型,购物车下单或立即支付下单,默认是购物车,

hasNoCoupons: true,
coupons: [],
youhuijine:0, //优惠券金额
curCoupon:null // 当前选择使用的优惠券
},
onShow : function () {
var that = this;
Expand All @@ -31,7 +36,7 @@ Page({
that.setData({
goodsList: shopList,
});
that.initShippingAddress();
that.initShippingAddress();
},

onLoad: function (e) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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();
}
})
},
Expand All @@ -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) {
Expand All @@ -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({
Expand Down Expand Up @@ -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) {
Expand All @@ -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({
Expand All @@ -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]
});
}
})
21 changes: 17 additions & 4 deletions pages/to-pay-order/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
</view>
</view>
</view>
<view class="peisong-way" hidden="{{hasNoCoupons}}">
<view class="row-box" style="border-bottom:none;">
<view class="row-label">选择使用优惠券</view>
</view>
<view class="row-box" style="border-bottom:none;">
<picker-view indicator-style="height: 50rpx;" style="width: 100%; height: 150rpx;" value="0" bindchange="bindChangeCoupon">
<picker-view-column>
<view style="line-height: 50px">不使用优惠券</view>
<view wx:for="{{coupons}}" style="line-height: 50px">{{item.money}}元 {{item.name}}</view>
</picker-view-column>
</picker-view>
</view>
</view>
<view class="goods-info">
<view class="row-box" wx:if="{{isNeedLogistics > 0 && yunPrice > 0}}">
<view class="row-label">商品金额</view>
Expand All @@ -49,14 +62,14 @@
<view class="row-label">运费</view>
<view class="right-text">+ ¥ {{yunPrice}}</view>
</view>
<view class="row-box">
<view class="row-label">应付总额</view>
<view class="right-text">¥ {{allGoodsAndYunPrice}}</view>
<view class="row-box" wx:if="{{!hasNoCoupons}}">
<view class="row-label">优惠券</view>
<view class="right-text">- ¥ {{youhuijine}}</view>
</view>
</view>
<view class="jiesuan-box">
<view class="left-price">
<view class="total">合计:¥ {{allGoodsAndYunPrice}}</view>
<view class="total">合计:¥ {{allGoodsAndYunPrice - youhuijine}}</view>
</view>
<button class="to-pay-btn" formType="submit">提交订单</button>
</view>
Expand Down

0 comments on commit 177ff10

Please sign in to comment.