|
|
@@ -68,6 +68,28 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
+ <!-- Points Deduction Section -->
|
|
|
+ <view class="section" v-if="userTotalPoints > 0">
|
|
|
+ <view class="info-row">
|
|
|
+ <text class="info-label">积分抵扣</text>
|
|
|
+ <text class="points-balance">可用 {{ userTotalPoints }} 积分</text>
|
|
|
+ </view>
|
|
|
+ <view class="points-input-row">
|
|
|
+ <input
|
|
|
+ class="points-input"
|
|
|
+ type="number"
|
|
|
+ :value="pointsUsed"
|
|
|
+ @input="onPointsInput"
|
|
|
+ placeholder="输入使用积分"
|
|
|
+ placeholder-style="color: #ccc; font-size: 26rpx;"
|
|
|
+ />
|
|
|
+ <text class="points-hint">≈ ¥{{ pointsYuanEquivalent }}</text>
|
|
|
+ </view>
|
|
|
+ <view class="points-tip">
|
|
|
+ <text class="points-tip-text">1积分 = ¥0.01,最多使用 {{ maxPoints }} 积分</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
<!-- Remark Section -->
|
|
|
<view class="section">
|
|
|
<view class="info-row">
|
|
|
@@ -151,7 +173,10 @@ export default {
|
|
|
actualAmount: 0,
|
|
|
coupons: [],
|
|
|
selectedCoupon: null,
|
|
|
- showCouponPicker: false
|
|
|
+ showCouponPicker: false,
|
|
|
+ pointsUsed: 0,
|
|
|
+ userTotalPoints: 0,
|
|
|
+ pointsLoading: false
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -159,10 +184,25 @@ export default {
|
|
|
var total = (this.actualAmount || 0) + (this.freight || 0)
|
|
|
if (this.selectedCoupon) {
|
|
|
total = total - this.selectedCoupon.value
|
|
|
- if (total < 0) total = 0
|
|
|
+ }
|
|
|
+ total = total - (this.pointsUsed || 0)
|
|
|
+ if (total < 0) total = 0
|
|
|
+ return total
|
|
|
+ },
|
|
|
+ maxPoints() {
|
|
|
+ var total = (this.actualAmount || 0) + (this.freight || 0)
|
|
|
+ if (this.selectedCoupon) {
|
|
|
+ total = total - this.selectedCoupon.value
|
|
|
+ }
|
|
|
+ if (total < 0) total = 0
|
|
|
+ if (this.userTotalPoints < total) {
|
|
|
+ return this.userTotalPoints
|
|
|
}
|
|
|
return total
|
|
|
},
|
|
|
+ pointsYuanEquivalent() {
|
|
|
+ return (this.pointsUsed / 100).toFixed(2)
|
|
|
+ },
|
|
|
availableCoupons() {
|
|
|
var self = this
|
|
|
return this.coupons.filter(function(c) {
|
|
|
@@ -196,6 +236,7 @@ export default {
|
|
|
}
|
|
|
this.loadDefaultAddress()
|
|
|
this.loadCoupons()
|
|
|
+ this.loadUserPoints()
|
|
|
},
|
|
|
methods: {
|
|
|
calcAmount() {
|
|
|
@@ -231,6 +272,16 @@ export default {
|
|
|
this.selectedCoupon = null
|
|
|
this.showCouponPicker = false
|
|
|
},
|
|
|
+ onPointsInput(e) {
|
|
|
+ var val = parseInt(e.detail.value) || 0
|
|
|
+ if (val < 0) val = 0
|
|
|
+ var maxP = this.maxPoints
|
|
|
+ if (val > maxP) {
|
|
|
+ val = maxP
|
|
|
+ uni.showToast({ title: '最多使用 ' + maxP + ' 积分', icon: 'none' })
|
|
|
+ }
|
|
|
+ this.pointsUsed = val
|
|
|
+ },
|
|
|
getConditionText(minSpend) {
|
|
|
if (!minSpend || minSpend <= 0) return '无门槛'
|
|
|
return '满' + (minSpend / 100).toFixed(2) + '元可用'
|
|
|
@@ -285,6 +336,23 @@ export default {
|
|
|
goAddAddress() {
|
|
|
uni.navigateTo({ url: '/pages/shop/address-edit/address-edit' })
|
|
|
},
|
|
|
+ loadUserPoints() {
|
|
|
+ var that = this
|
|
|
+ uni.request({
|
|
|
+ url: config.api('/api/user/info'),
|
|
|
+ method: 'POST',
|
|
|
+ data: {},
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'Authorization': 'Bearer ' + uni.getStorageSync('token')
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ if (res.data && res.data.code === 200) {
|
|
|
+ that.userTotalPoints = res.data.data.totalPoints || 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
onSubmit() {
|
|
|
if (!this.selectedAddress) {
|
|
|
uni.showToast({ title: '请选择收货地址', icon: 'none' })
|
|
|
@@ -321,7 +389,8 @@ export default {
|
|
|
data: {
|
|
|
items: orderItems,
|
|
|
remark: this.remark,
|
|
|
- addressSnapshot: addressSnapshot
|
|
|
+ addressSnapshot: addressSnapshot,
|
|
|
+ pointsUsed: that.pointsUsed
|
|
|
},
|
|
|
header: {
|
|
|
'Content-Type': 'application/json',
|
|
|
@@ -333,9 +402,11 @@ export default {
|
|
|
var order = res.data.data
|
|
|
uni.showToast({ title: '下单成功', icon: 'success' })
|
|
|
uni.removeStorageSync('checkoutItems')
|
|
|
+ var moneyAmount = order.moneyAmount != null ? order.moneyAmount : order.totalAmount
|
|
|
+ var pointsUsed = order.pointsUsed || 0
|
|
|
setTimeout(function() {
|
|
|
uni.navigateTo({
|
|
|
- url: '/pages/shop/payment/payment?orderNo=' + order.orderNo + '&amount=' + order.totalAmount
|
|
|
+ url: '/pages/shop/payment/payment?orderNo=' + order.orderNo + '&amount=' + (moneyAmount / 100).toFixed(2) + '&pointsUsed=' + pointsUsed
|
|
|
})
|
|
|
}, 1000)
|
|
|
} else {
|
|
|
@@ -743,4 +814,44 @@ export default {
|
|
|
background: #ddd;
|
|
|
color: #999;
|
|
|
}
|
|
|
+.points-balance {
|
|
|
+ font-size: 24rpx;
|
|
|
+ color: #F97316;
|
|
|
+}
|
|
|
+.points-input-row {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ margin-top: 16rpx;
|
|
|
+ padding: 12rpx 0;
|
|
|
+ border-top: 1rpx solid #f5f5f5;
|
|
|
+}
|
|
|
+.points-input {
|
|
|
+ flex: 1;
|
|
|
+ height: 60rpx;
|
|
|
+ font-size: 28rpx;
|
|
|
+ color: #333;
|
|
|
+ background: #f9f9f9;
|
|
|
+ border-radius: 8rpx;
|
|
|
+ padding: 0 16rpx;
|
|
|
+}
|
|
|
+.points-hint {
|
|
|
+ font-size: 24rpx;
|
|
|
+ color: #999;
|
|
|
+ margin-left: 12rpx;
|
|
|
+ min-width: 100rpx;
|
|
|
+ text-align: right;
|
|
|
+}
|
|
|
+.points-tip {
|
|
|
+ margin-top: 8rpx;
|
|
|
+}
|
|
|
+.points-tip-text {
|
|
|
+ font-size: 22rpx;
|
|
|
+ color: #bbb;
|
|
|
+}
|
|
|
+.total-original {
|
|
|
+ font-size: 24rpx;
|
|
|
+ color: #bbb;
|
|
|
+ text-decoration: line-through;
|
|
|
+ margin-left: 8rpx;
|
|
|
+}
|
|
|
</style>
|