refactor(servicing): 针对需求:234

- 司机现金收款界面,超限类型的只允许修改公里数,收款金额不允许修改
- 不论超限还是纯现金案件,在司机现金收款界面,全部填全程公里数,系统自动减去免拖公里数,计算出应收现金金额
- 司机现金收款界面,将“调整金额”字段名称改成“额外费用”
This commit is contained in:
songzhiling
2025-04-28 10:10:02 +08:00
parent 863329d107
commit bc4590755a
3 changed files with 158 additions and 176 deletions

View File

@ -67,6 +67,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
import com.blankj.utilcode.util.ToastUtils import com.blankj.utilcode.util.ToastUtils
import com.za.base.BaseActivity import com.za.base.BaseActivity
import com.za.base.theme.bgColor
import com.za.base.theme.black90 import com.za.base.theme.black90
import com.za.base.view.CommonDialog import com.za.base.view.CommonDialog
import com.za.base.view.HeadView import com.za.base.view.HeadView
@ -98,11 +99,6 @@ class InputMoneyActivity : BaseActivity() {
} }
} }
@Preview(showBackground = true)
@Composable
fun PreviewInputMoneyScreen() {
InputMoneyScreen(userOrderId = 1, taskId = 1)
}
@Composable @Composable
fun InputMoneyScreen(userOrderId : Int, taskId : Int, vm : InputMoneyVm = viewModel()) { fun InputMoneyScreen(userOrderId : Int, taskId : Int, vm : InputMoneyVm = viewModel()) {
@ -144,7 +140,7 @@ fun InputMoneyScreen(userOrderId : Int, taskId : Int, vm : InputMoneyVm = viewMo
.padding(16.dp), .padding(16.dp),
tonalElevation = 8.dp, tonalElevation = 8.dp,
shadowElevation = 8.dp, shadowElevation = 8.dp,
color = backgroundColor, color = bgColor,
shape = RoundedCornerShape(24.dp)) { shape = RoundedCornerShape(24.dp)) {
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -162,7 +158,7 @@ fun InputMoneyScreen(userOrderId : Int, taskId : Int, vm : InputMoneyVm = viewMo
contentColor = Color.White), contentColor = Color.White),
elevation = ButtonDefaults.buttonElevation(4.dp), elevation = ButtonDefaults.buttonElevation(4.dp),
interactionSource = remember { MutableInteractionSource() }) { interactionSource = remember { MutableInteractionSource() }) {
Text("收款", fontSize = 12.sp, fontWeight = FontWeight.Medium) Text("收款", fontSize = 12.sp, fontWeight = FontWeight.Medium)
} }
Button(onClick = { Button(onClick = {
@ -418,3 +414,9 @@ private fun SuccessDialog(amount : String, onDismiss : () -> Unit) {
} }
} }
} }
@Preview()
@Composable
fun PreviewInputMoneyScreen() {
InputMoneyScreen(userOrderId = 1, taskId = 1)
}

View File

@ -25,18 +25,19 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.za.base.theme.bgColor
import com.za.base.theme.headBgColor import com.za.base.theme.headBgColor
import com.za.base.view.HeadView import com.za.base.view.HeadView
import com.za.ext.finish import com.za.ext.finish
import com.za.ui.servicing.order_confirm.modify_money.ModifyMoneyViewModel import com.za.ui.servicing.order_confirm.modify_money.ModifyMoneyViewModel
import com.za.ui.servicing.order_confirm.receive_money.backgroundColor
@Composable @Composable
fun ModifyMoneyScreen(userOrderId: Int, taskId: Int, vm: ModifyMoneyViewModel = viewModel()) { fun ModifyMoneyScreen(userOrderId : Int, taskId : Int, vm : ModifyMoneyViewModel = viewModel()) {
val uiState = vm.uiState.collectAsStateWithLifecycle() val uiState = vm.uiState.collectAsStateWithLifecycle()
val context = LocalContext.current val context = LocalContext.current
@ -48,7 +49,7 @@ fun ModifyMoneyScreen(userOrderId: Int, taskId: Int, vm: ModifyMoneyViewModel =
context.finish() context.finish()
} }
Scaffold(topBar = { Scaffold(containerColor = bgColor, topBar = {
HeadView(title = "修改金额", onBack = { context.finish() }) HeadView(title = "修改金额", onBack = { context.finish() })
}) { }) {
Column(modifier = Modifier Column(modifier = Modifier
@ -69,104 +70,84 @@ fun ModifyMoneyScreen(userOrderId: Int, taskId: Int, vm: ModifyMoneyViewModel =
label = "超限单价", label = "超限单价",
suffix = "元/公里", suffix = "元/公里",
hint = uiState.value.paymentInfoBean?.unitPrice?.toString() ?: "0", hint = uiState.value.paymentInfoBean?.unitPrice?.toString() ?: "0",
enabled = false enabled = false)
)
} }
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
MoneyInputField( MoneyInputField(value = uiState.value.mileageText ?: "",
value = uiState.value.mileageText ?: "",
onValueChange = { onValueChange = {
vm.dispatch(ModifyMoneyViewModel.Action.ChangeMileage((it))) vm.dispatch(ModifyMoneyViewModel.Action.ChangeMileage((it)))
}, },
label = "公里数", label = "全程公里数",
hint = uiState.value.paymentInfoBean?.mileage?.toString() ?: "0", hint = uiState.value.paymentInfoBean?.mileage?.toString() ?: "0",
suffix = "公里" suffix = "公里")
)
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
MoneyInputField( MoneyInputField(value = "${uiState.value.calculateAmount ?: 0}",
value = "${uiState.value.calculateAmount ?: 0}",
onValueChange = { }, onValueChange = { },
label = "计算金额", label = "计算金额",
suffix = "", suffix = "",
hint = uiState.value.paymentInfoBean?.calculateAmount?.toString() ?: "0", hint = uiState.value.paymentInfoBean?.calculateAmount?.toString() ?: "0",
enabled = false enabled = false)
)
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
MoneyInputField( //超限类型只允许修改公里数,额外费用和超限单价不允许修改
value = uiState.value.adjustAmountText ?: "", MoneyInputField(value = uiState.value.adjustAmountText ?: "",
onValueChange = { onValueChange = {
vm.dispatch(ModifyMoneyViewModel.Action.ChangeAdjustAmount(it)) vm.dispatch(ModifyMoneyViewModel.Action.ChangeAdjustAmount(it))
}, },
label = "调整金", label = "外费用",
hint = uiState.value.paymentInfoBean?.adjustAmount?.toString() ?: "0", hint = uiState.value.paymentInfoBean?.adjustAmount?.toString() ?: "0",
suffix = "" suffix = "",
) enabled = uiState.value.paymentInfoBean?.payItem == 1)
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(2.dp))
OutlinedTextField( OutlinedTextField(value = uiState.value.adjustRemark,
value = uiState.value.adjustRemark,
onValueChange = { vm.updateState(uiState.value.copy(adjustRemark = it)) }, onValueChange = { vm.updateState(uiState.value.copy(adjustRemark = it)) },
label = { Text("调整原因") }, label = { Text("调整原因") },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(80.dp) .height(80.dp),
) enabled = uiState.value.paymentInfoBean?.payItem == 1)
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
// 替换原来的 Row 为新的底部布局 // 替换原来的 Row 为新的底部布局
Surface( Surface(modifier = Modifier
modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(bottom = 16.dp), .padding(bottom = 16.dp),
tonalElevation = 8.dp, tonalElevation = 8.dp,
shadowElevation = 8.dp, shadowElevation = 8.dp,
color = backgroundColor, color = Color.White,
shape = RoundedCornerShape(16.dp) shape = RoundedCornerShape(16.dp)) {
) { Row(modifier = Modifier
Row(
modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 16.dp), .padding(horizontal = 20.dp, vertical = 16.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically) {
) {
Column { Column {
Text( Text(text = "总金额",
text = "总金额",
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant color = MaterialTheme.colorScheme.onSurfaceVariant)
) Text(text = "¥ ${uiState.value.totalMoney ?: 0}",
Text(
text = "¥ ${uiState.value.totalMoney ?: 0}",
style = MaterialTheme.typography.headlineMedium, style = MaterialTheme.typography.headlineMedium,
color = headBgColor, color = headBgColor,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold)
)
} }
Button( Button(onClick = { vm.dispatch(ModifyMoneyViewModel.Action.Save) },
onClick = { vm.dispatch(ModifyMoneyViewModel.Action.Save) },
modifier = Modifier modifier = Modifier
.height(48.dp) .height(48.dp)
.width(120.dp), .width(120.dp),
shape = RoundedCornerShape(24.dp), shape = RoundedCornerShape(24.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(containerColor = headBgColor)) {
containerColor = headBgColor Text("保存",
)
) {
Text(
"保存",
style = MaterialTheme.typography.bodyLarge, style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Medium fontWeight = FontWeight.Medium)
)
} }
} }
} }
@ -175,18 +156,15 @@ fun ModifyMoneyScreen(userOrderId: Int, taskId: Int, vm: ModifyMoneyViewModel =
} }
@Composable @Composable
private fun MoneyInputField( private fun MoneyInputField(value : String,
value: String, onValueChange : (String) -> Unit,
onValueChange: (String) -> Unit, label : String,
label: String, suffix : String,
suffix: String, hint : String,
hint: String, keyboardType : KeyboardType = KeyboardType.Decimal,
keyboardType: KeyboardType = KeyboardType.Decimal, enabled : Boolean = true) {
enabled: Boolean = true val secondaryTextColor = Color(0xFF666666)
) { OutlinedTextField(value = value,
val secondaryTextColor=Color(0xFF666666)
OutlinedTextField(
value = value,
placeholder = { Text(hint, color = secondaryTextColor) }, placeholder = { Text(hint, color = secondaryTextColor) },
onValueChange = onValueChange, onValueChange = onValueChange,
label = { Text(label, color = secondaryTextColor) }, label = { Text(label, color = secondaryTextColor) },
@ -195,14 +173,19 @@ private fun MoneyInputField(
.padding(vertical = 4.dp), .padding(vertical = 4.dp),
enabled = enabled, enabled = enabled,
keyboardOptions = KeyboardOptions(keyboardType = keyboardType), keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
trailingIcon = { Text(suffix, modifier = Modifier.padding(end = 12.dp), color = secondaryTextColor) }, trailingIcon = {
colors = OutlinedTextFieldDefaults.colors( Text(suffix, modifier = Modifier.padding(end = 12.dp), color = secondaryTextColor)
focusedBorderColor = headBgColor, },
colors = OutlinedTextFieldDefaults.colors(focusedBorderColor = headBgColor,
unfocusedBorderColor = Color(0xFFE0E0E0), unfocusedBorderColor = Color(0xFFE0E0E0),
focusedLabelColor = headBgColor, focusedLabelColor = headBgColor,
unfocusedLabelColor = secondaryTextColor, unfocusedLabelColor = secondaryTextColor,
cursorColor = headBgColor cursorColor = headBgColor),
), shape = RoundedCornerShape(8.dp))
shape = RoundedCornerShape(8.dp) }
)
@Preview
@Composable
private fun ModifyMoneyPre() {
ModifyMoneyScreen(userOrderId = 0, taskId = 0)
} }

View File

@ -64,7 +64,6 @@ class ModifyMoneyViewModel : BaseVm<Action, UiState>() {
private fun changeMileage(value: String?) { private fun changeMileage(value: String?) {
val mileage = value?.toFloatOrNull() ?: 0f val mileage = value?.toFloatOrNull() ?: 0f
if (uiState.value.paymentInfoBean?.payItem == 1) {
val calculateAmount = if (mileage <= (uiState.value.paymentInfoBean?.limitedMileage val calculateAmount = if (mileage <= (uiState.value.paymentInfoBean?.limitedMileage
?: 0) ?: 0)
) { ) {
@ -76,11 +75,9 @@ class ModifyMoneyViewModel : BaseVm<Action, UiState>() {
} }
updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount.toFloat(), updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount.toFloat(),
totalMoney = calculateAmount.toFloat().plus(uiState.value.adjustAmount ?: 0f))) totalMoney = calculateAmount.toFloat().plus(uiState.value.adjustAmount ?: 0f)))
return // val calculateAmount = mileage.times(uiState.value.unitPrice ?: 0f)
} // val totalMoney = calculateAmount + (uiState.value.paymentInfoBean?.adjustAmount ?: 0)
val calculateAmount = mileage.times(uiState.value.unitPrice ?: 0f) // updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount, totalMoney = totalMoney))
val totalMoney = calculateAmount + (uiState.value.paymentInfoBean?.adjustAmount ?: 0)
updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount, totalMoney = totalMoney))
} }
private fun changeAdjustAmount(value: String?) { private fun changeAdjustAmount(value: String?) {