18034727885
2026-06-26 253f680fb9666751e0f9a8e5e8f2f9e3eb1894e3
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.example.smart.ui.projectevent.frag
 
import android.content.Context
import android.text.TextUtils
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.basecore.base.BaseContextViewModel
import com.example.basecore.net.http.Result
import com.example.basecore.widget.LoadingLayout
import com.example.smart.reqeust.RetrofitClient
import com.example.smart.ui.projectevent.adapter.CAdapter
import com.example.smart.ui.exclude.adapter.HAdapter
import com.example.smart.ui.exclude.adapter.TreeBaseAdapter
import com.example.smart.ui.exclude.adapter.VAdapter
import com.example.smart.ui.projectevent.bean.ProjectEventBean
import com.example.smart.ui.projectevent.bean.SysProblemBean
import com.example.smart.ui.projectevent.bean.SystemTreeBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
 
 
class SystemViewModel : BaseContextViewModel() {
 
    private lateinit var adapterV: VAdapter
 
    private lateinit var adapterH: HAdapter
 
    private lateinit var adapterC: CAdapter
 
    private lateinit var taskId: String
    private val vList = ArrayList<SystemTreeBean>()
    private val hList = ArrayList<SystemTreeBean>()
    private val cList = ArrayList<ProjectEventBean>()
 
    private var loadView: LoadingLayout? = null
 
 
    fun bindData(
        context: Context,
        id :String,
        list: ArrayList<SystemTreeBean>,
        vListView: RecyclerView,
        hListView: RecyclerView,
        cListView: RecyclerView
    ) {
        vList.addAll(list)
        this.taskId = id
 
        adapterV = VAdapter(context, vList)
        vListView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        vListView.adapter = adapterV
        adapterV.setTreeClickEvent(object : TreeBaseAdapter.OnTreeClickEvent {
            override fun onClicked(pos: Int, path: String) {
                val childSixTrees = vList[adapterV.getSelectItem()].children[pos].children
                adapterH.notifyHChanged(childSixTrees)
                if (!childSixTrees.isNullOrEmpty()) {
                    callSystemPro(childSixTrees[0].path)
                }
            }
        })
 
        adapterH = HAdapter(context, hList)
        adapterH.setTreeClickEvent(object : TreeBaseAdapter.OnTreeClickEvent {
            override fun onClicked(pos: Int, path: String) {
                callSystemPro(path)
            }
        })
        hListView.layoutManager =
            LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
        hListView.adapter = adapterH
 
        val childFourTree = vList[adapterV.getSelectItem()].children[0]
        //一般来说横向层级不会为空
        if (vList.isEmpty() || childFourTree.children.isNullOrEmpty()) {
            val tree = SystemTreeBean()
            tree.isFilledSelf = true
            hList.add(tree)
        } else {
            adapterH.notifyHChanged(childFourTree.children)
            if (!childFourTree.children.isNullOrEmpty()) {
                callSystemPro(childFourTree.children[0].path)
            }
        }
 
 
        adapterC = CAdapter(context, cList)
        cListView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        cListView.adapter = adapterC
    }
 
    fun bindId(from: String, projectId: String, planId: String) {
        adapterC.bindId(from, projectId, planId)
    }
 
    /**
     * 具体问题列表
     */
    private fun callSystemPro(path: String) {
        loadView?.loadingData()
        if (TextUtils.isEmpty(path) || TextUtils.isEmpty(taskId)) {
            loadView?.loadEmpty()
            return
        }
        viewModelScope.launch(Dispatchers.Main) {
            val result = safeCall { callList(RetrofitClient.api.callSystemTreeList(path, taskId)) }
            if (result is Result.Success) {
                if (result.data.isEmpty()) {
                    loadView?.loadEmpty()
                    adapterC.notifyHChanged(result.data)
                    return@launch
                }
                loadView?.loadNull()
                adapterC.notifyHChanged(result.data)
            } else if (result is Result.Error) {
                loadView?.loadEmpty()
            }
        }
    }
 
 
    private fun generateNullProblemBean(): SysProblemBean {
        val bean = SysProblemBean()
        bean.isNullContent = true
        return bean
    }
 
    fun bindLoading(loadView: LoadingLayout) {
        this.loadView = loadView
    }
 
    override fun onCleared() {
        super.onCleared()
        this.loadView = null
    }
 
}