admin
2021-05-14 1b4b3fed2569ac21ad6feb0a3a2c051175e7c36e
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
package com.tejia.lijin.app.ui.mine;
 
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
 
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.util.KeFuUtil;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
 
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.HashMap;
 
/**
 * 免单详情页面
 */
public class FreeChargeDetailsActivity extends BaseActivity implements View.OnClickListener {
    private ImageView iv_top_bar_right;//联系客服
    private TextView tv_top_bar_middle;//标题
    private TextView tv_top_bar_left;//返回
 
    private ScrollView help_center_scrollview;
 
    private ImageView help_center_progressimg;//状态 圆形图标
    private TextView help_center_progressMsg;//状态描述
    private ImageView help_center_progressimg1;
    private ImageView help_center_progressimg2;
    private ImageView help_center_progressimg3;
    private ImageView help_center_progressimg4;
    private TextView help_center_fanMoney;//返利金额
    private TextView help_center_receive;//商品收货
    private TextView help_center_account;//返利到账
    private TextView help_center_finish;//免单成功
 
    private ListView help_center_listview;//共工订单详情
    private TextView help_center_ordernumber;//订单号
    private TextView help_center_ordernumbercopy;//复制订单号
 
    private TextView help_center_fanMoney1;//返利金额显示
    private TextView help_center_fanMoney2;//返利金额显示状态
 
    private TextView help_center_regulationtitle;//备注
    private TextView help_center_regulationcontent;//备注详情
 
    private String ordernumber = "";//订单号
 
