|
@@ -48,9 +48,9 @@
|
|
|
<view class="choose-item">
|
|
|
<view class="item" @click="intoChooseCoupon">
|
|
|
<text>优惠卷</text>
|
|
|
- <view v-if="checkedCoupon" class="right">
|
|
|
+ <view v-if="couponList.length" class="right">
|
|
|
<u-icon name="gift" color="rgb(255,0,0)" size="32"></u-icon>
|
|
|
- <text class="coopon">9.8元洗车券(¥-9.8)</text>
|
|
|
+ <text class="coopon">{{checkedCoupon?(checkedCoupon.couponTitle+'(¥-'+checkedCoupon.couponAmount+')'):''}}</text>
|
|
|
<u-icon name="arrow-right" color="rgb(255,0,0)" size="32"></u-icon>
|
|
|
</view>
|
|
|
<view v-else class="right">
|
|
@@ -200,6 +200,8 @@
|
|
|
dataInit(){
|
|
|
// 监听点击已阅读事件
|
|
|
uni.$once('read', this.read)
|
|
|
+ // 监听用户选择的优惠券
|
|
|
+ uni.$on('couponChoose', this.couponChoose)
|
|
|
// 获取用户信息
|
|
|
this.getUserPhone()
|
|
|
// 获取服务项目
|
|
@@ -262,7 +264,8 @@
|
|
|
if (res.status == 200) {
|
|
|
this.itemList = res.data
|
|
|
this.serverIndex = 0
|
|
|
- this.getFinalAmount()
|
|
|
+ // 获取用户可用优惠券
|
|
|
+ this.getCouponList()
|
|
|
} else {
|
|
|
this.itemList = []
|
|
|
}
|
|
@@ -271,7 +274,8 @@
|
|
|
// 选择服务项目
|
|
|
chooseItem(index) {
|
|
|
this.serverIndex = index
|
|
|
- this.getFinalAmount()
|
|
|
+ // 获取用户可用优惠券
|
|
|
+ this.getCouponList()
|
|
|
},
|
|
|
// 下一步
|
|
|
nextStep() {
|
|
@@ -282,66 +286,51 @@
|
|
|
read(e) {
|
|
|
this.isRead = e.msg
|
|
|
},
|
|
|
+ // 获取用户选择的优惠券
|
|
|
+ couponChoose (e) {
|
|
|
+ this.checkedCoupon = e.curCoupon
|
|
|
+ // 计算合计
|
|
|
+ this.getFinalAmount()
|
|
|
+ },
|
|
|
// 获取用户可用优惠券
|
|
|
getCouponList() {
|
|
|
+ let item = this.itemList[this.serverIndex]
|
|
|
let params = {
|
|
|
- consumAmount: this.amount, //订单金额
|
|
|
- couponScopeList: [
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- ],
|
|
|
- goodsType: 'ORDER' // string消费商品类型 ORDER 工单/ORDER_BUNDLE套餐订单
|
|
|
+ consumAmount: item.currentPrice, //服务金额
|
|
|
+ itemId: item.itemId // 服务id
|
|
|
}
|
|
|
+ uni.showLoading({
|
|
|
+ title: '正在查询可用优惠券...',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
couponEnable(params).then(res=> {
|
|
|
+ uni.hideLoading()
|
|
|
if (res.status == 200) {
|
|
|
this.couponList = res.data
|
|
|
+ this.checkedCoupon = this.couponList[0]
|
|
|
+ // 计算合计
|
|
|
+ this.getFinalAmount()
|
|
|
} else {
|
|
|
this.couponList = []
|
|
|
+ this.checkedCoupon = null
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- // 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
|
|
|
- formatCouponData() {
|
|
|
- let arr = []
|
|
|
- let _this = this
|
|
|
- this.couponList.map(item => {
|
|
|
- let data = {}
|
|
|
- data.id = item.couponReceivesId
|
|
|
- if (item.couponType == 'DISCOUNT') {
|
|
|
- console.log(_this.amount, '_this.amount')
|
|
|
- data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
|
|
|
- } else {
|
|
|
- data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
|
|
|
- }
|
|
|
- arr.push(data)
|
|
|
- })
|
|
|
- console.log(arr, 'arr')
|
|
|
- // 比较数据中优惠金额最大的值 并返回该对象
|
|
|
- let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
|
|
|
- console.log(obj)
|
|
|
- let p = this.couponList.find(item => item.couponReceivesId == obj.id)
|
|
|
- // 订单金额为0时,默认不使用优惠卷
|
|
|
- if (this.amount != 0) {
|
|
|
- this.checkedCoupon = p
|
|
|
- this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
|
|
|
- } else {
|
|
|
- this.checkedCoupon = null
|
|
|
- this.couponAmount = 0
|
|
|
- }
|
|
|
- // 计算合计
|
|
|
- this.getFinalAmount()
|
|
|
- },
|
|
|
+
|
|
|
// 计算合计
|
|
|
getFinalAmount() {
|
|
|
this.amount = this.itemList[this.serverIndex].currentPrice
|
|
|
+ this.couponAmount = (this.checkedCoupon && this.checkedCoupon.couponAmount > this.amount) ? this.amount : (this.checkedCoupon ?this.checkedCoupon.couponAmount : 0)
|
|
|
let ret = this.amount - this.couponAmount
|
|
|
this.finalAmount = ret.toFixed(2)
|
|
|
},
|
|
|
// 选择优惠券
|
|
|
intoChooseCoupon() {
|
|
|
+ this.couponList.map((item)=> {
|
|
|
+ item.checked = (this.checkedCoupon && item.id == this.checkedCoupon.id) ? true : false
|
|
|
+ })
|
|
|
uni.navigateTo({
|
|
|
- url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
|
|
|
+ url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}&curCoupon=${encodeURIComponent(JSON.stringify(this.checkedCoupon))}`
|
|
|
})
|
|
|
},
|
|
|
// 打开服务协议
|