parent
acb519df85
commit
a38dcf6587
@ -0,0 +1,53 @@ |
||||
package com.gyf.csams.association.model |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.viewModelScope |
||||
import com.google.gson.reflect.TypeToken |
||||
import com.gyf.csams.module.ApiResponse |
||||
import com.gyf.csams.module.AuditJoinVo |
||||
import com.gyf.csams.module.JoinAssociationVo |
||||
import com.gyf.csams.module.SearchExamVo |
||||
import com.gyf.lib.model.ScrollViewModel |
||||
import com.gyf.lib.util.* |
||||
import kotlinx.coroutines.launch |
||||
|
||||
class AuditJoinViewModel(application: Application) : |
||||
ScrollViewModel<JoinAssociationVo>(application = application) { |
||||
|
||||
fun load(associationId: Int) { |
||||
viewModelScope.launch { |
||||
HttpClient.post( |
||||
url = Api.buildUrl(AssociationApi.CheckJoin), |
||||
callback = HttpCallback<MutableList<JoinAssociationVo>>( |
||||
action = "查看入团申请记录", |
||||
onSuccess = { |
||||
it.body?.let { |
||||
_data.postValue(it) |
||||
} |
||||
}, |
||||
typeToken = object : |
||||
TypeToken<ApiResponse<MutableList<JoinAssociationVo>>>() {}.type |
||||
), jsonParam = |
||||
SearchExamVo(associationId = associationId, token = TokenManager.getToken()) |
||||
) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 审核结果 |
||||
* |
||||
* @param joinId |
||||
* @param result |
||||
*/ |
||||
fun audit(joinId: Int, result: Boolean, callback: (message: String) -> Unit) { |
||||
viewModelScope.launch { |
||||
HttpClient.post( |
||||
url = Api.buildUrl(AssociationApi.AuditJoin), |
||||
callback = HttpCallback<Boolean>(action = "审核入团申请", onSuccess = { |
||||
callback(it.message) |
||||
}, typeToken = object : TypeToken<ApiResponse<Boolean>>() {}.type), jsonParam = |
||||
AuditJoinVo(joinId = joinId, result = result, token = TokenManager.getToken()) |
||||
) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,133 @@ |
||||
package com.gyf.csams.association.ui |
||||
|
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import androidx.activity.ComponentActivity |
||||
import androidx.activity.compose.setContent |
||||
import androidx.compose.foundation.layout.* |
||||
import androidx.compose.foundation.lazy.LazyColumn |
||||
import androidx.compose.material.Card |
||||
import androidx.compose.material.OutlinedButton |
||||
import androidx.compose.material.Text |
||||
import androidx.compose.runtime.LaunchedEffect |
||||
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.unit.dp |
||||
import androidx.lifecycle.viewmodel.compose.viewModel |
||||
import com.gyf.csams.R |
||||
import com.gyf.csams.association.model.AuditJoinViewModel |
||||
import com.gyf.csams.association.model.ExamActivityType |
||||
import com.gyf.lib.uikit.Body |
||||
import com.gyf.lib.uikit.MainColumnFrame |
||||
import com.gyf.lib.uikit.ScaffoldModel |
||||
import com.gyf.lib.util.BottomButton |
||||
import com.gyf.lib.util.DateTimeUtil.datetimeFormat |
||||
import java.util.* |
||||
|
||||
/** |
||||
* 审核入团申请 |
||||
* |
||||
*/ |
||||
class AuditJoinActivity : ComponentActivity() { |
||||
|
||||
private val associationId: Int |
||||
get() { |
||||
val id = intent.getIntExtra( |
||||
AssociationActivity::class.java.name, |
||||
0 |
||||
) |
||||
return if (id == 0) throw IllegalArgumentException("社团id:${id}不合法,初始化失败") else id |
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
setContent { |
||||
Body { |
||||
MainColumnFrame(background = { }) { |
||||
val model: AuditJoinViewModel = viewModel() |
||||
val data by model.data.observeAsState() |
||||
val scaffoldModel: ScaffoldModel = viewModel() |
||||
LaunchedEffect(associationId) { |
||||
model.load(associationId = associationId) |
||||
} |
||||
LazyColumn( |
||||
verticalArrangement = Arrangement.spacedBy( |
||||
10.dp, |
||||
Alignment.CenterVertically |
||||
) |
||||
) { |
||||
data?.forEach { |
||||
item { |
||||
Card(elevation = 5.dp) { |
||||
Column( |
||||
modifier = Modifier.fillMaxWidth(), |
||||
horizontalAlignment = Alignment.CenterHorizontally |
||||
) { |
||||
Text(text = "申请人:${it.user.name}") |
||||
Text(text = "申请时间:${Date(it.applyTime).datetimeFormat()}") |
||||
if (it.hasPaper) { |
||||
Spacer(modifier = Modifier.height(5.dp)) |
||||
OutlinedButton(onClick = { |
||||
startActivity( |
||||
Intent( |
||||
this@AuditJoinActivity, |
||||
ExamActivity::class.java |
||||
).apply { |
||||
putExtra( |
||||
ExamActivityType::name.name, |
||||
ExamActivityType.Answer |
||||
) |
||||
putExtra( |
||||
AuditJoinActivity::class.java.name, |
||||
it.id |
||||
) |
||||
putExtra( |
||||
AssociationActivity::class.java.name, |
||||
it.associationVo.associationId |
||||
) |
||||
}) |
||||
}) { |
||||
Text(text = "查看申请答卷") |
||||
} |
||||
Spacer(modifier = Modifier.height(5.dp)) |
||||
} |
||||
when (val result = it.result) { |
||||
null -> BottomButton(confirmDesc = R.string.allow_btn, |
||||
backDesc = R.string.refuse_btn, |
||||
modifier = Modifier.fillMaxWidth(), |
||||
onBack = { |
||||
model.audit(joinId = it.id, result = false) { |
||||
scaffoldModel.update( |
||||
message = it, |
||||
actionLabel = "关闭提示" |
||||
) |
||||
model.load(associationId = associationId) |
||||
} |
||||
}, |
||||
onConfirm = { |
||||
model.audit(joinId = it.id, result = true) { |
||||
scaffoldModel.update( |
||||
message = it, |
||||
actionLabel = "关闭提示" |
||||
) |
||||
model.load(associationId = associationId) |
||||
} |
||||
}) |
||||
true, false -> { |
||||
Text("审核结果:${if (result) "通过" else "不通过"}") |
||||
Text("审核时间:${it.auditTime?.let { Date(it).datetimeFormat() }}") |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue