refactor(servicing): 针对需求:234
- 司机现金收款界面,超限类型的只允许修改公里数,收款金额不允许修改 - 不论超限还是纯现金案件,在司机现金收款界面,全部填全程公里数,系统自动减去免拖公里数,计算出应收现金金额 - 司机现金收款界面,将“调整金额”字段名称改成“额外费用”
This commit is contained in:
@ -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)
|
||||||
|
}
|
@ -25,184 +25,167 @@ 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
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
vm.dispatch(ModifyMoneyViewModel.Action.Init(userOrderId, taskId))
|
vm.dispatch(ModifyMoneyViewModel.Action.Init(userOrderId, taskId))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uiState.value.saveSuccess == true) {
|
if (uiState.value.saveSuccess == true) {
|
||||||
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
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(it)
|
.padding(it)
|
||||||
.padding(20.dp)) {
|
.padding(20.dp)) {
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
if (uiState.value.paymentInfoBean?.payItem == 1) {
|
if (uiState.value.paymentInfoBean?.payItem == 1) {
|
||||||
MoneyInputField(value = "${uiState.value.unitPrice ?: "0"}",
|
MoneyInputField(value = "${uiState.value.unitPrice ?: "0"}",
|
||||||
onValueChange = { vm.updateState(uiState.value.copy(unitPrice = it.toFloat())) },
|
onValueChange = { vm.updateState(uiState.value.copy(unitPrice = it.toFloat())) },
|
||||||
label = "单价",
|
label = "单价",
|
||||||
suffix = "元/公里",
|
suffix = "元/公里",
|
||||||
hint = uiState.value.paymentInfoBean?.unitPrice?.toString() ?: "0",
|
hint = uiState.value.paymentInfoBean?.unitPrice?.toString() ?: "0",
|
||||||
enabled = false)
|
enabled = false)
|
||||||
} else {
|
} else {
|
||||||
MoneyInputField(value = "${uiState.value.unitPrice ?: "0"}",
|
MoneyInputField(value = "${uiState.value.unitPrice ?: "0"}",
|
||||||
onValueChange = { vm.updateState(uiState.value.copy(unitPrice = it.toFloat())) },
|
onValueChange = { vm.updateState(uiState.value.copy(unitPrice = it.toFloat())) },
|
||||||
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 = Color.White,
|
||||||
color = backgroundColor,
|
shape = RoundedCornerShape(16.dp)) {
|
||||||
shape = RoundedCornerShape(16.dp)
|
Row(modifier = Modifier
|
||||||
) {
|
.fillMaxWidth()
|
||||||
Row(
|
.padding(horizontal = 20.dp, vertical = 16.dp),
|
||||||
modifier = Modifier
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
.fillMaxWidth()
|
verticalAlignment = Alignment.CenterVertically) {
|
||||||
.padding(horizontal = 20.dp, vertical = 16.dp),
|
Column {
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
Text(text = "总金额",
|
||||||
verticalAlignment = Alignment.CenterVertically
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
) {
|
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
Column {
|
Text(text = "¥ ${uiState.value.totalMoney ?: 0}",
|
||||||
Text(
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
text = "总金额",
|
color = headBgColor,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
fontWeight = FontWeight.Bold)
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
}
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "¥ ${uiState.value.totalMoney ?: 0}",
|
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
|
||||||
color = headBgColor,
|
|
||||||
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(containerColor = headBgColor)) {
|
||||||
colors = ButtonDefaults.buttonColors(
|
Text("保存",
|
||||||
containerColor = headBgColor
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
)
|
fontWeight = FontWeight.Medium)
|
||||||
) {
|
}
|
||||||
Text(
|
}
|
||||||
"保存",
|
}
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
}
|
||||||
fontWeight = FontWeight.Medium
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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)
|
placeholder = { Text(hint, color = secondaryTextColor) },
|
||||||
OutlinedTextField(
|
onValueChange = onValueChange,
|
||||||
value = value,
|
label = { Text(label, color = secondaryTextColor) },
|
||||||
placeholder = { Text(hint, color = secondaryTextColor) },
|
modifier = Modifier
|
||||||
onValueChange = onValueChange,
|
.fillMaxWidth()
|
||||||
label = { Text(label, color = secondaryTextColor) },
|
.padding(vertical = 4.dp),
|
||||||
modifier = Modifier
|
enabled = enabled,
|
||||||
.fillMaxWidth()
|
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
||||||
.padding(vertical = 4.dp),
|
trailingIcon = {
|
||||||
enabled = enabled,
|
Text(suffix, modifier = Modifier.padding(end = 12.dp), color = secondaryTextColor)
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
|
},
|
||||||
trailingIcon = { Text(suffix, modifier = Modifier.padding(end = 12.dp), color = secondaryTextColor) },
|
colors = OutlinedTextFieldDefaults.colors(focusedBorderColor = headBgColor,
|
||||||
colors = OutlinedTextFieldDefaults.colors(
|
unfocusedBorderColor = Color(0xFFE0E0E0),
|
||||||
focusedBorderColor = headBgColor,
|
focusedLabelColor = headBgColor,
|
||||||
unfocusedBorderColor = Color(0xFFE0E0E0),
|
unfocusedLabelColor = secondaryTextColor,
|
||||||
focusedLabelColor = headBgColor,
|
cursorColor = headBgColor),
|
||||||
unfocusedLabelColor = secondaryTextColor,
|
shape = RoundedCornerShape(8.dp))
|
||||||
cursorColor = headBgColor
|
}
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(8.dp)
|
@Preview
|
||||||
)
|
@Composable
|
||||||
|
private fun ModifyMoneyPre() {
|
||||||
|
ModifyMoneyScreen(userOrderId = 0, taskId = 0)
|
||||||
}
|
}
|
@ -64,23 +64,20 @@ 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)
|
) {
|
||||||
) {
|
uiState.value.paymentInfoBean?.startPrice ?: 0f
|
||||||
uiState.value.paymentInfoBean?.startPrice ?: 0f
|
} else {
|
||||||
} else {
|
(mileage - (uiState.value.paymentInfoBean?.limitedMileage ?: 0))
|
||||||
(mileage - (uiState.value.paymentInfoBean?.limitedMileage ?: 0))
|
.times(uiState.value.unitPrice ?: 0f)
|
||||||
.times(uiState.value.unitPrice ?: 0f)
|
.plus(uiState.value.paymentInfoBean?.startPrice ?: 0)
|
||||||
.plus(uiState.value.paymentInfoBean?.startPrice ?: 0)
|
|
||||||
}
|
|
||||||
updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount.toFloat(),
|
|
||||||
totalMoney = calculateAmount.toFloat().plus(uiState.value.adjustAmount ?: 0f)))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
val calculateAmount = mileage.times(uiState.value.unitPrice ?: 0f)
|
updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount.toFloat(),
|
||||||
val totalMoney = calculateAmount + (uiState.value.paymentInfoBean?.adjustAmount ?: 0)
|
totalMoney = calculateAmount.toFloat().plus(uiState.value.adjustAmount ?: 0f)))
|
||||||
updateState(uiState.value.copy(mileage = mileage, mileageText = value, calculateAmount = calculateAmount, totalMoney = totalMoney))
|
// val calculateAmount = mileage.times(uiState.value.unitPrice ?: 0f)
|
||||||
|
// 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?) {
|
||||||
|
Reference in New Issue
Block a user