左晓为主开发手持机充值管理机
zuoxiao
2024-08-21 6a5879320dfac43155d024814a0a4d794a612696
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
package com.dayu.qiheonlinelibrary.activity;
 
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
 
import com.dayu.baselibrary.utils.MornyUtil;
import com.dayu.qiheonlinelibrary.card.UserCard;
import com.dayu.qiheonlinelibrary.databinding.ActivityRechargeDetailQhlBinding;
import com.dayu.qiheonlinelibrary.dbBean.RechargeBean;
import com.dayu.qiheonlinelibrary.dbBean.UserCardBean;
import com.dayu.qiheonlinelibrary.utils.PrintUtils;
 
 
import java.util.Calendar;
 
/**
 * Created by Android Studio.
 * author: zuo
 * Date: 2023-11-21
 * Time: 15:01
 * 备注:写卡后的详情页
 */
public class RechargeDetailActivity extends BaseActivity {
 
    ActivityRechargeDetailQhlBinding binding;
    UserCard userCard;
    String statu;
    String morny;
    UserCardBean userCardBean;
    RechargeBean rechargeBean;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        binding = ActivityRechargeDetailQhlBinding.inflate(LayoutInflater.from(this));
        setContentView(binding.getRoot());
 
        try {
            if (getIntent().hasExtra("userCard")) {
                userCard = (UserCard) getIntent().getSerializableExtra("userCard");
            }
            if (getIntent().hasExtra("statu")) {
                statu = getIntent().getStringExtra("statu");
            }
            if (getIntent().hasExtra("rechargeBean")) {
                rechargeBean = (RechargeBean) getIntent().getSerializableExtra("rechargeBean");
            }
            if (getIntent().hasExtra("userCardBean")) {
                userCardBean = (UserCardBean) getIntent().getSerializableExtra("userCardBean");
            }
            setUserData(statu);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
 
    }
 
    private void setUserData(String statu) {
 
        if (rechargeBean != null) {
            binding.tip.setText("充值成功!");
            binding.redName.setText("姓名:" + rechargeBean.getUserName());
            binding.redRemainderMorny.setText("充值金额:" + rechargeBean.getMorny() + " 元");
            binding.redRechargeBalance.setText("剩余金额:" + rechargeBean.getBalance() + " 元");
            binding.redRechargeElectric.setText("充值电量:" + rechargeBean.getRechargeElectric() + " 度");
            binding.redSurplusElectric.setText("剩余电量:" + rechargeBean.getSurplusElectic() + " 度");
            binding.redInitCode.setText("卡号:" + rechargeBean.getCardNumber());
            binding.redUserCode.setText("用户编号:" + rechargeBean.getUserCode());
            if (MornyUtil.changeY2F(rechargeBean.getDeductionMorny()) > 0) {
                binding.redDeductionMorny.setText("补扣金额:" + rechargeBean.getDeductionMorny());
            } else {
                binding.redDeductionMorny.setVisibility(View.GONE);
            }
            binding.readBtn.setVisibility(View.VISIBLE);
            binding.readBtn.setOnClickListener(v -> {
                PrintUtils.printerData(rechargeBean);
            });
        } else {
            int balance = userCard.getBalance();
            binding.redName.setText("姓名:" + userCardBean.getUserName());
            binding.tip.setText("开卡成功!");
            binding.redInitCode.setText("卡号:" + userCardBean.getCardNumber());
            binding.redUserCode.setText("用户编号:" + userCardBean.getUserCode());
            binding.redRemainderMorny.setVisibility(View.GONE);
            binding.redRechargeBalance.setVisibility(View.GONE);
            binding.redRechargeElectric.setVisibility(View.GONE);
            binding.redSurplusElectric.setVisibility(View.GONE);
            binding.redDeductionMorny.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(statu)) {
            binding.redStatu.setVisibility(View.GONE);
        } else {
            binding.redStatu.setText("卡状态:" + statu);
        }
        if (userCard != null) {
            Calendar calendar = userCard.getRechargeDate();
            if (calendar != null) {
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH); // 月份从0开始,所以需要加1
                int day = calendar.get(Calendar.DAY_OF_MONTH);
                binding.redRechargeDate.setText("本卡最后购水日期:" + year + month + day);
            } else {
                binding.redRechargeDate.setText("本卡最后购水日期:无");
            }
        }
    }
}