Commit af834644 authored by shiyl's avatar shiyl

选择代金券逻辑优化

parent bc03a3cc
...@@ -45,8 +45,6 @@ data class CouponDto( ...@@ -45,8 +45,6 @@ data class CouponDto(
val endTime: String? = null,// 有效期结束时间 val endTime: String? = null,// 有效期结束时间
@SerializedName("status") @SerializedName("status")
val status: Int? = null,// 优惠券状态 val status: Int? = null,// 优惠券状态
@SerializedName("selected")
var selected: Boolean? = false,// 优惠券是否被选中
) : Parcelable ) : Parcelable
/** /**
......
...@@ -126,6 +126,8 @@ class ConfirmOrderViewModel : BaseViewModel() { ...@@ -126,6 +126,8 @@ class ConfirmOrderViewModel : BaseViewModel() {
* 选择代金券, 如果有上次选中的带过去最新的列表 * 选择代金券, 如果有上次选中的带过去最新的列表
*/ */
fun chooseVoucher() { fun chooseVoucher() {
//选择之前先将上次的金额清零
couponAmount = 0.00
_chooseCouponEvent.value = couponsAvailableList.value _chooseCouponEvent.value = couponsAvailableList.value
} }
...@@ -137,11 +139,9 @@ class ConfirmOrderViewModel : BaseViewModel() { ...@@ -137,11 +139,9 @@ class ConfirmOrderViewModel : BaseViewModel() {
val list = mutableListOf<CouponDto>() val list = mutableListOf<CouponDto>()
indexList.forEach { indexList.forEach {
val coupon = couponsAvailableList.value?.get(it) val coupon = couponsAvailableList.value?.get(it)
//将该优惠券更新为选中状态
coupon?.let { couponDto -> coupon?.let { couponDto ->
// 累加优惠券金额 // 累加优惠券金额
couponAmount += couponDto.amount?.toDouble() ?: 0.00 couponAmount += couponDto.amount?.toDouble() ?: 0.00
couponDto.selected = true
list.add(couponDto) list.add(couponDto)
} }
} }
......
...@@ -296,7 +296,7 @@ ...@@ -296,7 +296,7 @@
android:paddingTop="@dimen/dp2" android:paddingTop="@dimen/dp2"
android:paddingEnd="@dimen/dp5" android:paddingEnd="@dimen/dp5"
android:paddingBottom="@dimen/dp2" android:paddingBottom="@dimen/dp2"
android:text="@{@string/amount(vm.couponAmountValue)}" android:text='@{"- " + @string/amount(vm.couponAmountValue)}'
android:textColor="@color/color_FD7823" android:textColor="@color/color_FD7823"
android:textSize="11sp" android:textSize="11sp"
app:isShow="@{vm.selectedCouponList.size() > 0}" app:isShow="@{vm.selectedCouponList.size() > 0}"
......
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