添加了界面及逻辑
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
package com.sw.platecabinet.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.platecabinet.databinding.FragmentUnbindPlateBinding
|
||||
import com.sw.platecabinet.ext.maskName
|
||||
import com.sw.platecabinet.ext.maskPhone
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 餐盘柜绑定
|
||||
@@ -12,8 +19,8 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
|
||||
FragmentUnbindPlateBinding::inflate
|
||||
) {
|
||||
internal val ARG_PARAM1 = "param1"
|
||||
private var param1: EquipmentUserInfo? = null
|
||||
private var info: EquipmentUserInfo? = null
|
||||
private val viewModel by viewModels<SettingViewModel>()
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@@ -31,15 +38,46 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
|
||||
info?.let {
|
||||
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||
binding.tvPlateNumberValue.text = it.plateNumber
|
||||
binding.tvNameValue.text = it.name
|
||||
binding.tvPhoneValue.text = it.phone
|
||||
binding.tvNameValue.text = it.name.maskName()
|
||||
binding.tvPhoneValue.text = it.phone.maskPhone()
|
||||
val timeInfo = DateTimeUtils.parseDateTime(it.updateTime)
|
||||
val timeAgo = DateTimeUtils.getTimeAgo(timeInfo)
|
||||
binding.tvUpdateTimeValue.text = timeAgo
|
||||
}
|
||||
}
|
||||
binding.llUnbind.setOnClickListener {
|
||||
if (info == null) return@setOnClickListener
|
||||
viewModel.unbindPlate(
|
||||
equipmentBoxCode = info!!.equipmentBoxCode!!,
|
||||
equipmentCode = info!!.equipmentCode!!
|
||||
)
|
||||
}
|
||||
binding.tvBack.setOnClickListener {
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerDataChange() {
|
||||
lifecycleScope.launch {
|
||||
viewModel.bindStateChange.collect {
|
||||
if (it.first == null) return@collect // 绑定状态过滤
|
||||
val errorInfo = it.second
|
||||
if (errorInfo.isSuccess()) {
|
||||
ToastUtils.showToast("解绑成功")
|
||||
activity?.finish()
|
||||
} else {
|
||||
ToastUtils.showToast(errorInfo.msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.showLoading.collect {
|
||||
if (it) {
|
||||
showWaitingDialog("")
|
||||
} else {
|
||||
hideWaitingDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user