Commit 4d84cc0b by 谢中龙

抵用券优惠之后金额为负数

parent 2029db4c
......@@ -23,10 +23,10 @@ wxService.page({
noSelectPrice: '',
plusSpread: '',
goodsAddress: false,
uAddress : {
name : '',
phone : '',
address : '',
uAddress: {
name: '',
phone: '',
address: '',
},
citys: null,
cityView: '',
......@@ -43,8 +43,8 @@ wxService.page({
defalutCouponId: '', // 默认第一项
addressId: '', // 收货地址id
totalGoodsPrice: 0,
buyerRemark: '',//备注信息
currentType: 'delivery',//delivery 快递 selfPickUp 门店自提
buyerRemark: '', //备注信息
currentType: 'delivery', //delivery 快递 selfPickUp 门店自提
storeInfo: {
storeName: '',
storeId: '',
......@@ -52,18 +52,18 @@ wxService.page({
storeCode: ''
},
orderStoreInfo: null,
couponDiscountPreviews : [],
couponDiscountPreviews: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function(options) {
wx.hideShareMenu();
this.getMyLocationInfo();
},
//输入
onInput(e){
onInput(e) {
let key = e.target.dataset.name;
let value = e.detail.value;
this.data.uAddress[key] = value;
......@@ -116,10 +116,12 @@ wxService.page({
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1];
const { trolleySku2Buy } = this.options;
const {
trolleySku2Buy
} = this.options;
let tradeDto = {
trolleySku2Buy: JSON.parse(trolleySku2Buy)
}
......@@ -132,8 +134,7 @@ wxService.page({
// 地址列表
if (this.data.currentType == 'delivery') {
this.getAddressList()
}
else {
} else {
// 获取本地选择的门店信息
this.getLocalStoreInfo();
}
......@@ -171,8 +172,7 @@ wxService.page({
this.data.storeInfo.storeName = storeInfo.name;
this.data.storeInfo.storeAddress = storeInfo.storeFullAddress;
this.data.storeInfo.storeCode = storeInfo.code;
}
else {
} else {
this.data.storeInfo = {
storeName: '',
storeId: '',
......@@ -185,9 +185,17 @@ wxService.page({
storeInfo: this.data.storeInfo
});
const { memberId } = wx.getStorageSync('_baseUserInfo');
const { trolleySku2Buy, checkByPremium } = this.data;
let params = { checkByPremium, trolleySku2Buy };
const {
memberId
} = wx.getStorageSync('_baseUserInfo');
const {
trolleySku2Buy,
checkByPremium
} = this.data;
let params = {
checkByPremium,
trolleySku2Buy
};
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
this.calPreferentialPrice(params)
......@@ -202,8 +210,7 @@ wxService.page({
if (type == 'delivery') {
this.getAddressList()
}
else {
} else {
this.getLocalStoreInfo();
}
},
......@@ -225,7 +232,7 @@ wxService.page({
// faceAmount 抵用多少钱(分) 1 抵用券 2 折扣券 3 定额券
if (!e.detail) {
this.setData({
useNotUserCoupon : true,
useNotUserCoupon: true,
defalutCoupon: 0,
couponId: '',
couponSettingId: '',
......@@ -237,9 +244,19 @@ wxService.page({
});
return
}
const { faceAmount, type, id, couponDiscount, sid } = e.detail
const { defalutCouponId } = this.data
const { orderPrice } = this.data
const {
faceAmount,
type,
id,
couponDiscount,
sid
} = e.detail
const {
defalutCouponId
} = this.data
const {
orderPrice
} = this.data
// couponId---id couponSettingId --sid
let finCouponId = id ? id : sid
let finCouponName = id ? 'couponId' : 'couponSettingId';
......@@ -252,7 +269,7 @@ wxService.page({
// couponId: id,
haveCoupon: true,
currentCoupon: `${parseFloat(faceAmount/10/10).toFixed(2)} 元`
},() => {
}, () => {
this.reCallPreview();
})
} else if (type == 2) {
......@@ -266,11 +283,10 @@ wxService.page({
// couponId: id,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
},() => {
}, () => {
this.reCallPreview();
});
}
else if(type == 3){ //定额券
} else if (type == 3) { //定额券
this.setData({
defalutCoupon: true,
......@@ -279,7 +295,7 @@ wxService.page({
[finCouponName]: finCouponId,
haveCoupon: true,
currentCoupon: `${couponDiscount} 元`
},() => {
}, () => {
this.reCallPreview();
})
}
......@@ -288,17 +304,24 @@ wxService.page({
this.setPayPrice();
},
setPayPrice() {
const { currentCoupon, orderInitPrice, isSelect, plusMemberPrice, defalutCoupon } = this.data
const {
currentCoupon,
orderInitPrice,
isSelect,
plusMemberPrice,
defalutCoupon
} = this.data
let newCurrentCoupon = currentCoupon ? currentCoupon : 0
let orderCoupon = parseFloat(newCurrentCoupon) // 优惠券价格
let plusPrice = isSelect ? plusMemberPrice : 0 // plus
let calCouponPrice = orderCoupon ? orderCoupon : defalutCoupon
//获取计算优惠后的价格
let promotionPrice = (orderInitPrice - calCouponPrice) > 0 ? (orderInitPrice - calCouponPrice) : 0;
// 实际价格 - 优惠价 + plus
this.setData({
// orderPrice: Math.round(orderInitPrice - orderCoupon)
// orderPrice: orderInitPrice - orderCoupon + plusPrice
orderPrice: orderInitPrice - calCouponPrice + plusPrice
orderPrice: promotionPrice + plusPrice
})
},
//提交按钮
......@@ -322,12 +345,11 @@ wxService.page({
showCancel: true,
confirmText: '确定',
confirmColor: '#cb3c3c',
success: function (res) {
success: function(res) {
if (res.confirm) {
//跳去开卡
wxService.openCard();
}
else if (res.cancel) {
} else if (res.cancel) {
}
}
......@@ -338,7 +360,9 @@ wxService.page({
}
//判断是不是快递配送
if (this.data.currentType == 'delivery') {
const { goodsAddress } = this.data
const {
goodsAddress
} = this.data
// 保存地址 && 支付
if (goodsAddress) {
if (!this.data.uAddress.name) {
......@@ -370,7 +394,9 @@ wxService.page({
return false;
}
const { memberId } = wx.getStorageSync('_baseUserInfo')
const {
memberId
} = wx.getStorageSync('_baseUserInfo')
this.setData({
params: {
userId: memberId,
......@@ -389,7 +415,9 @@ wxService.page({
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result } = res.data
const {
result
} = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
......@@ -411,8 +439,7 @@ wxService.page({
// 调起支付
this.handelGobuy()
}
}
else {
} else {
this.handelGobuy()
}
},
......@@ -422,8 +449,7 @@ wxService.page({
if (envInfo.brandId == 2010) {
//由于地址框太大了,现在先用热风的一个
cityData = city.default;
}
else {
} else {
cityData = city.default;
}
......@@ -511,7 +537,9 @@ wxService.page({
this.setData({
isSelect: !this.data.isSelect
}, () => {
const { isSelect } = this.data
const {
isSelect
} = this.data
this.setData({
checkByPremium: isSelect,
defalutCoupon: 0,
......@@ -532,7 +560,10 @@ wxService.page({
})
wxService.get(`/sale/premium/getDefault`).then(res => {
if (res) {
const { result, data } = res.data
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
......@@ -552,7 +583,12 @@ wxService.page({
},
//拼接字段重新调用preview
reCallPreview() {
const { trolleySku2Buy, checkByPremium, addressId, addressInfo } = this.data
const {
trolleySku2Buy,
checkByPremium,
addressId,
addressInfo
} = this.data
let params = {
checkByPremium,
......@@ -563,8 +599,7 @@ wxService.page({
if (this.data.currentType == 'delivery') {
params.addressId = addressId ? addressId : addressInfo.id // 微信地址 or 地址id
params.orderType = 1;
}
else {
} else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
}
......@@ -580,13 +615,16 @@ wxService.page({
});
//如果有couponId需要在预览接口传过去
if (this.data.couponId){
if (this.data.couponId) {
params.couponId = this.data.couponId;
}
wxService.post(`/sale/trade/buyer/preview`, params).then(res => {
if (res) {
const { result, data } = res.data
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading()
let skuList = data.tradePreviewSkus;
......@@ -598,7 +636,9 @@ wxService.page({
this.data.totalGoodsPrice = sum;
// 初始化商品价格
const { isSelect } = this.data
const {
isSelect
} = this.data
if (isSelect) {
this.setData({
......@@ -611,7 +651,7 @@ wxService.page({
}
//如果没有couponId则认为是第一次进来没有自己选择优惠券
if (!this.data.couponId) {
if(!this.data.useNotUserCoupon){
if (!this.data.useNotUserCoupon) {
//获取优惠券信息
let defalutCoupon = data && data.couponDiscountPreviews.length &&
data.couponDiscountPreviews[0].couponSettingDTO.type == 1 ?
......@@ -642,7 +682,7 @@ wxService.page({
})
}
//用户取消使用优惠券
else{
else {
this.setData({
currentOrderList: data,
orderInitPrice: data.amount,
......@@ -652,8 +692,7 @@ wxService.page({
this.setPayPrice()
})
}
}
else{
} else {
//重新调用之后 不刷新优惠券列表
this.setData({
currentOrderList: data,
......@@ -723,8 +762,7 @@ wxService.page({
})
return;
}
}
else {
} else {
params.orderType = 4;
params.storeId = this.data.storeInfo.storeId;
params.storeCode = this.data.storeInfo.storeCode;
......@@ -747,7 +785,9 @@ wxService.page({
title: '正在下单..'
});
const { isSelect } = this.data;
const {
isSelect
} = this.data;
//增加订单备注信息
params.buyerRemark = this.data.buyerRemark;
//下单之前先做校验
......@@ -756,8 +796,7 @@ wxService.page({
let data = result.data.data ? result.data.data : [];
if (data.length == 0) {
this.order(isSelect, params);
}
else {
} else {
//有商品限购了,组织提示语
let tips = '根据限购规则以下商品限购:\r\n';
let tempObj = data[0];
......@@ -803,14 +842,17 @@ wxService.page({
let url = isSelect ? '/sale/payment/merged/buyer/bill' : '/sale/trade/buyer/bill'
wxService.post(`${url}`, params).then(res => {
if (res) {
const { result, data } = res.data
const {
result,
data
} = res.data
let tradeId = data.tradeId;
wx.removeStorageSync('choosedStoreInfo');
wx.removeStorageSync('orderRemark');
if (result == 0) {
delete data.appId
let amount = data.amount || 0;
if(amount > 0){
if (amount > 0) {
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
......@@ -823,11 +865,11 @@ wxService.page({
}).then(res => {
let tempArr = res.data.data ? res.data.data : [];
let currentType = _this.data.currentType;
if (tempArr.length == 0){
if (tempArr.length == 0) {
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
return ;
return;
}
let tempids = [];
......@@ -837,17 +879,17 @@ wxService.page({
wx.requestSubscribeMessage({
tmplIds: tempids,
success: (res)=>{
for(let i = 0; i < tempArr.length; i++){
success: (res) => {
for (let i = 0; i < tempArr.length; i++) {
wxService.post(`${'/merchant/message/wxSubMsgSubscride/member/subscribe'}`, {
businessId: tradeId,
memberId: baseUserInfo.memberId,
scenarioId:tempArr[i].scenarioId,
scenarioId: tempArr[i].scenarioId,
templateId: tempArr[i].templateId
}).then(resp => {});
}
},
complete: (res)=>{
complete: (res) => {
wx.redirectTo({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
......@@ -870,22 +912,19 @@ wxService.page({
wx.redirectTo({
url: '/pages/order/order',
});
}
else {
} else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
}
}, data.wxParams));
}
else{
} else {
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
url: '/pages/order/order',
});
}
else {
} else {
wx.redirectTo({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
......@@ -901,9 +940,17 @@ wxService.page({
},
// 获取地址列表
getAddressList() {
const { memberId } = wx.getStorageSync('_baseUserInfo');
const { trolleySku2Buy, checkByPremium } = this.data;
let params = { checkByPremium, trolleySku2Buy };
const {
memberId
} = wx.getStorageSync('_baseUserInfo');
const {
trolleySku2Buy,
checkByPremium
} = this.data;
let params = {
checkByPremium,
trolleySku2Buy
};
params.orderType = 1;
wxService.post(`/member/addressManage/getall`, {
......@@ -911,7 +958,10 @@ wxService.page({
}).then(res => {
if (!res) return false;
let hasDefalut = wx.getStorageSync('_defalutAddress');
let { result, data } = res.data
let {
result,
data
} = res.data
if (result == 0) {
//看看本地是不是有已经选择的地址了
if (!hasDefalut) { // 无
......@@ -936,16 +986,14 @@ wxService.page({
addressId: this.data.addressId,
goodsAddress: params.addressId ? false : true,
});
}
else { // 有已经选择的地址了
} else { // 有已经选择的地址了
let defaultInAddressList = null;
//判断地址列表中是不是已经把这个地址删除了
let id = hasDefalut.id;
let filterArr = data.filter(item => item.id == id);
if (filterArr.length > 0) {
defaultInAddressList = hasDefalut
}
else { // 无
} else { // 无
//此时已经没有 看看是不是有默认地址 有则默认选中
data = data ? data : [];
data.forEach(item => {
......@@ -975,11 +1023,13 @@ wxService.page({
this.calPreferentialPrice(params)
}
}).finally(() => { });
}).finally(() => {});
},
//获取微信地址
chooseWxAddress() {
const { memberId } = wx.getStorageSync('_baseUserInfo')
const {
memberId
} = wx.getStorageSync('_baseUserInfo')
wx.chooseAddress({
success: (res) => {
res.name = res.userName
......@@ -1006,7 +1056,10 @@ wxService.page({
});
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result, data } = res.data
const {
result,
data
} = res.data
if (result == 0) {
wx.hideLoading();
this.data.addressInfo.fullArea = this.data.addressInfo.provinceName + ' ' +
......@@ -1025,7 +1078,7 @@ wxService.page({
wx.hideLoading()
})
},
fail: function (err) {
fail: function(err) {
console.log(err)
}
})
......@@ -1038,29 +1091,27 @@ wxService.page({
})
},
//校验地址库 原因是地址库发生过改变 老用户之前维护过地址 但是地址可能对不上影响邮费 若发现地址不对这里强制提示用户去更新
validateAddress(){
if (this.data.addressId){
validateAddress() {
if (this.data.addressId) {
let province = this.data.addressInfo.province,
cityName = this.data.addressInfo.city,
district = this.data.addressInfo.district;
let defaultCities = city.default;
//先处理省份
let filterProvince = defaultCities.filter(item => item.value == province);
if(filterProvince.length == 0){
if (filterProvince.length == 0) {
//省份地址维护不对 提示用户去改
this.showEditAddressModal(this.data.addressId);
}
else{
} else {
//檢查市
let filterCity = filterProvince[0].children.filter(item => item.value == cityName);
if (filterCity.length == 0){
if (filterCity.length == 0) {
//市维护的地址不对 提示用户去修改
this.showEditAddressModal(this.data.addressId);
}
else{
} else {
//检查区是否正确
let filterDistinct = filterCity[0].children.filter(item => item.value == district);
if (filterDistinct.length == 0){
if (filterDistinct.length == 0) {
//区维护的地址不对 提示用户去修改
this.showEditAddressModal(this.data.addressId);
}
......@@ -1069,7 +1120,7 @@ wxService.page({
}
},
//展示地址修改弹框
showEditAddressModal(addressId){
showEditAddressModal(addressId) {
wx.showModal({
title: '地址更改提示',
content: `您好,因地址库的修改,您当前的收货地址需要重新编辑才可下单,请先编辑此地址。感谢您的配合~`,
......
......@@ -4,10 +4,8 @@
<view class="page-confirm-order">
<!-- 选择方式 -->
<view class="deliveryType" wx:if="{{isOpenSelfMention}}">
<view class="de-type-item {{currentType == 'delivery' ? 'active' : ''}}"
data-type="delivery" bindtap="onTapChangeType">快递配送</view>
<view class="de-type-item {{currentType == 'selfPickUp' ? 'active' : ''}}"
data-type="selfPickUp" bindtap="onTapChangeType">门店自提</view>
<view class="de-type-item {{currentType == 'delivery' ? 'active' : ''}}" data-type="delivery" bindtap="onTapChangeType">快递配送</view>
<view class="de-type-item {{currentType == 'selfPickUp' ? 'active' : ''}}" data-type="selfPickUp" bindtap="onTapChangeType">门店自提</view>
</view>
<form>
......@@ -15,55 +13,29 @@
<view class="address-wrap" wx:if="{{currentType == 'delivery'}}">
<block wx:if="{{goodsAddress}}">
<view class="address-section">
<input class="address-input" name="name"
data-name="name" value='{{uAddress.name}}'
bindinput='onInput'
placeholder="请输入收货人姓名" />
<input class="address-input" name="phone"
data-name="phone"
bindinput='onInput'
value='{{uAddress.phone}}'
placeholder="请输入手机号码" />
<input class="address-input" name="name" data-name="name" value='{{uAddress.name}}' bindinput='onInput' placeholder="请输入收货人姓名" />
<input class="address-input" name="phone" data-name="phone" bindinput='onInput' value='{{uAddress.phone}}' placeholder="请输入手机号码" />
</view>
<view class="address-section">
<picker
class="address-input address-picker"
mode="multiSelector"
bindchange="bindMultiPickerChange"
bindcolumnchange="bindMultiPickerColumnChange"
value="{{multiIndex}}"
range="{{citys}}"
>
<picker class="address-input address-picker" mode="multiSelector" bindchange="bindMultiPickerChange" bindcolumnchange="bindMultiPickerColumnChange" value="{{multiIndex}}" range="{{citys}}">
<view class="form-picker" style="padding-top: 8rpx;" wx:if="{{cityView}}">
{{cityView}}
</view>
<view wx:if="{{!cityView}}">
<input
class='form-input'
placeholder-class="placeholder-picker"
style="padding-top: 8rpx;"
type="text"
disabled
placeholder="所在区域"
/>
<input class='form-input' placeholder-class="placeholder-picker" style="padding-top: 8rpx;" type="text" disabled placeholder="所在区域" />
</view>
</picker>
</view>
<view class="address-section">
<input class="address-input address-detail"
name="address"
bindinput='onInput'
data-name="address"
value='{{uAddress.address}}'
placeholder="请输入路名门牌号" />
<input class="address-input address-detail" name="address" bindinput='onInput' data-name="address" value='{{uAddress.address}}' placeholder="请输入路名门牌号" />
</view>
</block>
<block wx:if="{{!goodsAddress}}">
<view class="address-list" bindtap="selectAddress">
<view class="address-info">
<view>
<image class="defalut-add-img"
src="{{addressInfo.type == 1 ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001f7a6186d-6882-422c-a77c-61b8291c091a.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/300129705d0a-bf5c-4b2f-aedd-0c3fc9f78ba1.png'}}" />
<image class="defalut-add-img" src="{{addressInfo.type == 1 ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001f7a6186d-6882-422c-a77c-61b8291c091a.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/300129705d0a-bf5c-4b2f-aedd-0c3fc9f78ba1.png'}}"
/>
<text class="user-name">{{addressInfo.name}}</text>
<text class="phone-number">{{addressInfo.phone}}</text>
</view>
......@@ -133,8 +105,7 @@
<view class="vip-info" wx:if="{{!isVip && plusIsOpen}}">
<view class="vip-left">
<view class="left-top">
<image class="top-image"
src="https://img3.bigaka.com/prd/3001/202003/20200309/3001a3933408-de10-4029-861f-f8fb5de26092.png" />
<image class="top-image" src="https://img3.bigaka.com/prd/3001/202003/20200309/3001a3933408-de10-4029-861f-f8fb5de26092.png" />
<text>现在勾选成为vip,享受更多优惠</text>
</view>
<view class="left-bottom">
......@@ -147,7 +118,8 @@
<image class="check-status-img" src="{{isSelect ? '/assets/imgs/7_1_0/08_22/trade-success.png' : '/assets/imgs/7_1_0/08_22/trade-unsel.png'}}" />
</view>
<view class="right-check-tips {{isSelect? 'tip-check' : 'tip-un-check'}}">
<image class="select-check-open {{isSelect? 'tip-check' : 'tip-un-check'}}" src="{{isSelect ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001ab6df057-e550-446c-a641-c5dcd8dbb51e.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/3001e6e3414a-3f8e-4100-b9da-7f852d842235.png'}}" />
<image class="select-check-open {{isSelect? 'tip-check' : 'tip-un-check'}}" src="{{isSelect ? 'https://img3.bigaka.com/prd/3001/202003/20200309/3001ab6df057-e550-446c-a641-c5dcd8dbb51e.png' : 'https://img3.bigaka.com/prd/3001/202003/20200309/3001e6e3414a-3f8e-4100-b9da-7f852d842235.png'}}"
/>
</view>
</view>
</view>
......@@ -175,7 +147,7 @@
<!-- class='coupon-items' -->
<view bindtap="selectCoupon">
<text class="price-label">优惠券</text>
<view class="select-coupon" >
<view class="select-coupon">
<text class="{{defalutCoupon ? 'coupon-price' : 'no-coupon'}}">{{defalutCoupon ? (currentCoupon ? '-' + currentCoupon : '-' + defalutCoupon): (currentOrderList.couponDiscountPreviews.length == 0 ? '无可使用优惠券' : '选择优惠券')}}</text>
<image class="arrow-right" src="/assets/imgs/7_1_0/arrow-right.png" />
</view>
......@@ -262,9 +234,5 @@
</view>
<!--goHome-->
<go-home/>
<floatNav bind:getAuth="_getUserInfo" bind:updatePage="updatePage"/>
<select-coupon
show="{{showSelectCoupon}}"
bind:updateCoupon="updateCoupon"
coupon-list="{{couponDiscountPreviews}}"/>
<floatNav bind:getAuth="_getUserInfo" bind:updatePage="updatePage" />
<select-coupon show="{{showSelectCoupon}}" bind:updateCoupon="updateCoupon" coupon-list="{{couponDiscountPreviews}}" />
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment