- 规格栏显示改为直接展示规格重量,去除单价/100克显示 - 新增最小计费重量常量 MIN_BILLABLE_WEIGHT,净重不足时阻止下单 - 下单时检测净重,低于最小计费重量时弹出提示并拦截 - 计算价格时按净重计算,单价基于规格价与规格重量的比值 - 本地明细中 eatNum 仅用于展示份数,不参与金额计算 - SettlementOrder 用实际食用重量 eatWeight 赋值 num 字段,配合重量栏显示逻辑调整
66 lines
2.6 KiB
Kotlin
66 lines
2.6 KiB
Kotlin
package com.sw.dualscreen.adapter
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.graphics.Color
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import android.widget.TextView
|
|
import androidx.core.graphics.toColorInt
|
|
import androidx.core.view.updateLayoutParams
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import com.chad.library.adapter4.BaseQuickAdapter
|
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
|
import com.sw.dualscreen.databinding.ListItemFoodOrderBinding
|
|
import com.sw.dualscreen.ext.dp
|
|
import com.sw.dualscreen.ext.format2String
|
|
import com.sw.dualscreen.ext.gone
|
|
import com.sw.dualscreen.ext.visible
|
|
import com.sw.dualscreen.model.response.FoodItem
|
|
|
|
class FoodOrderAdapter(list: MutableList<FoodItem>) :
|
|
BaseQuickAdapter<FoodItem, FoodOrderAdapter.VH>(list) {
|
|
|
|
inner class VH(var binding: ListItemFoodOrderBinding) : QuickViewHolder(binding.root)
|
|
|
|
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
|
val inflater = LayoutInflater.from(context)
|
|
val binding = ListItemFoodOrderBinding.inflate(inflater, parent, false)
|
|
return VH(binding)
|
|
}
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
override fun onBindViewHolder(holder: VH, position: Int, item: FoodItem?) {
|
|
val binding = holder.binding
|
|
setTextColor(binding.tvFoodName, binding.tvPriceNorm, binding.tvWeight, binding.tvAmount)
|
|
item?.let {
|
|
binding.tvFoodName.text = it.foodName
|
|
binding.tvFoodName.setTextColor(if (it.isLocalData) Color.GREEN else "#FF33446A".toColorInt())
|
|
if (it.orderFrom == 2) {
|
|
binding.tvPriceNorm.text = if (it.specName.isNullOrBlank()) "${it.specWeight}克" else "${it.specName}/${it.specWeight}克"
|
|
} else {
|
|
// 营养秤结算:规格栏显示规格重量 specWeight
|
|
binding.tvPriceNorm.text = "${it.specWeight}克"
|
|
}
|
|
//if (it.specName.isNullOrBlank().not()) {
|
|
// binding.tvPriceFlag.text = "[${it.specName}]"
|
|
//}
|
|
binding.tvWeight.text = "${it.num}克"
|
|
binding.tvAmount.text = it.price.format2String(2)
|
|
binding.tvLabel.run {
|
|
if (it.orderFrom == 2) visible() else gone()
|
|
}
|
|
}
|
|
binding.root.updateLayoutParams<RecyclerView.LayoutParams> {
|
|
topMargin = 2.dp
|
|
bottomMargin = 2.dp
|
|
}
|
|
}
|
|
|
|
fun setTextColor(vararg tvList: TextView) {
|
|
tvList.forEach {
|
|
it.setTextColor("#FF33446A".toColorInt())
|
|
}
|
|
}
|
|
|
|
} |