admin
2021-06-11 ae4dc86b64bd8ef85bc832106741fb98e8d516da
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
package com.tejia.lijin.app.ui.mine;
 
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.wpc.library.util.common.DimenUtils;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.ui.BaseActivity;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.util.TopStatusSettings;
import com.tejia.lijin.app.util.user.UserUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import okhttp3.Call;
 
/**
 * Created by weikou2015 on 2018/1/18.
 * 资金
 */
 
public class UserOrderRewardStatisticActivity extends BaseActivity implements View.OnClickListener {
    TextView tv_left, tv_middle;
    private String TYPE = "money";
    private TextView tv_notice_content;
    private LinearLayout ll_notice;
    private ImageView iv_close, iv_top_bar_right1;
    private LinearLayout ll_money_data;
 
    private LinearLayout ll_list;
 
    private TextView tv_money_1, tv_name_1, tv_money_2, tv_name_2, tv_money_3, tv_name_3, tv_money_total, tv_name_total;
    private View view_cutline_2;
    private LinearLayout ll_3, ll_total;
    private String helpLink = null;
 
    int type;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_order_reward_statistic);
        TopStatusSettings.setStatusViewAndDeepColor(this);
        tv_left = findViewById(R.id.tv_top_bar_left);
        tv_middle = findViewById(R.id.tv_top_bar_middle);
        iv_top_bar_right1 = findViewById(R.id.iv_top_bar_right1);
        iv_top_bar_right1.setVisibility(View.VISIBLE);
 
        ll_list = findViewById(R.id.ll_list);
        tv_money_1 = findViewById(R.id.tv_money_1);
        tv_name_1 = findViewById(R.id.tv_name_1);
        tv_money_2 = findViewById(R.id.tv_money_2);
        tv_name_2 = findViewById(R.id.tv_name_2);
        tv_money_3 = findViewById(R.id.tv_money_3);
        tv_name_3 = findViewById(R.id.tv_name_3);
 
        tv_money_total = findViewById(R.id.tv_money_total);
        tv_name_total = findViewById(R.id.tv_name_total);
 
        view_cutline_2 = findViewById(R.id.view_cutline_2);
        ll_3 = findViewById(R.id.ll_3);
        ll_total = findViewById(R.id.ll_total);
        ll_money_data = findViewById(R.id.ll_money_data);
 
        type = Integer.parseInt(getIntent().getStringExtra("type"));
        if (type == 1) {
            tv_middle.setText("自购返利");
        } else if (type == 2) {
            tv_middle.setText("分享奖金");
        } else if (type == 3) {
            tv_middle.setText("团队收益");
        }
 
        iv_top_bar_right1.setOnClickListener(this);
        tv_left.setOnClickListener(this);
        init();
        getUserMoney();
    }
 
    private void init() {
        if (type == 3) {
            ll_total.setVisibility(View.VISIBLE);
            ll_3.setVisibility(View.VISIBLE);
            view_cutline_2.setVisibility(View.VISIBLE);
            tv_name_1.setText("累计团队奖金(元)");
            tv_name_2.setText("累计团队补贴(元)");
            tv_name_3.setText("累计团队分红(元)");
            ViewGroup.LayoutParams params = ll_money_data.getLayoutParams();
            params.height = DimenUtils.dip2px(getApplicationContext(), 60);
            ll_money_data.setLayoutParams(params);
        } else {
            ll_total.setVisibility(View.GONE);
            ll_3.setVisibility(View.GONE);
            view_cutline_2.setVisibility(View.GONE);
            tv_name_1.setText("累计已到账(元)");
            tv_name_2.setText("累计未到账(元)");
            ViewGroup.LayoutParams params = ll_money_data.getLayoutParams();
            params.height = DimenUtils.dip2px(this, 96);
            ll_money_data.setLayoutParams(params);
        }
    }
 
 
    @Override
    protected void onResume() {
        super.onResume();
    }
 
    /**
     * 用户资金统计
     */
    private void getUserMoney() {
        ShoppingApi.getCurrentBonus(getApplicationContext(), UserUtil.getUid(getApplicationContext()), type + "", new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                super.onSuccessPerfect(statusCode, headers, jsonObject);
                if (jsonObject.optInt("code") == 0) {
                    parseData(jsonObject.optJSONObject("data"));
                } else {
                    Toast.makeText(UserOrderRewardStatisticActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
            }
 
            @Override
            public void onFailure(Call call, IOException e) {
                super.onFailure(call, e);
                tv_left.post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(UserOrderRewardStatisticActivity.this, "网络连接出错", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
 
 
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_top_bar_left:
                finish();
                break;
            case R.id.iv_top_bar_right1:
                if (StringUtils.isEmpty(helpLink))
                    return;
                startActivity(new Intent(this, ShareBrowserActivity.class).putExtra("url", helpLink));
                break;
        }
    }
 
    private void parseData(JSONObject data) {
        helpLink = data.optString("link");
        if (type == 3) {
            setMoney(tv_money_total, data.optString("total"), 1.333f);
            setMoney(tv_money_1, data.optString("totalBonus"), 1.333f);
            setMoney(tv_money_2, data.optString("totalubsidy"), 1.333f);
            setMoney(tv_money_3, data.optString("totalDividend"), 1.333f);
 
            List<DateMoneyVO> voList = new ArrayList<>();
            JSONObject bonus = data.optJSONObject("bonus");//团队奖金
            DateMoneyVO vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日预估", bonus.optString("today")), new MoneyInfo("昨日预估", bonus.optString("yesterday")), new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队奖金(元)", R.drawable.shape_user_order_reward_statistic_blue_bottom, Color.parseColor("#DEF2FF"), R.drawable.shape_user_order_reward_statistic_blue);
            voList.add(vo);
 
            bonus = data.optJSONObject("subsidy");//补贴
            vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日预估", bonus.optString("today")), new MoneyInfo("昨日预估", bonus.optString("yesterday")), new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队补贴(元)", R.drawable.shape_user_order_reward_statistic_yellow_bottom, Color.parseColor("#FFF5E0"), R.drawable.shape_user_order_reward_statistic_yellow);
            voList.add(vo);
 
            bonus = data.optJSONObject("dividend");//分红
            vo = new DateMoneyVO(new DateMoney(null, null, new MoneyInfo("本月预估", bonus.optString("thisMonth")), new MoneyInfo("上月已到账", bonus.optString("lastMonth"))), "团队分红(元)", R.drawable.shape_user_order_reward_statistic_red_bottom, Color.parseColor("#FFF1F7"), R.drawable.shape_user_order_reward_statistic_red);
            voList.add(vo);
 
            setData(voList);
        } else {
            setMoney(tv_money_1, data.optString("total"), 1.333f);
            setMoney(tv_money_2, data.optString("totalNot"), 1.333f);
            List<DateMoneyVO> voList = new ArrayList<>();
            JSONObject bonus = data.optJSONObject("bonus");//已到账
            DateMoneyVO vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日", bonus.optString("today")), new MoneyInfo("昨日", bonus.optString("yesterday")), new MoneyInfo("本月", bonus.optString("thisMonth")), new MoneyInfo("上月", bonus.optString("lastMonth"))), "已到账(元)", R.drawable.shape_user_order_reward_statistic_red_bottom, Color.parseColor("#FFF1F7"), R.drawable.shape_user_order_reward_statistic_red);
            voList.add(vo);
            bonus = data.optJSONObject("bonusNot");//未到账
            vo = new DateMoneyVO(new DateMoney(new MoneyInfo("今日", bonus.optString("today")), new MoneyInfo("昨日", bonus.optString("yesterday")), new MoneyInfo("本月", bonus.optString("thisMonth")), new MoneyInfo("上月", bonus.optString("lastMonth"))), "已到账(元)", R.drawable.shape_user_order_reward_statistic_yellow_bottom, Color.parseColor("#FFF5E0"), R.drawable.shape_user_order_reward_statistic_yellow);
            voList.add(vo);
            setData(voList);
        }
    }
 
    private void setMoney(TextView tv, String money, float rate) {
        int start = 0;
        int end = money.length() - 1;
        if (money.indexOf(".") > -1) {
            end = money.indexOf(".");
        }
        Spannable span = new SpannableString(money);
        span.setSpan(new RelativeSizeSpan(rate), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(span);
    }
 
    private void setData(List<DateMoneyVO> voList) {
        LayoutInflater inflater = LayoutInflater.from(this);
        for (DateMoneyVO vo : voList) {
            View view = inflater.inflate(R.layout.item_user_order_reward_statistic, null);
            LinearLayout ll_content = view.findViewById(R.id.ll_content);
            LinearLayout ll_money = view.findViewById(R.id.ll_money);
            TextView tv_name = view.findViewById(R.id.tv_name);
            tv_name.setText(vo.getName());
            ll_content.setBackgroundResource(vo.getBackground());
            setItemData(ll_money, vo);
            ll_list.addView(view);
        }
    }
 
    private void setItemData(LinearLayout container, DateMoneyVO vo) {
        LayoutInflater inflater = LayoutInflater.from(this);
 
        List<MoneyInfo> moneyList = new ArrayList<>();
        if (vo.getDateMoney().getToday() != null)
            moneyList.add(vo.getDateMoney().getToday());
        if (vo.getDateMoney().getYesterday() != null)
            moneyList.add(vo.getDateMoney().getYesterday());
        if (vo.getDateMoney().getThisMonth() != null)
            moneyList.add(vo.getDateMoney().getThisMonth());
        if (vo.getDateMoney().getLastMonth() != null)
            moneyList.add(vo.getDateMoney().getLastMonth());
 
 
        for (int i = 0; i < moneyList.size(); i++) {
            View view = inflater.inflate(R.layout.item_user_order_reward_statistic_content, null);
            FrameLayout fl_content = view.findViewById(R.id.fl_content);
            TextView tv_date = view.findViewById(R.id.tv_date);
            TextView tv_money = view.findViewById(R.id.tv_money);
            setMoney(tv_money, moneyList.get(i).getMoney(), 1.25f);
            tv_date.setText(moneyList.get(i).getName());
 
            if (i == moneyList.size() - 1) {
                fl_content.setBackgroundResource(vo.getItemBackground());
            } else if (i % 2 == 0) {
                fl_content.setBackgroundColor(Color.WHITE);
            } else {
                fl_content.setBackgroundColor(vo.getEvenBackground());
            }
            container.addView(view);
        }
    }
 
 
    @Override
    protected void onPause() {
        super.onPause();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
 
 
    class MoneyInfo {
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
        public String getMoney() {
            return money;
        }
 
        public void setMoney(String money) {
            this.money = money;
        }
 
        public MoneyInfo(String name, String money) {
            this.name = name;
            this.money = money;
        }
 
        private String money;
        private String name;
    }
 
    class DateMoney {
        private MoneyInfo lastMonth;
        private MoneyInfo thisMonth;
        private MoneyInfo today;
 
        public DateMoney(MoneyInfo today, MoneyInfo yesterday, MoneyInfo thisMonth, MoneyInfo lastMonth) {
            this.lastMonth = lastMonth;
            this.thisMonth = thisMonth;
            this.today = today;
            this.yesterday = yesterday;
        }
 
        private MoneyInfo yesterday;
 
        public MoneyInfo getLastMonth() {
            return lastMonth;
        }
 
        public void setLastMonth(MoneyInfo lastMonth) {
            this.lastMonth = lastMonth;
        }
 
        public MoneyInfo getThisMonth() {
            return thisMonth;
        }
 
        public void setThisMonth(MoneyInfo thisMonth) {
            this.thisMonth = thisMonth;
        }
 
        public MoneyInfo getToday() {
            return today;
        }
 
        public void setToday(MoneyInfo today) {
            this.today = today;
        }
 
        public MoneyInfo getYesterday() {
            return yesterday;
        }
 
        public void setYesterday(MoneyInfo yesterday) {
            this.yesterday = yesterday;
        }
 
 
    }
 
 
    class DateMoneyVO {
        private DateMoney dateMoney;
        private String name;
        private int itemBackground;
        private int evenBackground;
 
        public DateMoneyVO(DateMoney dateMoney, String name, int itemBackground, int evenBackground, int background) {
            this.dateMoney = dateMoney;
            this.name = name;
            this.itemBackground = itemBackground;
            this.evenBackground = evenBackground;
            this.background = background;
        }
 
        private int background;
 
        public int getBackground() {
            return background;
        }
 
        public void setBackground(int background) {
            this.background = background;
        }
 
 
        public int getEvenBackground() {
            return evenBackground;
        }
 
        public void setEvenBackground(int evenBackground) {
            this.evenBackground = evenBackground;
        }
 
 
        public int getItemBackground() {
            return itemBackground;
        }
 
        public void setItemBackground(int itemBackground) {
            this.itemBackground = itemBackground;
        }
 
 
        public DateMoney getDateMoney() {
            return dateMoney;
        }
 
        public void setDateMoney(DateMoney dateMoney) {
            this.dateMoney = dateMoney;
        }
 
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
 
    }
}