package com.example.smart.ui.exclude.fragment
|
|
import android.view.LayoutInflater
|
import androidx.fragment.app.viewModels
|
import com.example.basecore.util.LogUtils
|
import com.example.basecore.util.showCenterToast
|
import com.example.basecore.util.showOnlyToast
|
import com.example.smart.databinding.FragmentContentBinding
|
import com.example.smart.ui.exclude.ExcludeViewModel
|
import com.example.smart.ui.exclude.adapter.ContentAdapter
|
import com.example.smart.ui.exclude.bean.ByPassInfoBean
|
import com.example.smart.ui.exclude.bean.SelectArrayList
|
import com.example.smart.ui.home.BasePageFragment
|
import com.example.smart.ui.projectevent.bean.SystemTreeBean
|
import com.example.smart.widget.dialog.LoadingDialog
|
import com.google.android.material.tabs.TabLayoutMediator
|
|
|
/**
|
* @description:
|
*/
|
open class SystemByPassFragment(var viewModel: ExcludeViewModel, val isClose: Boolean) : BasePageFragment() {
|
|
val mSelectedItemList = SelectArrayList<String>()
|
|
var treeBean : List<SystemTreeBean> = emptyList()
|
|
var byPassInfoBean: ByPassInfoBean? = null
|
|
val loadingDialog: LoadingDialog by lazy { LoadingDialog(requireContext()) }
|
|
val binding by lazy {
|
FragmentContentBinding.inflate(LayoutInflater.from(context))
|
}
|
|
override fun initView() {
|
binding.submitTv.setOnClickListener {
|
if (isClose) {
|
mContext?.showOnlyToast("项目已关闭")
|
return@setOnClickListener
|
}
|
if (mSelectedItemList.isEmpty()) {
|
mContext?.showCenterToast("还没有选中条目,请选择...")
|
return@setOnClickListener
|
}
|
submitSelectItem()
|
}
|
}
|
|
open fun applyData(){
|
byPassInfoBean?.systemHierarchyPaths = mSelectedItemList
|
}
|
|
private fun submitSelectItem() {
|
if(byPassInfoBean == null) {
|
mContext?.showCenterToast("数据异常,请稍后再试...")
|
return
|
}
|
|
applyData()
|
|
loadingDialog.show()
|
|
viewModel.submit(byPassInfoBean!!) {
|
mContext?.showCenterToast("提交失败,请稍后再试...")
|
loadingDialog.dismiss()
|
}
|
}
|
|
override fun onBindObserver() {
|
super.onBindObserver()
|
|
viewModel.systemTreeBean.observe(this) {
|
LogUtils.e("s t = ${System.currentTimeMillis()}")
|
treeBean = it
|
onCreatePage()
|
}
|
|
viewModel.byPassInfoBean.observe(this) {
|
byPassInfoBean = it
|
if(it.systemHierarchyPaths!=null && it.systemHierarchyPaths.isNotEmpty()) {
|
mSelectedItemList.addAll(it.systemHierarchyPaths)
|
onCreatePage()
|
}
|
}
|
|
viewModel.submitResult.observe(this) {
|
mContext?.showCenterToast("提交成功")
|
loadingDialog.dismiss()
|
}
|
}
|
|
open fun onCreatePage() {
|
val contentAdapter = ContentAdapter(mContext!!, treeBean, viewModel.taskId, mSelectedItemList)
|
binding.viewPager.adapter = contentAdapter
|
|
binding.run {
|
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
|
tab.text = treeBean[position].name
|
}.attach()
|
}
|
}
|
|
override fun initData() {
|
viewModel.callSystemTree() {}
|
}
|
|
companion object {
|
fun newInstance(viewModel: ExcludeViewModel, isClose: Boolean): SystemByPassFragment {
|
return SystemByPassFragment(viewModel, isClose)
|
}
|
}
|
|
override fun getRootView() = binding.root
|
|
|
}
|