|  |  | 
 |  |  |  | 
 |  |  |     // 支付方式 | 
 |  |  |     private var paymentMethod: String = "现金" | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     // 支付方式ID | 
 |  |  |     private var paymentId: Long = 0 | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |     // 用户ID | 
 |  |  |     private var userId: String = "" | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     // 客户ID | 
 |  |  |     private var clientId: String = "" | 
 |  |  |  | 
 |  |  |     // 是否已读卡 | 
 |  |  |     private var isReadCard: Boolean = false | 
 |  |  |  | 
 |  |  |     companion object { | 
 |  |  |         private const val TAG = "NewCard2Activity" | 
 |  |  | 
 |  |  |         val pageSize: Any?, | 
 |  |  |         val pageTotal: Any? | 
 |  |  |     ) | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     // 用户信息数据类 | 
 |  |  |     data class ClientInfo( | 
 |  |  |         val clientId: String, | 
 |  |  | 
 |  |  |  | 
 |  |  |         // 获取传递的clientId参数 | 
 |  |  |         clientId = intent.getStringExtra("clientId") ?: "" | 
 |  |  |          | 
 |  |  |  | 
 |  |  |         initView() | 
 |  |  |          | 
 |  |  |  | 
 |  |  |         // 如果有clientId,获取客户信息 | 
 |  |  |         if (clientId.isNotEmpty()) { | 
 |  |  |             getClientInfo(clientId) | 
 |  |  |         } | 
 |  |  |          | 
 |  |  |  | 
 |  |  |         // 获取支付方式 | 
 |  |  |         getPaymentMethods() | 
 |  |  |         initListener() | 
 |  |  | 
 |  |  |         binding.newCardRechargeAmount.addTextChangedListener(createDecimalTextWatcher()) | 
 |  |  |         binding.newCardCardFee.addTextChangedListener(createDecimalTextWatcher()) | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取客户详细信息 | 
 |  |  |      */ | 
 |  |  | 
 |  |  |             } | 
 |  |  |         ) | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 显示客户信息到界面 | 
 |  |  |      */ | 
 |  |  |     private fun displayClientInfo(clientInfo: ClientInfo) { | 
 |  |  |         // 保存用户ID供后续使用 | 
 |  |  |         userId = clientInfo.clientId | 
 |  |  |          | 
 |  |  |  | 
 |  |  |         // 显示用户基本信息 | 
 |  |  |         binding.newCardUserName.text = clientInfo.name | 
 |  |  |         binding.newCardIdCard.text = if (clientInfo.idCard.isBlank()) "无" else clientInfo.idCard | 
 |  |  | 
 |  |  |                 resources.getDimensionPixelSize(R.dimen.dimen_40), | 
 |  |  |                 1.0f | 
 |  |  |             ) | 
 |  |  |              | 
 |  |  |  | 
 |  |  |             // 如果不是最后一个按钮,添加右边距 | 
 |  |  |             if (index < paymentMethodList.size - 1) { | 
 |  |  |                 (radioButton.layoutParams as android.widget.LinearLayout.LayoutParams).rightMargin =  | 
 |  |  |                 (radioButton.layoutParams as android.widget.LinearLayout.LayoutParams).rightMargin = | 
 |  |  |                     resources.getDimensionPixelSize(R.dimen.dimen_15) | 
 |  |  |             } | 
 |  |  |              | 
 |  |  |  | 
 |  |  |             radioButton.text = method.name | 
 |  |  |             radioButton.background = resources.getDrawable(R.drawable.radio_selector) | 
 |  |  |             radioButton.buttonDrawable = null | 
 |  |  |             radioButton.gravity = android.view.Gravity.CENTER | 
 |  |  |             radioButton.setTextColor(resources.getColorStateList(R.color.radio_button_text_color)) | 
 |  |  |             radioButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f) | 
 |  |  |              | 
 |  |  |  | 
 |  |  |             // 添加到RadioGroup | 
 |  |  |             binding.newCardPaymentMethod.addView(radioButton) | 
 |  |  |              | 
 |  |  |  | 
 |  |  |             // 默认选中第一个 | 
 |  |  |             if (index == 0) { | 
 |  |  |                 radioButton.isChecked = true | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     override fun onNfcBack(intent: Intent) { | 
 |  |  |         val cardNumber = NfcReadHelper.getInstance(intent, this).getCardNumberNoClose() | 
 |  |  |         if (cardNumber.isNotEmpty()) { | 
 |  |  |             try { | 
 |  |  |                 // 创建密钥列表的副本,避免ConcurrentModificationException | 
 |  |  |                 val keyList = ArrayList(NfcReadHelper.getInstance(intent, this).getKeyList()) | 
 |  |  |         if (!isReadCard) { | 
 |  |  |             val cardNumber = NfcReadHelper.getInstance(intent, this).getCardNumberNoClose() | 
 |  |  |             if (cardNumber.isNotEmpty()) { | 
 |  |  |                 try { | 
 |  |  |                     // 创建密钥列表的副本,避免ConcurrentModificationException | 
 |  |  |                     val keyList = ArrayList(NfcReadHelper.getInstance(intent, this).getKeyList()) | 
 |  |  |  | 
 |  |  |                 // 使用美化的加载动画来显示NFC操作的加载状态 | 
 |  |  |                 val nfcHelper = NfcWreatHelper.getInstance(intent, this) | 
 |  |  |                 nfcHelper.setLoadingView(binding.loadingContainer, binding.nfcProgressWheel) | 
 |  |  |                  | 
 |  |  |                 // 异步修改密码 | 
 |  |  |                 nfcHelper.changePSAsync(keyList, false, true) { success: Boolean, msg: String? -> | 
 |  |  |                     if (success) { | 
 |  |  |                         // 保存卡物理ID | 
 |  |  |                         cardPhysicalId = cardNumber | 
 |  |  |                         // 更新UI | 
 |  |  |                         binding.newCardArerNumber.text = cardNumber | 
 |  |  |                         // 隐藏NFC读卡界面 | 
 |  |  |                         binding.nfcContainer.visibility = View.GONE | 
 |  |  |                         binding.centerScroll.visibility = View.VISIBLE | 
 |  |  |                         binding.newCardRegistBtn.visibility = View.VISIBLE | 
 |  |  |                     } else { | 
 |  |  |                         // 密码修改失败,处理错误情况 | 
 |  |  |                         Toast.makeText( | 
 |  |  |                             this@NewCard2Activity, | 
 |  |  |                             "卡片初始化失败:$msg", | 
 |  |  |                             Toast.LENGTH_LONG | 
 |  |  |                         ).show() | 
 |  |  |                     // 使用美化的加载动画来显示NFC操作的加载状态 | 
 |  |  |                     val nfcHelper = NfcWreatHelper.getInstance(intent, this) | 
 |  |  |                     nfcHelper.setLoadingView(binding.loadingContainer, binding.nfcProgressWheel) | 
 |  |  |  | 
 |  |  |                     // 异步修改密码 | 
 |  |  |                     nfcHelper.changePSAsync( | 
 |  |  |                         keyList, | 
 |  |  |                         false, | 
 |  |  |                         true | 
 |  |  |                     ) { success: Boolean, msg: String? -> | 
 |  |  |                         if (success) { | 
 |  |  |                             isReadCard = true | 
 |  |  |                             // 保存卡物理ID | 
 |  |  |                             cardPhysicalId = cardNumber | 
 |  |  |                             // 更新UI | 
 |  |  |                             binding.newCardArerNumber.text = cardNumber | 
 |  |  |                             // 隐藏NFC读卡界面 | 
 |  |  |                             binding.nfcContainer.visibility = View.GONE | 
 |  |  |                             binding.centerScroll.visibility = View.VISIBLE | 
 |  |  |                             binding.newCardRegistBtn.visibility = View.VISIBLE | 
 |  |  |                         } else { | 
 |  |  |                             // 密码修改失败,处理错误情况 | 
 |  |  |                             Toast.makeText( | 
 |  |  |                                 this@NewCard2Activity, | 
 |  |  |                                 "卡片初始化失败:$msg", | 
 |  |  |                                 Toast.LENGTH_LONG | 
 |  |  |                             ).show() | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } catch (e: Exception) { | 
 |  |  |                     // 处理异常情况 | 
 |  |  |                     CrashReport.postCatchedException(e) | 
 |  |  |                     e.printStackTrace() | 
 |  |  |                 } | 
 |  |  |             } catch (e: Exception) { | 
 |  |  |                 // 处理异常情况 | 
 |  |  |                 CrashReport.postCatchedException(e) | 
 |  |  |                 e.printStackTrace() | 
 |  |  |             } else { | 
 |  |  |                 Toast.makeText( | 
 |  |  |                     this@NewCard2Activity, | 
 |  |  |                     "获取卡号失败", | 
 |  |  |                     Toast.LENGTH_SHORT | 
 |  |  |                 ).show() | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             Toast.makeText( | 
 |  |  |                 this@NewCard2Activity, | 
 |  |  |                 "获取卡号失败", | 
 |  |  |                 "当前已读卡,不可再次读卡", | 
 |  |  |                 Toast.LENGTH_SHORT | 
 |  |  |             ).show() | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     override fun onDestroy() { |