From cece79bf75a9b672b33b772acffca209eecfc8f2 Mon Sep 17 00:00:00 2001
From: zuoxiao <lf_zuo@163.com>
Date: 星期四, 26 六月 2025 08:27:25 +0800
Subject: [PATCH] refactor(generallibrary):优化补卡界面布局和样式- 调整了卡片信息展示区域的样式,包括背景色、文字颜色等 - 优化了输入区域的布局结构,减小了控件间距和尺寸- 更新了确认补卡按钮的样式 - 统一了文字大小和颜色,提高了可读性

---
 generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt |  217 +++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 174 insertions(+), 43 deletions(-)

diff --git a/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt b/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
index bd7b9f1..7658e5b 100644
--- a/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
+++ b/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
@@ -12,6 +12,7 @@
 import android.widget.Toast
 import androidx.appcompat.app.AppCompatActivity
 import com.dayu.baselibrary.net.subscribers.SubscriberListener
+import com.dayu.baselibrary.utils.MornyUtil
 import com.dayu.baselibrary.utils.ToastUtil
 import com.dayu.baselibrary.view.TitleBar
 import com.dayu.general.BaseApplication
@@ -22,6 +23,7 @@
 import com.dayu.general.bean.net.RechargeRequest
 import com.dayu.general.bean.net.RechargeResult
 import com.dayu.general.bean.card.UserCard
+import com.dayu.general.bean.net.PaymentMethodListResponse
 import com.dayu.general.databinding.ActivityRechargeDetailBinding
 import com.dayu.general.net.ApiManager
 import com.dayu.general.net.BaseResponse
@@ -37,7 +39,7 @@
 
     // 鏀粯鏂瑰紡鐩稿叧灞炴��
     private var paymentMethod: String = "鐜伴噾"
-    private var paymentId: Long = 0
+    private var paymentId: String = ""
     private var paymentMethodList: List<PaymentMethod> = listOf()
 
     companion object {
@@ -45,7 +47,12 @@
         private const val EXTRA_CARD_ADDRESS = "extra_card_address"
         private const val EXTRA_USER_CARD = "extra_user_card"
 
-        fun start(context: Context, cardInfo: CardInfoResult?, cardAddress: String?, userCard: UserCard?) {
+        fun start(
+            context: Context,
+            cardInfo: CardInfoResult?,
+            cardAddress: String?,
+            userCard: UserCard?
+        ) {
             val intent = Intent(context, RechargeDetailActivity::class.java)
             intent.putExtra(EXTRA_CARD_INFO, cardInfo)
             intent.putExtra(EXTRA_CARD_ADDRESS, cardAddress)
@@ -86,7 +93,7 @@
             // 澶勭悊鍏呭�奸�昏緫
             handleRecharge()
         }
-        
+
         // 璁剧疆閲戦杈撳叆闄愬埗
         setupAmountInputLimit(binding.rechargeMorny)
         setupAmountInputLimit(binding.rechargeWater)
@@ -98,13 +105,13 @@
     private fun setupAmountInputLimit(editText: EditText) {
         editText.addTextChangedListener(object : TextWatcher {
             override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
-            
+
             override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
-            
+
             override fun afterTextChanged(s: Editable?) {
                 val text = s.toString()
                 if (text.isEmpty()) return
-                
+
                 // 妫�鏌ユ槸鍚﹀寘鍚皬鏁扮偣
                 if (text.contains(".")) {
                     val parts = text.split(".")
@@ -120,7 +127,7 @@
                         }
                     }
                 }
-                
+
                 // 闃叉杈撳叆澶氫釜灏忔暟鐐�
                 val dotCount = text.count { it == '.' }
                 if (dotCount > 1) {
@@ -130,7 +137,7 @@
                     editText.setSelection(newText.length)
                     editText.addTextChangedListener(this)
                 }
-                
+
                 // 闃叉浠ュ皬鏁扮偣寮�澶�
                 if (text.startsWith(".")) {
                     editText.removeTextChangedListener(this)
@@ -143,23 +150,60 @@
     }
 
     /**
-     * 鑾峰彇鏀粯鏂瑰紡鍒楄〃
+     * 鑾峰彇鏀粯鏂瑰紡鍒楄〃 - 浣跨敤Object绫诲瀷瀹夊叏澶勭悊JSON鏁扮粍
      */
     private fun getPaymentMethods() {
         ApiManager.getInstance().requestGetLoading(
             this,
-            "sell/paymentmethod/get",
-            PaymentMethodResponse::class.java,
+            "terminal/paymentmethod/get",
+            Any::class.java,
             null,
-            object : SubscriberListener<BaseResponse<PaymentMethodResponse>>() {
-                override fun onNext(response: BaseResponse<PaymentMethodResponse>) {
+            object : SubscriberListener<BaseResponse<Any>>() {
+                override fun onNext(response: BaseResponse<Any>) {
                     if (response.success) {
-                        // 鑾峰彇鏀粯鏂瑰紡鍒楄〃
-                        val paymentMethods = response.content?.obj ?: listOf()
-                        if (paymentMethods.isNotEmpty()) {
-                            paymentMethodList = paymentMethods
-                            // 鏇存柊鏀粯鏂瑰紡鏄剧ず
-                            updatePaymentMethodRadioGroup()
+                        try {
+                            // 瀹夊叏鍦板鐞嗚繑鍥炵殑content锛屾湇鍔″櫒杩斿洖鐨勬槸ArrayList<LinkedHashMap>
+                            val paymentMethods = mutableListOf<PaymentMethod>()
+                            val content = response.content
+                            
+                            if (content is List<*>) {
+                                content.forEach { item ->
+                                    if (item is Map<*, *>) {
+                                        val id = item["id"]?.toString() ?: ""
+                                        val name = item["name"]?.toString() ?: ""
+                                        if (id.isNotEmpty() && name.isNotEmpty()) {
+                                            paymentMethods.add(PaymentMethod(id, name))
+                                        }
+                                    }
+                                }
+                            }
+                            
+                            if (paymentMethods.isNotEmpty()) {
+                                paymentMethodList = paymentMethods
+                                // 鏇存柊鏀粯鏂瑰紡鏄剧ず
+                                updatePaymentMethodRadioGroup()
+                                
+                                // 璋冭瘯鏃ュ織
+                                android.util.Log.d("RechargeDetail", "鎴愬姛鑾峰彇${paymentMethods.size}涓敮浠樻柟寮�:")
+                                paymentMethods.forEach { method ->
+                                    android.util.Log.d("RechargeDetail", "- ID: ${method.id}, Name: ${method.name}")
+                                }
+                            } else {
+                                Toast.makeText(
+                                    this@RechargeDetailActivity,
+                                    "鑾峰彇鏀粯鏂瑰紡澶辫触锛氳繑鍥炴暟鎹负绌�",
+                                    Toast.LENGTH_SHORT
+                                ).show()
+                            }
+                        } catch (e: Exception) {
+                            android.util.Log.e("RechargeDetail", "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触", e)
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁绫诲瀷: ${response.content?.javaClass?.name}")
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁鍐呭: $response.content")
+                            Toast.makeText(
+                                this@RechargeDetailActivity,
+                                "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触: ${e.message}",
+                                Toast.LENGTH_SHORT
+                            ).show()
                         }
                     } else {
                         Toast.makeText(
@@ -172,6 +216,7 @@
 
                 override fun onError(e: Throwable?) {
                     super.onError(e)
+                    android.util.Log.e("RechargeDetail", "缃戠粶璇锋眰澶辫触", e)
                     Toast.makeText(
                         this@RechargeDetailActivity,
                         "鑾峰彇鏀粯鏂瑰紡澶辫触: ${e?.message ?: "缃戠粶寮傚父"}",
@@ -249,9 +294,9 @@
             binding.redInitCode.text = cardAddress ?: ""
             binding.userName.text = info.userName ?: ""
             binding.redCardNum.text = info.cardNum ?: ""
-            
+
             // 浣跨敤鐢ㄦ埛鍗′腑鐨勪綑棰濇樉绀�
-            val balance = userCard?.let { 
+            val balance = userCard?.let {
                 // 灏嗗垎杞崲涓哄厓锛屼繚鐣欎袱浣嶅皬鏁�
                 String.format("%.2f", it.balance / 100.0)
             } ?: run {
@@ -261,7 +306,7 @@
             binding.redRemainderBlance.text = "$balance 鍏�"
 
             // 璁剧疆鍗$姸鎬佸拰瀵瑰簲棰滆壊
-            val cardStatus = when (info.status) {
+            val cardStatus = when (info.state) {
                 1 -> "姝e父"
                 2 -> "鎸傚け"
                 3 -> "閿佸畾"
@@ -271,7 +316,7 @@
             binding.redStatu.text = cardStatus
 
             // 鏍规嵁鍗$姸鎬佽缃笉鍚岄鑹�
-            val statusColor = when (info.status) {
+            val statusColor = when (info.state) {
                 1 -> android.graphics.Color.parseColor("#4CAF50") // 缁胯壊-姝e父
                 2 -> android.graphics.Color.parseColor("#FF9800") // 姗欒壊-鎸傚け
                 3 -> android.graphics.Color.parseColor("#F44336") // 绾㈣壊-閿佸畾
@@ -316,31 +361,62 @@
             0.0
         }
 
-        // 璋冪敤鍏呭�兼帴鍙�
-        callRechargeApi(rechargeAmount, bonusAmount)
+        // 鑾峰彇褰撳墠浣欓锛堣浆鎹负鍏冿級
+        val currentBalance = userCard?.let {
+            // 灏嗗垎杞崲涓哄厓
+            it.balance / 100.0
+        } ?: run {
+            // 濡傛灉鐢ㄦ埛鍗′负绌猴紝鍒欎娇鐢ㄦ湇鍔″櫒杩斿洖鐨勪綑棰�
+            cardInfo?.balance ?: 0.0
+        }
+
+        // 璁$畻鍏呭�煎悗鐨勬�讳綑棰�
+        val totalAmountAfterRecharge = currentBalance + rechargeAmount + bonusAmount
+
+        // 妫�鏌ユ槸鍚﹁秴杩囨渶澶т綑棰濋檺鍒�9999.99鍏�
+        if (totalAmountAfterRecharge > 9999.99) {
+            val maxRechargeAmount = 9999.99 - currentBalance
+            ToastUtil.show("鍏呭�煎け璐ワ細鍏呭�煎悗浣欓涓嶈兘瓒呰繃9999.99鍏僜n褰撳墠浣欓锛�${String.format("%.2f", currentBalance)}鍏僜n鏈�澶氬彲鍏呭�硷細${String.format("%.2f", maxRechargeAmount)}鍏�")
+            return
+        }
+
+        // 璋冪敤鍏呭�兼帴鍙o紝浼犻�掑綋鍓嶄綑棰�
+        callRechargeApi(currentBalance, rechargeAmount, bonusAmount)
     }
 
     /**
      * 璋冪敤鍏呭�兼帴鍙�
      */
-    private fun callRechargeApi(rechargeAmount: Double, bonusAmount: Double) {
+    private fun callRechargeApi(currentBalance: Double, rechargeAmount: Double, bonusAmount: Double) {
         val cardNum = cardInfo?.cardNum ?: cardAddress ?: ""
         if (cardNum.isEmpty()) {
             ToastUtil.show("鍗″彿淇℃伅缂哄け")
             return
         }
 
+        // 楠岃瘉鏀粯鏂瑰紡鏄惁宸查�夋嫨锛屽鏋滀负绌哄垯閲嶆柊鑾峰彇鏀粯鏂瑰紡
+        if (paymentId.isEmpty()) {
+            ToastUtil.show("鏀粯鏂瑰紡鏈姞杞斤紝姝e湪閲嶆柊鑾峰彇...")
+            // 閲嶆柊鑾峰彇鏀粯鏂瑰紡锛屾垚鍔熷悗鑷姩閲嶈瘯鍏呭��
+            getPaymentMethodsAndRetryRecharge(currentBalance, rechargeAmount, bonusAmount)
+            return
+        }
+
         // 鑾峰彇姘翠环锛堝鏋滀负绌轰細鑷姩瑙﹀彂MainActivity鑾峰彇锛�
         val currentWaterPrice = BaseApplication.requestWaterPrice()
 
-        // 鏋勫缓鍏呭�艰姹傚弬鏁�
+        // 鎵撳嵃璋冭瘯淇℃伅
+        android.util.Log.d("RechargeDetail", "鍏呭�煎弬鏁� - paymentMethod: $paymentMethod, paymentId: $paymentId")
+        android.util.Log.d("RechargeDetail", "瀛楁鍚箟 - money(褰撳墠浣欓): ${String.format("%.2f", currentBalance)}鍏�, amount(鍏呭�奸噾棰�): ${String.format("%.2f", rechargeAmount)}鍏�, gift(璧犻�侀噾棰�): ${String.format("%.2f", bonusAmount)}鍏�")
+
+        // 鏋勫缓鍏呭�艰姹傚弬鏁� - 淇瀛楁鍚箟
         val rechargeRequest = RechargeRequest(
             rechargeType = 2,
             cardNum = cardNum,
-            money = String.format("%.0f", rechargeAmount),
-            amount = String.format("%.0f", bonusAmount),
-            gift = String.format("%.0f", bonusAmount),
-            paymentId = paymentId.toString(),
+            money = String.format("%.2f", currentBalance), // money涓哄綋鍓嶅崱浣欓
+            amount = String.format("%.2f", rechargeAmount), // amount涓哄厖鍊奸噾棰�
+            gift = String.format("%.2f", bonusAmount), // gift涓鸿禒閫侀噾棰�
+            paymentId = paymentId,
             price = String.format("%.2f", currentWaterPrice), // 浣跨敤缁熶竴鑾峰彇鐨勬按浠�
             remarks = "鍏呭��",
             operator = BaseApplication.userId // 榛樿鎿嶄綔鍛業D锛屽彲浠ユ牴鎹疄闄呮儏鍐佃皟鏁�
@@ -387,27 +463,82 @@
     }
 
     /**
+     * 閲嶆柊鑾峰彇鏀粯鏂瑰紡骞堕噸璇曞厖鍊�
+     */
+    private fun getPaymentMethodsAndRetryRecharge(currentBalance: Double, rechargeAmount: Double, bonusAmount: Double) {
+        ApiManager.getInstance().requestGetLoading(
+            this,
+            "terminal/paymentmethod/get",
+            Any::class.java,
+            null,
+            object : SubscriberListener<BaseResponse<Any>>() {
+                override fun onNext(response: BaseResponse<Any>) {
+                    if (response.success) {
+                        try {
+                            // 瀹夊叏鍦板鐞嗚繑鍥炵殑content锛屾湇鍔″櫒杩斿洖鐨勬槸ArrayList<LinkedHashMap>
+                            val paymentMethods = mutableListOf<PaymentMethod>()
+                            val content = response.content
+                            
+                            if (content is List<*>) {
+                                content.forEach { item ->
+                                    if (item is Map<*, *>) {
+                                        val id = item["id"]?.toString() ?: ""
+                                        val name = item["name"]?.toString() ?: ""
+                                        if (id.isNotEmpty() && name.isNotEmpty()) {
+                                            paymentMethods.add(PaymentMethod(id, name))
+                                        }
+                                    }
+                                }
+                            }
+                            
+                            if (paymentMethods.isNotEmpty()) {
+                                paymentMethodList = paymentMethods
+                                // 鏇存柊鏀粯鏂瑰紡鏄剧ず
+                                updatePaymentMethodRadioGroup()
+                                // 鏀粯鏂瑰紡鍔犺浇鎴愬姛鍚庯紝鑷姩閲嶈瘯鍏呭��
+                                ToastUtil.show("鏀粯鏂瑰紡鍔犺浇鎴愬姛锛屾鍦ㄩ噸璇曞厖鍊�...")
+                                callRechargeApi(currentBalance, rechargeAmount, bonusAmount)
+                            } else {
+                                ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触锛氳繑鍥炴暟鎹负绌�")
+                            }
+                        } catch (e: Exception) {
+                            android.util.Log.e("RechargeDetail", "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触", e)
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁绫诲瀷: ${response.content?.javaClass?.name}")
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁鍐呭: ${response.content}")
+                            ToastUtil.show("瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触: ${e.message}")
+                        }
+                    } else {
+                        ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触: ${response.msg}")
+                    }
+                }
+
+                override fun onError(e: Throwable?) {
+                    super.onError(e)
+                    ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触: ${e?.message ?: "缃戠粶寮傚父"}")
+                }
+            }
+        )
+    }
+
+    /**
      * 鍚姩鍐欏崱鐣岄潰
      */
-    private fun startWriteCardActivity(rechargeResult: RechargeResult, rechargeAmount: Double, bonusAmount: Double) {
+    private fun startWriteCardActivity(
+        rechargeResult: RechargeResult,
+        rechargeAmount: Double,
+        bonusAmount: Double
+    ) {
         try {
             // 鍒涘缓UserCard瀵硅薄鐢ㄤ簬鍐欏崱
             val userCard = UserCard().apply {
                 // 璁剧疆鐢ㄦ埛鍗′俊鎭�
                 cardInfo?.let { info ->
-                    userCode = info.cardNum ?: ""
-                    
-                    // 璁$畻鏂颁綑棰濓細鍘熸湁浣欓 + 鍏呭�奸噾棰� + 璧犻�侀噾棰�
-                    val originalBalance = this@RechargeDetailActivity.userCard?.balance ?: 0 // 鍘熸湁浣欓锛堝垎锛�
-                    val rechargeAmountInCents = (rechargeAmount * 100).toInt() // 鍏呭�奸噾棰濊浆鍒�
-                    val bonusAmountInCents = (bonusAmount * 100).toInt() // 璧犻�侀噾棰濊浆鍒�
-                    
-                    balance = originalBalance + rechargeAmountInCents + bonusAmountInCents
+                    balance = MornyUtil.changeY2F(rechargeResult.balance)
                 }
-                
+
                 // 璁剧疆鍏朵粬蹇呰淇℃伅
                 projectCode = rechargeResult.projectNo
-                waterPrice = rechargeResult.waterPrice.toFloat()
+                waterPrice = MornyUtil.changeY2F(rechargeResult.waterPrice.toString())
                 rechargeDate = java.util.Calendar.getInstance()
             }
 
@@ -422,7 +553,7 @@
                 putExtra("bonusAmount", bonusAmount) // 浼犻�掕禒閫侀噾棰�
             }
             startActivity(intent)
-
+            finish()
         } catch (e: Exception) {
             ToastUtil.show("鍚姩鍐欏崱鐣岄潰澶辫触: ${e.message}")
         }

--
Gitblit v1.8.0