| | |
| | | package com.dayu.general.activity |
| | | |
| | | import android.os.Bundle |
| | | import android.widget.Toast |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener |
| | | import com.dayu.baselibrary.utils.ToastUtil |
| | | import com.dayu.baselibrary.view.TitleBar.ClickType_LEFT_IMAGE |
| | | import com.dayu.baselibrary.view.TitleBar.ClickType_RIGHT_IMAGE |
| | | import com.dayu.general.adapter.SearchListAdapter |
| | | import com.dayu.general.bean.net.SearchUserResult |
| | | import com.dayu.general.databinding.ActivitySearchUserGeBinding |
| | | import com.dayu.general.dialog.SearchDialog |
| | | import com.dayu.general.view.SearchDialog |
| | | import com.dayu.general.net.ApiManager |
| | | import com.dayu.general.net.BaseResponse |
| | | |
| | | /** |
| | | * @author: zuo |
| | |
| | | class SearchUserActivity : BaseActivity() { |
| | | |
| | | var binding: ActivitySearchUserGeBinding? = null |
| | | private var userAdapter: SearchListAdapter? = null |
| | | var searchDialog: SearchDialog? = null |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | | binding = ActivitySearchUserGeBinding.inflate(layoutInflater) |
| | | setContentView(binding?.root) |
| | | initView() |
| | | setupRecyclerView() |
| | | |
| | | } |
| | | |
| | | |
| | | fun initView() { |
| | | searchDialog = SearchDialog(this) |
| | | searchDialog?.show() |
| | | binding?.titleBar?.setOnItemclickListner(ClickType_LEFT_IMAGE) { this.finish() } |
| | | // 设置搜索监听器 |
| | | searchDialog?.setOnSearchListener(object : SearchDialog.OnSearchListener { |
| | | override fun onSearch(farmerId: String, farmerName: String, cardNumber: String) { |
| | | // 处理搜索结果 |
| | | // 这里只是示例,实际应用中可能需要调用API或查询数据库 |
| | | val message = |
| | | "搜索条件:\n农户编号:$farmerId\n农户名称:$farmerName\n卡号:$cardNumber" |
| | | // 执行实际的搜索逻辑 |
| | | searchUser(farmerId, farmerName, cardNumber) |
| | | } |
| | | }) |
| | | binding?.titleBar?.setOnItemclickListner(ClickType_RIGHT_IMAGE) { |
| | | // 创建搜索对话框 |
| | | val searchDialog = SearchDialog(this) |
| | | |
| | | // 设置搜索监听器 |
| | | searchDialog.setOnSearchListener(object : SearchDialog.OnSearchListener { |
| | | override fun onSearch(farmerId: String, farmerName: String, cardNumber: String) { |
| | | // 处理搜索结果 |
| | | // 这里只是示例,实际应用中可能需要调用API或查询数据库 |
| | | val message = |
| | | "搜索条件:\n农户编号:$farmerId\n农户名称:$farmerName\n卡号:$cardNumber" |
| | | // 执行实际的搜索逻辑 |
| | | performSearch(farmerId, farmerName, cardNumber) |
| | | } |
| | | }) |
| | | // 显示对话框 |
| | | searchDialog.show() |
| | | searchDialog?.show() |
| | | } |
| | | } |
| | | /** |
| | | * 执行搜索逻辑 |
| | | * 这里只是一个示例方法,实际应用中需要根据具体需求实现 |
| | | */ |
| | | private fun performSearch(farmerId: String, farmerName: String, cardNumber: String) { |
| | | // 这里可以实现实际的搜索逻辑 |
| | | // 例如:调用API、查询数据库等 |
| | | |
| | | // 示例:构建搜索条件 |
| | | val searchConditions = mutableMapOf<String, String>() |
| | | private fun setupRecyclerView() { |
| | | userAdapter = SearchListAdapter() |
| | | binding?.recyclerView?.apply { |
| | | layoutManager = LinearLayoutManager(this@SearchUserActivity) |
| | | adapter = userAdapter |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据农民ID、姓名和银行卡号搜索用户 |
| | | * |
| | | * 此函数构建一个参数映射,根据提供的农民ID、姓名和银行卡号来搜索用户 |
| | | * 它仅包含有效的、非空的搜索参数,以确保搜索请求的准确性和效率 |
| | | * |
| | | * @param farmerId 农民的唯一标识符 |
| | | * @param farmerName 农民的姓名 |
| | | * @param cardNumber 银行卡号 |
| | | */ |
| | | private fun searchUser(farmerId: String, farmerName: String, cardNumber: String) { |
| | | val map = mutableMapOf<String, Any>() |
| | | |
| | | if (farmerId.isNotEmpty()) { |
| | | searchConditions["farmerId"] = farmerId |
| | | map["farmerId"] = farmerId |
| | | } |
| | | |
| | | if (farmerName.isNotEmpty()) { |
| | | searchConditions["farmerName"] = farmerName |
| | | map["farmerName"] = farmerName |
| | | } |
| | | |
| | | if (cardNumber.isNotEmpty()) { |
| | | searchConditions["cardNumber"] = cardNumber |
| | | map["cardNumber"] = cardNumber |
| | | } |
| | | |
| | | // 根据搜索条件执行搜索 |
| | | // 实际应用中,这里可能是网络请求或数据库查询 |
| | | // searchRepository.search(searchConditions) |
| | | // 使用正确的类型参数 |
| | | ApiManager.getInstance().requestGetLoading( |
| | | this, |
| | | "sell/client/get", |
| | | SearchUserResult::class.java, |
| | | map, |
| | | object : SubscriberListener<BaseResponse<SearchUserResult>>() { |
| | | override fun onNext(t: BaseResponse<SearchUserResult>) { |
| | | if (t.success) { |
| | | // 处理搜索成功的情况 |
| | | val result = t.content |
| | | if (result != null) { |
| | | // 处理搜索结果 |
| | | if (result.obj.isNotEmpty()) { |
| | | userAdapter?.setData(result.obj) |
| | | } else { |
| | | ToastUtil.show("未找到匹配的用户") |
| | | } |
| | | } else { |
| | | ToastUtil.show("未找到匹配的用户") |
| | | } |
| | | } else { |
| | | // 处理搜索失败的情况 |
| | | ToastUtil.show(t.msg) |
| | | } |
| | | } |
| | | |
| | | override fun onError(e: Throwable?) { |
| | | super.onError(e) |
| | | ToastUtil.show("搜索失败: ${e?.message ?: "未知错误"}") |
| | | } |
| | | } |
| | | ) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理搜索结果 |
| | | */ |
| | | |
| | | } |