You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
5.1 KiB
146 lines
5.1 KiB
package com.gyf.csams.main.ui
|
|
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.annotation.StringRes
|
|
import androidx.compose.foundation.border
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
import androidx.compose.material.MaterialTheme
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.gyf.csams.R
|
|
import com.gyf.csams.main.model.RenameViewModel
|
|
import com.gyf.csams.main.model.RenameVo
|
|
import com.gyf.lib.uikit.BaseTextField
|
|
import com.gyf.lib.uikit.BodyS
|
|
import com.gyf.lib.uikit.MainColumnFrame
|
|
import com.gyf.lib.uikit.ScaffoldModel
|
|
import com.gyf.lib.util.BottomButton
|
|
|
|
class RenameActivity : ComponentActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContent {
|
|
BodyS {
|
|
MainColumnFrame(background = { /*TODO*/ }) {
|
|
val listState = rememberLazyListState()
|
|
val model: RenameViewModel = viewModel()
|
|
val data by model.data.observeAsState()
|
|
Row(
|
|
horizontalArrangement = Arrangement.Center,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(10.dp)
|
|
) {
|
|
Text(
|
|
text = stringResource(id = R.string.rename_form),
|
|
style = MaterialTheme.typography.h4
|
|
)
|
|
}
|
|
LazyColumn(state = listState) {
|
|
data?.forEach {
|
|
item {
|
|
RenameForm(renameVo = it)
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun RenameForm(modifier: Modifier = Modifier, renameVo: RenameVo) {
|
|
val model: RenameViewModel = viewModel()
|
|
val scaffoldModel: ScaffoldModel = viewModel()
|
|
Column(modifier = modifier) {
|
|
val baseHeight = 50.dp
|
|
RowItem(
|
|
modifier = Modifier.height(baseHeight),
|
|
key = R.string.petitioner,
|
|
value = renameVo.studentId
|
|
)
|
|
RowItem(
|
|
modifier = Modifier.height(baseHeight),
|
|
key = R.string.oldname,
|
|
value = renameVo.oldName
|
|
)
|
|
RowItem(
|
|
modifier = Modifier.height(baseHeight),
|
|
key = R.string.newname,
|
|
value = renameVo.newName
|
|
)
|
|
RowItem(
|
|
modifier = Modifier.height(baseHeight),
|
|
key = R.string.reason_for_application,
|
|
value = renameVo.reason
|
|
)
|
|
RowItem(
|
|
modifier = Modifier.height(baseHeight), key = R.string.approver, value = ""
|
|
/**TODO 获取审批人**/
|
|
)
|
|
RowItem(modifier = Modifier.height(baseHeight * 3), key = R.string.approver_origin) {
|
|
BaseTextField(modifier = Modifier.fillMaxSize(), form = model.approverOrigin)
|
|
}
|
|
val message = stringResource(id = R.string.not_impl_error)
|
|
BottomButton(modifier = Modifier.fillMaxWidth()) {
|
|
scaffoldModel.update(message = message)
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun RowItem(
|
|
modifier: Modifier = Modifier,
|
|
@StringRes key: Int,
|
|
value: String? = null,
|
|
content: (@Composable () -> Unit)? = null
|
|
) {
|
|
Row(
|
|
modifier = modifier
|
|
.fillMaxWidth()
|
|
.border(width = 1.dp, color = Color.Black)
|
|
) {
|
|
Cell(
|
|
modifier = Modifier.weight(0.5F),
|
|
value = stringResource(id = key)
|
|
)
|
|
Cell(modifier = Modifier.weight(0.5F), value = value, content = content)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun Cell(
|
|
modifier: Modifier = Modifier,
|
|
value: String? = null,
|
|
content: (@Composable () -> Unit)? = null
|
|
) {
|
|
Box(
|
|
modifier = modifier
|
|
.fillMaxSize()
|
|
.border(width = 1.dp, color = MaterialTheme.colors.onBackground),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
if (content != null) content() else Text(
|
|
text = value ?: throw IllegalArgumentException(
|
|
"参数错误"
|
|
)
|
|
)
|
|
}
|
|
}
|
|
} |