联合支付余量计量模式订单显示当前取餐信息

This commit is contained in:
2026-03-25 15:42:22 +08:00
parent fcea0d785d
commit fb4278d2b7
8 changed files with 108 additions and 42 deletions
@@ -24,9 +24,11 @@ import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.common.util.concurrent.ListenableFuture
import com.sw.dualscreen.GlobalData
import com.sw.dualscreen.GlobalKey
import com.sw.dualscreen.adapter.FoodOrderAdapter
import com.sw.dualscreen.adapter.MainFoodListAdapter
import com.sw.dualscreen.databinding.ActivityMainBinding
import com.sw.dualscreen.dialog.RemindDialog
@@ -290,11 +292,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (weight <= WEIGHT_RESET_RECOGNIZE) {
//秤上重量过小,显示识别中页面
presentation?.step1FoodRecognizing()
lastWeight = weight
return
}
//余量计量+联合支付人脸查询订单完成
if (presentation!!.jointPaymentQueryFinish) {
presentation?.updateWeight(weight)
lastWeight = weight
return
}
val isWeightChange = weight - lastWeight > WEIGHT_CHANGE_VALUE
@@ -303,12 +307,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
private fun readWeight(weight: Int) {
log("registerDataChange weight = $weight")
runOnUiThread {
binding.tvShowWeight.let {
if (it.text.toString() == weight.toString()) return@runOnUiThread
binding.tvShowWeight.let {
if (it.text.toString() != weight.toString()) {
it.text = "$weight"
}
}
if (weight <= WEIGHT_RESET_RECOGNIZE) {
//检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
checkedItem = null
}
if (settlementMode == 0) {
//联合支付-------------------------------------------
//0-即放即取,1-余量计量
@@ -344,7 +351,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun registerDataChange() {
super.registerDataChange()
SensorScaleUtils.addWeightListener { value ->
readWeight(value)
runOnUiThread {
readWeight(value)
}
}
}
@@ -356,7 +365,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
presentation?.updateWeight(weight)
if (weight <= WEIGHT_RESET_RECOGNIZE) {
log("recognizeByWeight---00002,秤重未超过5")
log("recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}")
//检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
isRecognitionFood = true
return
@@ -364,8 +373,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (isWeightChange && isRecognitionFood) {
log("recognizeByWeight---00003,mealPickupMode=${presentation?.mealPickupMode}")
if (presentation?.mealPickupMode == 1) {
if (presentation?.mealPickupMode == 1 && checkedItem != null) {
isRecognitionFood = false
return
}
debouncer.debounce {
log("recognizeByWeight---00004")
@@ -1171,4 +1181,5 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
// ObjectBox.init(this)
// }
}
@@ -17,7 +17,7 @@ import com.sw.dualscreen.ext.gone
import com.sw.dualscreen.ext.visible
import com.sw.dualscreen.model.response.FoodItem
class FoodOrderAdapter(var list: MutableList<FoodItem>) :
class FoodOrderAdapter(list: MutableList<FoodItem>) :
BaseQuickAdapter<FoodItem, FoodOrderAdapter.VH>(list) {
inner class VH(var binding: ListItemFoodOrderBinding) : QuickViewHolder(binding.root)
@@ -33,10 +33,10 @@ class FoodOrderAdapter(var list: MutableList<FoodItem>) :
val binding = holder.binding
item?.let {
binding.tvFoodName.text = it.foodName
val foodPrice = it.foodPrice.format2String(2)
if (it.orderFrom == 2) {
binding.tvPriceNorm.text = "${it.specName}/${it.specWeight}"
binding.tvPriceNorm.text = if (it.specName.isNullOrBlank()) "${it.specWeight}" else "${it.specName}/${it.specWeight}"
} else {
val foodPrice = it.foodPrice.format2String(2)
binding.tvPriceNorm.text = "${foodPrice}/${it.num}"
}
//if (it.specName.isNullOrBlank().not()) {
@@ -165,22 +165,23 @@ data class WeightRecord(
)
data class FoodItem(
val id: String? = null,
val foodId: String? = null,
val foodName: String? = null,
val foodMaterialId: String? = null,
val specId: String? = null,
val num: Int = 0,
val eatNum: Int = 0,
val price: Double = 0.0,
val foodPrice: Double = 0.0,
val discount: Double = 0.0,
val income: Double = 0.0,
val foodDifferenceId: Long = 0,
val createTime: String? = null,
val specName: String? = null,
val specWeight: Int = 0,
val orderFrom: Int = 0
var id: String? = null,
var foodId: String? = null,
var foodName: String? = null,
var foodMaterialId: String? = null,
var specId: String? = null,
var num: Int = 0,
var eatNum: Int = 0,
var price: Double = 0.0,
var foodPrice: Double = 0.0,
var discount: Double = 0.0,
var income: Double = 0.0,
var foodDifferenceId: Long = 0,
var createTime: String? = null,
var specName: String? = null,
var specWeight: Int = 0,
var orderFrom: Int = 0,
var isLocalData: Boolean = false
)
data class FoodOrderModel(
@@ -314,7 +314,7 @@ interface ApiService {
): ApiResponse<Any?>
/**
* 档口机向量数据分页查询
* 查询就餐数据
*/
@GET
suspend fun getFoodOrderList(
@@ -670,12 +670,63 @@ class MainScreenPresentation(
// }
}
private var lastAddWeight = 0
private fun addFoodToOrder(weight: Int, foodInfo: FoodInfo) {
if (weight == lastAddWeight) return
lastAddWeight = weight
if (weight <= 10) {
if (foodOrderList.isNotEmpty()) {
val last = foodOrderList.last()
if (last.isLocalData) {
foodOrderList.remove(last)
foodOrderAdapter.submitList(foodOrderList)
//foodOrderAdapter.notifyDataSetChanged()
}
}
return
}
val foodPrice = if (isMember) foodInfo.vipPrice else foodInfo.specPrice
val eatNum = activity.getEatNum(weight.toDouble(), foodInfo.specWeight)
val price = eatNum * (foodPrice?:0.0)
if (foodOrderList.isNotEmpty()) {
val last = foodOrderList.last()
if (last.isLocalData) {
last.eatNum = eatNum
last.num = weight
last.price = price
foodOrderAdapter.submitList(foodOrderList)
//foodOrderAdapter.notifyItemChanged(foodOrderList.lastIndex)
return
}
}
foodOrderList.add(FoodItem(
id = System.currentTimeMillis().toString(),
foodId = foodInfo.foodId,
foodName = foodInfo.foodName,
price = price,
specId = foodInfo.specId,
foodMaterialId = foodInfo.foodMaterialId,
specWeight = foodInfo.specWeight?.toInt() ?: 0,
orderFrom = 2,
num = weight,
eatNum = eatNum,
isLocalData = true
))
foodOrderAdapter.submitList(foodOrderList)
//foodOrderAdapter.notifyDataSetChanged()
}
private fun calculateNutrition(value: Int) {
if (currentFood == null || userNutrition == null) {
return
}
var weight = value
if (weight < 0) weight = 0
if (activity.settlementMode == 0) {
activity.runOnUiThread {
addFoodToOrder(weight, currentFood!!)
}
}
debouncer.debounce {
Timber.tag(TAG)
.d("calculateNutrition weight = $weight, recognitionWeight = $recognitionWeight")
@@ -1341,7 +1392,7 @@ class MainScreenPresentation(
it.root.updateLayoutParams {
height = activity.screenSize[1] / 2 + 120.dp
}
it.tvFoodList.run {
it.rvFoodList.run {
if (adapter == null) {
layoutManager =
LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
@@ -1349,16 +1400,17 @@ class MainScreenPresentation(
}
}
userViewModel.getFoodOrderList(userId) { model ->
if (model == null) return@getFoodOrderList
foodOrderList.clear()
model.list?.let {
foodOrderList.addAll(model.list)
}
foodOrderAdapter.notifyDataSetChanged()
binding.detailInclude.tvTotalWeight.text = "总重量:${model.eatWeightSum}"
binding.detailInclude.tvTotalCalorie.text =
"总热量:${model.calorie.roundToInt()}千卡"
jointPaymentQueryFinish = true
activity.runOnUiThread {
if (model == null) return@runOnUiThread
foodOrderList.clear()
foodOrderList.addAll(model.list?:emptyList())
foodOrderAdapter.submitList(foodOrderList)
//foodOrderAdapter.notifyDataSetChanged()
binding.detailInclude.tvTotalWeight.text = "总重量:${model.eatWeightSum}"
binding.detailInclude.tvTotalCalorie.text =
"总热量:${model.calorie.roundToInt()}千卡"
jointPaymentQueryFinish = true
}
}
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/darker_gray"/>
<stroke android:color="#cdcdcd" android:width="1dp"/>
<solid android:color="#F2F2F2"/>
<!-- <stroke android:color="#cdcdcd" android:width="1dp"/>-->
<corners android:radius="5dp"/>
</shape>
+4 -2
View File
@@ -51,10 +51,11 @@
<TextView
android:id="@+id/tvShowWeight"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="80dp"
android:textSize="40sp"
android:textSize="20sp"
android:gravity="center"
android:maxLines="1"
android:textColor="@color/black"
tools:text="100克"/>
@@ -87,6 +88,7 @@
android:layout_margin="27dp"
android:background="@drawable/ic_camera_rect" />
<!-- preview_border-->
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
@@ -50,7 +50,7 @@
android:background="#FFDDE5F0" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tvFoodList"
android:id="@+id/rvFoodList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"