| | |
| | | import android.text.TextWatcher |
| | | import android.view.View |
| | | import android.widget.Toast |
| | | import androidx.lifecycle.lifecycleScope |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener |
| | | import com.dayu.baselibrary.view.TitleBar.ClickType_LEFT_IMAGE |
| | | import com.dayu.general.BaseApplication |
| | | import com.dayu.general.R |
| | | import com.dayu.general.bean.db.CardRegistrationBean |
| | | import com.dayu.general.dao.BaseDaoSingleton |
| | | import com.dayu.general.databinding.ActivityNewCard1GeBinding |
| | | import com.dayu.general.net.ApiManager |
| | | import com.dayu.general.net.BaseResponse |
| | | import com.dayu.general.tool.NfcReadHelper |
| | | import kotlinx.coroutines.launch |
| | | |
| | | /** |
| | | * Description: 用户开卡界面 |
| | |
| | | object : SubscriberListener<BaseResponse<String>>() { |
| | | override fun onNext(response: BaseResponse<String>) { |
| | | if (response.success) { |
| | | // 激活成功 |
| | | Toast.makeText(this@NewCard2Activity, "开卡成功", Toast.LENGTH_SHORT).show() |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | // 保存开卡信息到数据库 |
| | | val cardRegistration = CardRegistrationBean( |
| | | cardNumber = cardPhysicalId, |
| | | userName = binding.newCardUserName.text.toString(), |
| | | idCard = binding.newCardIdCard.text.toString(), |
| | | farmerCode = binding.newCardFarmerCode.text.toString(), |
| | | cardFee = cardFee, |
| | | remark = binding.newCardRemark.text.toString(), |
| | | paymentMethod = paymentId, |
| | | isReported = true, |
| | | isCardWritten = true |
| | | ) |
| | | |
| | | // 使用协程在后台线程中保存数据 |
| | | lifecycleScope.launch { |
| | | try { |
| | | BaseDaoSingleton.getInstance(this@NewCard2Activity).cardRegistrationDao().insert(cardRegistration) |
| | | Toast.makeText(this@NewCard2Activity, "开卡成功", Toast.LENGTH_SHORT).show() |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | } catch (e: Exception) { |
| | | Toast.makeText(this@NewCard2Activity, "保存开卡信息失败: ${e.message}", Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | } else { |
| | | // 激活失败 |
| | | Toast.makeText( |
| | |
| | | binding.newCardArerNumber.text = cardNumber |
| | | // 隐藏NFC读卡界面 |
| | | binding.nfcContainer.visibility = View.GONE |
| | | |
| | | Toast.makeText(this, "读卡成功", Toast.LENGTH_SHORT).show() |
| | | binding.centerScroll.visibility = View.VISIBLE |
| | | binding.newCardRegistBtn.visibility = View.VISIBLE |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |