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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package com.example.smart.ui.plan
 
import android.text.TextUtils
import android.view.LayoutInflater
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.basecore.BaseBindingActivity
import com.example.basecore.util.SchemeUtils
import com.example.basecore.util.sysbar.StatusBarUtils
import com.example.basecore.widget.LoadingLayout
import com.example.smart.databinding.ActivityPlanDetailsBinding
import com.example.smart.ui.plan.data.CheckTaskBean
import com.example.smart.ui.plan.adapter.PlanDetailsAdapter
import com.example.smart.util.createItemScheme
import com.example.basecore.util.toast
import com.example.smart.ui.home.page.data.FeedItemInfo
import com.example.smart.ui.item.CreateMissionPopWindow
 
class PlanDetailsActivity : BaseBindingActivity() {
 
    private val binding by lazy { ActivityPlanDetailsBinding.inflate(LayoutInflater.from(mContext)) }
 
    private val viewModel: PlanViewModel by viewModels()
 
    private lateinit var mAdapter: PlanDetailsAdapter
 
    private val mDataList = ArrayList<CheckTaskBean>()
    override fun getRootView() = binding.root
 
    private var planId = ""
 
    private var clientId = ""
 
    private var isRequest = false
 
    override fun initView() {
        StatusBarUtils.transparentMode(this, true, isFullScreen = true)
        initPlanInfo()
 
        bindMenu()
 
        mAdapter = PlanDetailsAdapter(mContext, mDataList, planId)
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)
            adapter = mAdapter
        }
 
        binding.loadingLayout.bindEvent(object : LoadingLayout.LoadEvent {
            override fun onRetryLoad() {
                binding.loadingLayout.isVisible = false
                requestData()
            }
        })
    }
 
    private fun bindMenu() {
        binding.apply {
            // 新建项目
            menuItem1.setOnClickListener {
                menuLayout.close(false)
                SchemeUtils.openScheme(mContext, "$createItemScheme?client_id=$clientId&plan_id=$planId")
            }
 
            // 新建任务
            menuItem2.setOnClickListener {
                menuLayout.close(false)
                // 从 adapter 获取最新的数据
                val currentData = if (::mAdapter.isInitialized && mAdapter.data.isNotEmpty()) {
                    mAdapter.data
                } else {
                    mDataList
                }
                if (currentData.isEmpty()) {
                    toast("请先创建项目")
                    return@setOnClickListener
                }
                // 新建任务模式:mode=false,可以选择计划可用的项目
                val firstProject = currentData[0]
                val pop = CreateMissionPopWindow(
                    mContext, 
                    planId.toInt(), 
                    firstProject.project.id, 
                    {
                        requestData()
                    },
                    mode = false // 新建任务模式
                )
                pop.showPopupWindow()
            }
        }
    }
 
    /**
     * 初始化标题,日期,地址
     */
    private fun initPlanInfo() {
        intent.getBundleExtra("param")?.let {
 
            planId = it.getInt("plan_id").toString()
 
            val itemInfo = it.getSerializable("plan_item") as FeedItemInfo
            clientId = itemInfo.client.id.toString()
 
            binding.titleTv.text = itemInfo.planName
            binding.dateTv.text = itemInfo.createTime
            binding.entrustTv.text = itemInfo.client.name
        }
    }
 
    override fun onStart() {
        super.onStart()
        requestData()
    }
 
    private fun requestData() {
        if (isRequest) {
            return
        }
        isRequest = true
        if (TextUtils.isEmpty(planId)) {
            toast("请检查Plan_Id")
            return
        }
        viewModel.requestProjectData(Integer.valueOf(planId)) {
            isRequest = false
            binding.loadingLayout.isVisible = true
            binding.loadingLayout.loadError()
            mAdapter.clearData()
            mAdapter.notifyDataSetChanged()
        }
    }
 
    override fun bindDataObserver() {
        super.bindDataObserver()
 
        viewModel.projectBean.observe(this) {
            bindData(it)
        }
    }
 
    private fun bindData(data: List<CheckTaskBean>) {
        isRequest = false
 
        if (data.isNotEmpty()) {
            mAdapter.notifyData(data)
        } else {
            binding.loadingLayout.isVisible = true
            binding.loadingLayout.loadEmpty()
        }
    }
 
}