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.
260 lines
9.0 KiB
260 lines
9.0 KiB
package com.gyf.csams.uikit
|
|
|
|
import androidx.annotation.StringRes
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.material.ExperimentalMaterialApi
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.google.accompanist.insets.ExperimentalAnimatedInsets
|
|
import com.gyf.csams.R
|
|
import com.gyf.csams.main.model.BaseAuditViewModel
|
|
import com.gyf.csams.module.AuditVo
|
|
import com.gyf.csams.module.Duty
|
|
import com.gyf.lib.uikit.*
|
|
import com.gyf.lib.util.BottomButton
|
|
import com.gyf.lib.util.TokenManager
|
|
|
|
val BASE_HEIGHT = 50.dp
|
|
|
|
@ExperimentalMaterialApi
|
|
@ExperimentalAnimatedInsets
|
|
@Composable
|
|
inline fun <reified T : AuditVo, reified E : BaseAuditViewModel<T>> ContentCheckForm(
|
|
@StringRes title: Int,
|
|
crossinline RegisterForm: @Composable (vo: T) -> Unit
|
|
) {
|
|
ImeBody {
|
|
val model: E = viewModel()
|
|
val data by model.data.observeAsState()
|
|
TestTableImeSimple(
|
|
title = title
|
|
) {
|
|
data?.forEach {
|
|
item {
|
|
RegisterForm(vo = it)
|
|
CheckForm<T, E>(vo = it)
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 表格审核组件
|
|
*
|
|
* @param VO
|
|
* @param M
|
|
* @param vo
|
|
* @param scaffoldModel
|
|
* @param model
|
|
* @param first
|
|
* @param last
|
|
*/
|
|
@Composable
|
|
inline fun <reified VO : AuditVo, reified M : BaseAuditViewModel<VO>> CheckForm(
|
|
vo: VO,
|
|
scaffoldModel: ScaffoldModel = viewModel(),
|
|
model: M = viewModel(),
|
|
first: @Composable () -> Unit = {
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.first_approver,
|
|
value = vo.audit.manager?.name ?: ""
|
|
)
|
|
},
|
|
last: @Composable () -> Unit = {
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.last_approver,
|
|
value = vo.audit.nextAudit?.manager?.name ?: ""
|
|
)
|
|
}
|
|
) {
|
|
|
|
|
|
TokenManager.getManagerInfo()?.let { it ->
|
|
var confirmDesc: Int? = null
|
|
var backDesc: Int? = null
|
|
var onConfirm: (() -> Unit)? = null
|
|
var onBack: (() -> Unit)? = null
|
|
val check: (result: Boolean, cause: StringForm) -> Unit =
|
|
{ result: Boolean, cause: StringForm ->
|
|
scaffoldModel.update(
|
|
message = "确认${if (result) "上报" else "驳回"}?",
|
|
actionLabel = "确认"
|
|
) {
|
|
model.check(
|
|
auditId = vo.audit.id,
|
|
result = result,
|
|
cause = cause.getValue()
|
|
) {
|
|
model.load()
|
|
}
|
|
}
|
|
}
|
|
|
|
val accept: (m: String) -> Unit =
|
|
{ m: String ->
|
|
scaffoldModel.update("确认${m}?", actionLabel = "确认") {
|
|
model.accept(
|
|
auditId = vo.audit.id
|
|
) {
|
|
model.load()
|
|
}
|
|
}
|
|
}
|
|
|
|
val doCheck: @Composable () -> Unit = {
|
|
val cause = ValidStringForm(
|
|
formDesc = "审核理由",
|
|
textLength = 20
|
|
)
|
|
val statusForm by cause.statusForm.observeAsState()
|
|
|
|
onConfirm = {
|
|
if (statusForm == FormStatus.Empty) {
|
|
scaffoldModel.update("${cause.formDesc}不能为空", actionLabel = "知道了")
|
|
} else {
|
|
check(true, cause)
|
|
}
|
|
}
|
|
onBack = {
|
|
if (statusForm == FormStatus.Empty) {
|
|
scaffoldModel.update("${cause.formDesc}不能为空", actionLabel = "知道了")
|
|
} else {
|
|
check(false, cause)
|
|
}
|
|
}
|
|
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.Center
|
|
) {
|
|
BaseTextField(
|
|
form = cause
|
|
)
|
|
}
|
|
}
|
|
|
|
when {
|
|
//初审记录,负责人为空 等待初审
|
|
vo.audit.nextAudit == null && vo.audit.manager == null -> {
|
|
if (it.duty == Duty.PamphaBhusal) {
|
|
confirmDesc = R.string.accept_btn
|
|
onConfirm = { accept("受理") }
|
|
}
|
|
first()
|
|
RowItem(key = R.string.first_approver_origin, value = "")
|
|
RowItem(key = R.string.first_result, value = "")
|
|
last()
|
|
RowItem(key = R.string.last_approver_origin, value = "")
|
|
RowItem(key = R.string.last_result, value = "")
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.audit_phases, value = "等待初审"
|
|
)
|
|
}
|
|
//初审记录,负责人不为空 初审受理
|
|
vo.audit.nextAudit == null && vo.audit.manager != null && vo.audit.result == null -> {
|
|
|
|
first()
|
|
if (it.duty == Duty.PamphaBhusal) {
|
|
confirmDesc = R.string.reported_btn
|
|
backDesc = R.string.reject_btn
|
|
|
|
doCheck()
|
|
} else {
|
|
RowItem(key = R.string.first_approver_origin, value = "")
|
|
}
|
|
RowItem(key = R.string.first_result, value = "")
|
|
last()
|
|
RowItem(key = R.string.last_approver_origin, value = "")
|
|
RowItem(key = R.string.last_result, value = "")
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.audit_phases, value = "初审受理"
|
|
)
|
|
}
|
|
//初审记录,审核通过(上报) 等待复审
|
|
vo.audit.nextAudit != null && vo.audit.nextAudit?.manager == null -> {
|
|
|
|
if (it.duty == Duty.Teacher) {
|
|
confirmDesc = R.string.recheck_btn
|
|
onConfirm = { accept("复审") }
|
|
}
|
|
first()
|
|
RowItem(key = R.string.first_approver_origin, value = vo.audit.cause)
|
|
RowItem(key = R.string.first_result, value = "通过")
|
|
last()
|
|
RowItem(key = R.string.last_approver_origin, value = "")
|
|
RowItem(key = R.string.last_result, value = "")
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.audit_phases, value = "等待复审"
|
|
)
|
|
}
|
|
//复审记录,审核结果为空 复审受理
|
|
vo.audit.nextAudit != null && vo.audit.nextAudit?.result == null -> {
|
|
first()
|
|
RowItem(key = R.string.first_approver_origin, value = vo.audit.cause)
|
|
RowItem(key = R.string.first_result, value = "通过")
|
|
last()
|
|
if (it.duty == Duty.Teacher) {
|
|
confirmDesc = R.string.allow_btn
|
|
backDesc = R.string.reject_btn
|
|
doCheck()
|
|
} else {
|
|
RowItem(key = R.string.last_approver_origin, value = "")
|
|
}
|
|
RowItem(key = R.string.last_result, value = "")
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.audit_phases, value = "复审受理"
|
|
)
|
|
}
|
|
else -> {
|
|
first()
|
|
RowItem(key = R.string.first_approver_origin, value = vo.audit.cause)
|
|
RowItem(
|
|
key = R.string.first_result, value = when (vo.audit.result) {
|
|
null -> ""
|
|
true -> "通过"
|
|
false -> "不通过"
|
|
}
|
|
)
|
|
last()
|
|
RowItem(
|
|
key = R.string.last_approver_origin,
|
|
value = vo.audit.nextAudit?.cause ?: ""
|
|
)
|
|
RowItem(
|
|
key = R.string.last_result, value = when (vo.audit.nextAudit?.result) {
|
|
null -> ""
|
|
true -> "通过"
|
|
false -> "不通过"
|
|
}
|
|
)
|
|
RowItem(
|
|
modifier = Modifier.height(BASE_HEIGHT),
|
|
key = R.string.audit_phases, value = "完成审核"
|
|
)
|
|
}
|
|
}
|
|
|
|
if (confirmDesc != null) {
|
|
BottomButton(
|
|
confirmDesc = confirmDesc,
|
|
backDesc = backDesc,
|
|
modifier = Modifier.fillMaxWidth(),
|
|
onBack = onBack
|
|
) {
|
|
onConfirm?.let { it() }
|
|
}
|
|
}
|
|
}
|
|
} |