    private ArrayList<HashMap<String, String>> mlist = new ArrayList<>();//共工订单详情
    private FreeChargeDetailsAdapter adapter;
    private FreeChargeDetailsActivity mContext;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_freechargedetails);
 
        iv_top_bar_right = findViewById(R.id.iv_top_bar_right);
        tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
        tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
 
        help_center_scrollview = findViewById(R.id.help_center_scrollview);
 
        help_center_progressimg = findViewById(R.id.help_center_progressimg);
        help_center_progressMsg = findViewById(R.id.help_center_progressMsg);
        help_center_progressimg1 = findViewById(R.id.help_center_progressimg1);
        help_center_progressimg2 = findViewById(R.id.help_center_progressimg2);
        help_center_progressimg3 = findViewById(R.id.help_center_progressimg3);
        help_center_progressimg4 = findViewById(R.id.help_center_progressimg4);
        help_center_fanMoney = findViewById(R.id.help_center_fanMoney);
        help_center_receive = findViewById(R.id.help_center_receive);
        help_center_account = findViewById(R.id.help_center_account);
        help_center_finish = findViewById(R.id.help_center_finish);
 
        help_center_listview = findViewById(R.id.help_center_listview);
        help_center_ordernumber = findViewById(R.id.help_center_ordernumber);
        help_center_ordernumbercopy = findViewById(R.id.help_center_ordernumbercopy);
 
        help_center_fanMoney1 = findViewById(R.id.help_center_fanMoney1);
        help_center_fanMoney2 = findViewById(R.id.help_center_fanMoney2);
 
        help_center_regulationtitle = findViewById(R.id.help_center_regulationtitle);
        help_center_regulationcontent = findViewById(R.id.help_center_regulationcontent);
        iv_top_bar_right.setVisibility(View.VISIBLE);
        iv_top_bar_right.setOnClickListener(this);
        tv_top_bar_left.setOnClickListener(this);
        iv_top_bar_right.setImageDrawable(getResources().getDrawable(R.mipmap.ic_ticket_state_contact_kefu));
        tv_top_bar_middle.setText("免单详情");
        help_center_ordernumbercopy.setOnClickListener(this);
        mContext = this;
 
        getFreeCounponRecord("279953933778047109");//获取订单详情
        adapter = new FreeChargeDetailsAdapter(mContext, mlist);
        help_center_listview.setAdapter(adapter);
 
        //更改状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            int result = 0;
            int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = getResources().getDimensionPixelSize(resourceId);
            }
            //设置状态栏文字颜色及图标为深色
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, result);
            findViewById(R.id.v_status_bar).setLayoutParams(params);
        } else {
            findViewById(R.id.v_status_bar).setVisibility(View.GONE);
        }
    }
 
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_top_bar_right://联系客服
//                startActivity(new Intent(iv_top_bar_right.getContext(), ContactUsActivity.class));
               KeFuUtil.jumpKeFu(this, "免单详情");
                break;
            case R.id.tv_top_bar_left://返回
                finish();
                break;
            case R.id.help_center_ordernumbercopy:
                if (!ordernumber.isEmpty()) {
                    //获取剪贴板管理器:
                    ClipboardUtil.copy(getApplicationContext(),ordernumber);
                    Toast.makeText(getApplication(), "复制成功", Toast.LENGTH_SHORT).show();
                }
 
                break;
            default:
 
                break;
 
        }
 
    }
 
 
    //获取订单详情
    //orderNo 订单号
    private void getFreeCounponRecord(String orderNo) {
        ShoppingApi.getFreeCounponRecord(this, orderNo, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    JSONObject frreCouponRecord = data.optJSONObject("frreCouponRecord");//免单券订单进度详情
 
                    //备注
                    String help_center_regulationtitletxt = frreCouponRecord.optJSONObject("remark").optString("title");
                    String help_center_regulationcontenttxt = frreCouponRecord.optJSONObject("remark").optString("content");
                    help_center_regulationtitle.setText(help_center_regulationtitletxt);//备注标题
                    help_center_regulationcontent.setText(help_center_regulationcontenttxt);//备注详情
 
                    //顶部进度状态
                    int progressState = frreCouponRecord.optInt("progressState");
                    //   progressMsg顶部进度描述 progressList顶部进度详细描述
                    progressState(progressState, frreCouponRecord.optJSONObject("progressMsg"), frreCouponRecord.optJSONArray("progressList"));
                    //订单号
                    ordernumber = frreCouponRecord.optJSONObject("commonOrder").optString("orderNo");
                    help_center_ordernumber.setText("订单号:" + ordernumber);
                    //实际付款&返利
                    help_center_fanMoney.setText(frreCouponRecord.optJSONObject("payMoney").optString("content") + "\n" + frreCouponRecord.optJSONObject("fanMoney").optString("content"));
                    //返利金额显示
                    help_center_fanMoney1.setText(frreCouponRecord.optJSONObject("payMoney").optString("content"));
                    //返利金额显示状态
                    help_center_fanMoney2.setText(frreCouponRecord.optString("couponMoneyState"));
 
                    //取出listview 数据
                    JSONArray jsarr = frreCouponRecord.optJSONObject("commonOrder").optJSONArray("listOrderGoods");
                    for (int i = 0; i < jsarr.length(); i++) {
                        JSONObject jsonObject1 = jsarr.optJSONObject(i);
                        HashMap<String, String> map = new HashMap<>();
                        map.put("actualCount", jsonObject1.optString("actualCount"));
                        map.put("actualPay", jsonObject1.optString("actualPay"));
                        map.put("goodsId", jsonObject1.optString("goodsId"));
                        map.put("picture", jsonObject1.optString("picture"));
                        map.put("title", jsonObject1.optString("title"));
                        mlist.add(map);
                    }
 
                    adapter.notifyDataSetChanged();
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }
 
    /**
     * 顶部进度状态
     *
     * @param progressState 进度状态: 1等待中 2失败  3成功
     * @param progressMsg   顶部进度描述
     * @param progressList  进度状态详情
     */
    private void progressState(int progressState, JSONObject progressMsg, JSONArray progressList) {
        String progressMsgtxt = progressMsg.optString("content");
        help_center_progressMsg.setText(progressMsgtxt);//顶部描述
        switch (progressState) {
            case 1:
                help_center_progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_ticket_state_ongoing));//等待中
                help_center_progressMsg.setTextColor(getResources().getColor(R.color.gray3));//灰色
                break;
            case 2:
                help_center_progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_ticket_state_fatrue));//失败
                help_center_progressMsg.setTextColor(getResources().getColor(R.color.mine_red_bottom));//红色
                break;
            case 3:
                help_center_progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_ticket_state_success));//成功
                help_center_progressMsg.setTextColor(getResources().getColor(R.color.login_wechat_bg));//绿色
                break;
 
            default:
                break;
        }
        //循环 取出4个圆点的状态
        for (int i = 0; i < 4; i++) {
            JSONObject obj = progressList.optJSONObject(i);
            int state = obj.optInt("state");//小点状态
            JSONObject contentobj = obj.optJSONObject("text");
            String content = null;
            if (i != 0) {
                content = contentobj.optString("content");//小点描述
            }
            switch (i) {
                case 0://第一个小点 state小点颜色 help_center_progressimg1小点img content描述内容 help_center_receive描述内容控件
                    statedot(state, help_center_progressimg1, null, null);
                    break;
                case 1://第二个小点
                    statedot(state, help_center_progressimg2, content, help_center_receive);
                    break;
                case 2://第三个小点
                    statedot(state, help_center_progressimg3, content, help_center_account);
                    break;
                case 3://第四个小点
                    statedot(state, help_center_progressimg4, content, help_center_finish);
                    break;
                default:
                    break;
            }
        }
 
    }
 
    /**
     * "state":i // 1 灰色 2 红色 3 绿色
     * progressimg 原点控件
     * content 圆点描述
     * help_center_textview 描述控件
     */
    private void statedot(int i, ImageView progressimg, String content, TextView textview) {
        if (content != null && textview != null) {
            textview.setText(content);
        } else {
        }
        switch (i) {
            case 1:
                //改变圆点颜色 灰色
                progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_rate_of_advance_gray));
                break;
            case 2:
                //改变圆点颜色 红色
                progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_rate_of_advance_red));
                break;
            case 3:
                //改变圆点颜色 绿色
                progressimg.setImageDrawable(getResources().getDrawable(R.mipmap.ic_rate_of_advance_green));
                break;
        }
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
//        adapter.fullScrollClick(10002);//销毁引用
        mContext = null;
    }
 
 
    public void fullScrollClick(int postion) {
        if (postion == 1221) {
            help_center_scrollview.scrollTo(0, 0);
        }
    }
}