18034727885
2026-04-27 3a4c1bbb2cf4fb1cdda8a5061b0674f30e7456b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
 
 
}