浏览代码

取消退款开发完成

huyuguo 5 年之前
父节点
当前提交
f01378d053

+ 71 - 3
app/src/main/java/com/electric/chargingpile/activity/RefundListActivity.java

@ -1,24 +1,33 @@
1 1
package com.electric.chargingpile.activity;
2 2
3
import android.content.Intent;
3 4
import android.os.Bundle;
4 5
import android.support.v7.app.AppCompatActivity;
6
import android.util.Log;
5 7
import android.view.View;
6 8
import android.widget.ImageView;
7 9
import android.widget.LinearLayout;
8 10
import android.widget.ListView;
9 11
import android.widget.TextView;
12
import android.widget.Toast;
10 13
11 14
import com.blankj.utilcode.util.LogUtils;
12 15
import com.electric.chargingpile.R;
13 16
import com.electric.chargingpile.adapter.RefundAdapter;
14 17
import com.electric.chargingpile.application.MainApplication;
15 18
import com.electric.chargingpile.data.RefundData;
19
import com.electric.chargingpile.fragment.CancelRefundDialogFragment;
16 20
import com.electric.chargingpile.util.BarColorUtil;
21
import com.electric.chargingpile.util.CommonParams;
17 22
import com.electric.chargingpile.util.JsonUtils;
23
import com.electric.chargingpile.util.LoadingDialog;
24
import com.electric.chargingpile.util.ToastUtil;
18 25
import com.zhy.http.okhttp.OkHttpUtils;
19 26
import com.zhy.http.okhttp.callback.StringCallback;
20 27
21 28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.Map;
22 31
23 32
import okhttp3.Call;
24 33
@ -27,6 +36,7 @@ public class RefundListActivity extends AppCompatActivity implements View.OnClic
27 36
    private LinearLayout llList;
28 37
    private ListView lvRefund;
29 38
    private TextView tvEmpty;
39
    private LoadingDialog loadingDialog;
30 40
31 41
    @Override
32 42
    protected void onCreate(Bundle savedInstanceState) {
@ -36,9 +46,12 @@ public class RefundListActivity extends AppCompatActivity implements View.OnClic
36 46
37 47
        initViews();
38 48
        initEvent();
49
39 50
    }
40 51
41 52
    private void initViews() {
53
        loadingDialog = new LoadingDialog(this);
54
        loadingDialog.setCanceledOnTouchOutside(false);
42 55
        ivBack = (ImageView) findViewById(R.id.iv_back);
43 56
        llList = (LinearLayout) findViewById(R.id.ll_list);
44 57
        lvRefund = (ListView) findViewById(R.id.listview);
@ -50,24 +63,38 @@ public class RefundListActivity extends AppCompatActivity implements View.OnClic
50 63
    }
51 64
52 65
    private void getRefundData() {
66
        loadingDialog.show();
53 67
        String url = MainApplication.url + "/zhannew/basic/web/index.php/refund/list?phone="
54 68
                + MainApplication.userPhone + "&password=" + MainApplication.userPassword;
55 69
        OkHttpUtils.get().url(url).build().connTimeOut(6000).execute(new StringCallback() {
56 70
            @Override
57 71
            public void onError(Call call, Exception e) {
58
72
                loadingDialog.dismiss();
73
                ToastUtil.showToast(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT);
59 74
            }
60 75
61 76
            @Override
62 77
            public void onResponse(String response) {
63
                LogUtils.e(response);
78
                loadingDialog.dismiss();
64 79
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
65 80
                if ("01".equals(rtnCode)) {
66 81
                    String data = JsonUtils.getKeyResult(response, "data");
67 82
                    ArrayList<RefundData> list = (ArrayList<RefundData>) JsonUtils.parseToObjectList(data, RefundData.class);
68
                    LogUtils.e(list.size());
69 83
                    if (list.size() > 0) {
70 84
                        RefundAdapter refundAdapter = new RefundAdapter(list);
85
                        refundAdapter.setOnRefundAdapterListener(new RefundAdapter.OnRefundAdapterListener() {
86
                            @Override
87
                            public void refund(final RefundData refundData) {
88
                                CancelRefundDialogFragment cancelRefundDialogFragment = CancelRefundDialogFragment.newInstance();
89
                                cancelRefundDialogFragment.setOnReportParkingDialogFragmentListener(new CancelRefundDialogFragment.OnCancelRefundDialogFragmentListener() {
90
                                    @Override
91
                                    public void cancelRefund() {
92
                                        cancelRefundPost(refundData);
93
                                    }
94
                                });
95
                                cancelRefundDialogFragment.show(getFragmentManager(), "");
96
                            }
97
                        });
71 98
                        lvRefund.setAdapter(refundAdapter);
72 99
                        llList.setVisibility(View.VISIBLE);
73 100
                        tvEmpty.setVisibility(View.GONE);
@ -88,6 +115,14 @@ public class RefundListActivity extends AppCompatActivity implements View.OnClic
88 115
    }
89 116
90 117
    @Override
118
    protected void onDestroy() {
119
        if (loadingDialog != null) {
120
            loadingDialog.dismiss();
121
        }
122
        super.onDestroy();
123
    }
124
125
    @Override
91 126
    public void onClick(View view) {
92 127
        switch (view.getId()) {
93 128
            case R.id.iv_back:
@ -95,4 +130,37 @@ public class RefundListActivity extends AppCompatActivity implements View.OnClic
95 130
                break;
96 131
        }
97 132
    }
133
134
    private void cancelRefundPost(RefundData refundData) {
135
        loadingDialog.show();
136
        String url = MainApplication.url + "/zhannew/basic/web/index.php/refunds/cancel";
137
        final Map<String, String> map = new HashMap<>();
138
        map.put("phone", MainApplication.userPhone + "");
139
        map.put("password", MainApplication.userPassword + "");
140
        map.put("refund_id", refundData.getId() + "");
141
        CommonParams.addCommonParams(map);
142
        Log.d("xxxxxxxxxxxxxxx", "cancelRefundPost: " + map);
143
144
        OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
145
            @Override
146
            public void onError(Call call, Exception e) {
147
                loadingDialog.dismiss();
148
                ToastUtil.showToast(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT);
149
            }
150
151
            @Override
152
            public void onResponse(String response) {
153
                loadingDialog.dismiss();
154
                String code = JsonUtils.getKeyResult(response, "code");
155
                if ("200".equals(code)) {
156
                    getRefundData();
157
                    ToastUtil.showToast(getApplicationContext(), "取消退款成功", Toast.LENGTH_SHORT);
158
                } else {
159
                    String err = JsonUtils.getKeyResult(response, "err");
160
                    ToastUtil.showToast(getApplicationContext(), err, Toast.LENGTH_SHORT);
161
                }
162
            }
163
        });
164
    }
165
98 166
}

+ 28 - 4
app/src/main/java/com/electric/chargingpile/adapter/RefundAdapter.java

@ -4,6 +4,7 @@ import android.view.LayoutInflater;
4 4
import android.view.View;
5 5
import android.view.ViewGroup;
6 6
import android.widget.BaseAdapter;
7
import android.widget.Button;
7 8
import android.widget.TextView;
8 9
9 10
import com.electric.chargingpile.R;
@ -16,6 +17,7 @@ import java.util.ArrayList;
16 17
 */
17 18
public class RefundAdapter extends BaseAdapter {
18 19
    private ArrayList<RefundData> datas;
20
    private OnRefundAdapterListener refundAdapterListener;
19 21
20 22
21 23
    public RefundAdapter(ArrayList<RefundData> datas) {
@ -71,6 +73,7 @@ public class RefundAdapter extends BaseAdapter {
71 73
                    .findViewById(R.id.goods_time);
72 74
            holder.tv_Status = (TextView) convertView
73 75
                    .findViewById(R.id.goods_status);
76
            holder.cancel_refund = convertView.findViewById(R.id.cancel_refund);
74 77
        }
75 78
76 79
        if (holder != null && convertView != null) {
@ -78,13 +81,12 @@ public class RefundAdapter extends BaseAdapter {
78 81
        }
79 82
80 83
        {
81
            RefundData refundData = datas.get(position);
84
            final RefundData refundData = datas.get(position);
82 85
            holder.tv_Time.setText(refundData.getTime());
83 86
84 87
            if ("0.00".equals(refundData.getGive_money())) {
85
                holder.tv_coins.setVisibility(View.GONE);
88
                holder.tv_coins.setText("");
86 89
            } else {
87
                holder.tv_coins.setVisibility(View.VISIBLE);
88 90
                holder.tv_coins.setText("清空赠送金额:" + refundData.getGive_money() + "元");
89 91
            }
90 92
@ -92,21 +94,43 @@ public class RefundAdapter extends BaseAdapter {
92 94
            if (refundData.getSchedule().equals("0")) {
93 95
                holder.tv_Status.setText("退款中");
94 96
                holder.tv_Status.setTextColor(convertView.getResources().getColor(R.color.juhuang));
97
                holder.cancel_refund.setVisibility(View.VISIBLE);
95 98
            } else if (refundData.getSchedule().equals("2")) {
96 99
                holder.tv_Status.setText("已操作退款");
97 100
                holder.tv_Status.setTextColor(convertView.getResources().getColor(R.color.lvse));
101
                holder.cancel_refund.setVisibility(View.GONE);
98 102
            } else {
99
                holder.tv_Status.setText("退款失败\n" + refundData.getRemarks());
103
                holder.tv_Status.setText("退款失败\n" + refundData.getRemarks()); // TODO 确认
100 104
                holder.tv_Status.setTextColor(convertView.getResources().getColor(R.color.ui_fail_red));
105
                holder.cancel_refund.setVisibility(View.GONE);
101 106
            }
102 107
103 108
            holder.tv_Name.setText("退款金额:" + refundData.getRefund_money());
104 109
110
            holder.cancel_refund.setOnClickListener(new View.OnClickListener() {
111
                @Override
112
                public void onClick(View v) {
113
                    if (refundAdapterListener != null) {
114
                        refundAdapterListener.refund(refundData);
115
                    }
116
                }
117
            });
118
105 119
        }
106 120
        return convertView;
107 121
    }
108 122
109 123
    private class ViewHolder {
110 124
        TextView tv_Name, tv_coins, tv_Time, tv_Status;
125
        Button cancel_refund;
126
    }
127
128
129
    public interface OnRefundAdapterListener {
130
        void refund(RefundData refundData);
131
    }
132
133
    public void setOnRefundAdapterListener(OnRefundAdapterListener listener) {
134
        this.refundAdapterListener = listener;
111 135
    }
112 136
}

+ 2 - 2
app/src/main/java/com/electric/chargingpile/application/MainApplication.java

@ -75,8 +75,8 @@ public class MainApplication extends MultiDexApplication {
75 75
    public static String firstPoint = "";
76 76
    public static Boolean firstSsyd;
77 77
    public static String password = "";
78
    public static String url = "http://59.110.68.162";// 充电桩测试环境
79
    //    public static String url = "http://cdz.evcharge.cc";// 充电桩正式环境
78
//    public static String url = "http://59.110.68.162";// 充电桩测试环境
79
        public static String url = "http://cdz.evcharge.cc";// 充电桩正式环境
80 80
//    public static String urlNew = "http://123.56.67.7:83/api/0300";// 一电测试环境
81 81
    public static String urlNew = "https://api.touchev.com:83/api/0300";// 一电正式环境
82 82
    public static String pic_url = "http://cdz.evcharge.cc/zhannew/uploadfile/";

+ 87 - 0
app/src/main/java/com/electric/chargingpile/fragment/CancelRefundDialogFragment.java

@ -0,0 +1,87 @@
1
package com.electric.chargingpile.fragment;
2
3
import android.app.Dialog;
4
import android.app.DialogFragment;
5
import android.os.Bundle;
6
import android.support.annotation.NonNull;
7
import android.view.Gravity;
8
import android.view.View;
9
import android.view.Window;
10
import android.view.WindowManager;
11
import android.widget.Button;
12
13
import com.electric.chargingpile.R;
14
15
public class CancelRefundDialogFragment extends DialogFragment implements View.OnClickListener {
16
17
    private Dialog mDialog;
18
    private Button continue_refund;
19
    private Button cancel_refund;
20
    private OnCancelRefundDialogFragmentListener cancelRefundDialogFragmentListener;
21
22
    public static CancelRefundDialogFragment newInstance() {
23
        Bundle args = new Bundle();
24
//        args.putSerializable("type", type);
25
        CancelRefundDialogFragment fragment = new CancelRefundDialogFragment();
26
        fragment.setArguments(args);
27
        return fragment;
28
    }
29
30
    @NonNull
31
    @Override
32
    public Dialog onCreateDialog(Bundle savedInstanceState) {
33
        mDialog = new Dialog(getActivity(), R.style.CenterDialog);
34
        mDialog.setCancelable(true);
35
        mDialog.setCanceledOnTouchOutside(true);
36
37
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
38
        mDialog.setContentView(R.layout.fragment_dialog_cancel_refund);
39
40
        Window window = mDialog.getWindow();
41
        WindowManager.LayoutParams layoutParams = window.getAttributes();
42
        // 布局属性位于整个窗口底部
43
        layoutParams.gravity = Gravity.CENTER;
44
        // 布局属性宽度填充整个窗口,默认是有margin的
45
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
46
        window.setAttributes(layoutParams);
47
48
        initDialog();
49
        initListener();
50
51
        return mDialog;
52
    }
53
54
    private void initDialog() {
55
        continue_refund = mDialog.findViewById(R.id.continue_refund);
56
        cancel_refund = mDialog.findViewById(R.id.cancel_refund);
57
    }
58
59
    private void initListener() {
60
        continue_refund.setOnClickListener(this);
61
        cancel_refund.setOnClickListener(this);
62
    }
63
64
    @Override
65
    public void onClick(View v) {
66
        switch (v.getId()) {
67
            case R.id.continue_refund:
68
                mDialog.dismiss();
69
                break;
70
            case R.id.cancel_refund:
71
                if (cancelRefundDialogFragmentListener != null) {
72
                    cancelRefundDialogFragmentListener.cancelRefund();
73
                }
74
                mDialog.dismiss();
75
                break;
76
        }
77
    }
78
79
    public interface OnCancelRefundDialogFragmentListener {
80
        void cancelRefund();
81
    }
82
83
    public void setOnReportParkingDialogFragmentListener(OnCancelRefundDialogFragmentListener listener) {
84
        this.cancelRefundDialogFragmentListener = listener;
85
    }
86
87
}

+ 0 - 2
app/src/main/java/com/electric/chargingpile/fragment/ReportParkingDialogFragment.java

@ -1,8 +1,6 @@
1 1
package com.electric.chargingpile.fragment;
2 2
3 3
import android.app.Dialog;
4
import android.graphics.Color;
5
import android.media.Image;
6 4
import android.os.Bundle;
7 5
import android.support.constraint.ConstraintLayout;
8 6
import android.support.v4.app.DialogFragment;

+ 7 - 0
app/src/main/res/drawable/cancel_refund_alert_shape.xml

@ -0,0 +1,7 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3
    <!-- 背景色 -->
4
    <solid android:color="#ffffff"></solid>
5
    <!-- 边框圆角 -->
6
    <corners android:radius="4dp"></corners>
7
</shape>

+ 9 - 0
app/src/main/res/drawable/cancel_refund_btn_shape.xml

@ -0,0 +1,9 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3
    <!-- 背景色 -->
4
    <solid android:color="#ffffff"></solid>
5
    <!-- 边框颜色、宽度  -->
6
    <stroke android:width="1dip" android:color="#e8e8e8"></stroke>
7
    <!-- 边框圆角 -->
8
    <corners android:radius="15dp"></corners>
9
</shape>

+ 4 - 4
app/src/main/res/drawable/report_parking_shape.xml

@ -1,7 +1,7 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3
    <!-- 背景色 -->
4
    <solid android:color="#00B536"></solid>
5
    <!-- 边框圆角 -->
6
    <corners android:radius="4dp"></corners>
3
<!-- 背景色 -->
4
<solid android:color="#00B536"></solid>
5
<!-- 边框圆角 -->
6
<corners android:radius="4dp"></corners>
7 7
</shape>

+ 71 - 0
app/src/main/res/layout/fragment_dialog_cancel_refund.xml

@ -0,0 +1,71 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent"
6
    android:background="#a0000000">
7
8
9
    <android.support.constraint.ConstraintLayout
10
        android:layout_width="270dp"
11
        android:layout_height="143dp"
12
        android:background="@drawable/cancel_refund_alert_shape"
13
        app:layout_constraintBottom_toBottomOf="parent"
14
        app:layout_constraintLeft_toLeftOf="parent"
15
        app:layout_constraintRight_toRightOf="parent"
16
        app:layout_constraintTop_toTopOf="parent">
17
18
        <TextView
19
            android:id="@+id/title"
20
            android:layout_width="wrap_content"
21
            android:layout_height="wrap_content"
22
            android:layout_marginTop="20dp"
23
            android:text="取消退款"
24
            android:textColor="#444444"
25
            android:textSize="15sp"
26
            app:layout_constraintLeft_toLeftOf="parent"
27
            app:layout_constraintRight_toRightOf="parent"
28
            app:layout_constraintTop_toTopOf="parent" />
29
30
31
        <TextView
32
            android:layout_width="wrap_content"
33
            android:layout_height="wrap_content"
34
            android:layout_marginTop="15dp"
35
            android:text="取消退款后,可继续使用APP充电"
36
            android:textColor="#444444"
37
            android:textSize="13sp"
38
            app:layout_constraintLeft_toLeftOf="parent"
39
            app:layout_constraintRight_toRightOf="parent"
40
            app:layout_constraintTop_toBottomOf="@+id/title" />
41
42
        <LinearLayout
43
            android:layout_width="match_parent"
44
            android:layout_height="35dp"
45
            android:layout_marginBottom="20dp"
46
            android:gravity="center"
47
            app:layout_constraintBottom_toBottomOf="parent"
48
            app:layout_constraintLeft_toLeftOf="parent"
49
            app:layout_constraintRight_toRightOf="parent">
50
            <Button
51
                android:id="@+id/continue_refund"
52
                android:layout_width="100dp"
53
                android:layout_height="match_parent"
54
                android:background="@drawable/cancel_report_parking_shap"
55
                android:text="继续退款"
56
                android:textColor="#999999"
57
                android:textSize="13sp" />
58
59
            <Button
60
                android:id="@+id/cancel_refund"
61
                android:layout_width="100dp"
62
                android:layout_height="match_parent"
63
                android:layout_marginLeft="10dp"
64
                android:background="@drawable/report_parking_shape"
65
                android:text="取消退款"
66
                android:textColor="#ffffff"
67
                android:textSize="13sp" />
68
        </LinearLayout>
69
70
    </android.support.constraint.ConstraintLayout>
71
</android.support.constraint.ConstraintLayout>

+ 32 - 14
app/src/main/res/layout/layout_refund_list.xml

@ -1,19 +1,22 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
3 4
    xmlns:tools="http://schemas.android.com/tools"
4 5
    android:layout_width="match_parent"
5 6
    android:layout_height="wrap_content"
7
    android:paddingBottom="10dp"
6 8
    tools:background="#dbe0e3">
7 9
8 10
    <TextView
9 11
        android:id="@+id/goods_name"
10 12
        android:layout_width="wrap_content"
11 13
        android:layout_height="wrap_content"
12
        android:layout_alignParentLeft="true"
13 14
        android:layout_marginTop="12dp"
14 15
        android:text=""
15 16
        android:textColor="@color/ui_62"
16 17
        android:textSize="16sp"
18
        app:layout_constraintLeft_toLeftOf="parent"
19
        app:layout_constraintTop_toTopOf="parent"
17 20
        tools:text="退款金额:100.0" />
18 21
19 22
@ -21,15 +24,14 @@
21 24
        android:id="@+id/goods_coins"
22 25
        android:layout_width="wrap_content"
23 26
        android:layout_height="wrap_content"
24
        android:layout_alignTop="@+id/goods_name"
25
        android:layout_alignParentEnd="true"
26
        android:layout_alignParentRight="true"
27
        android:layout_marginEnd="16dp"
27
        android:layout_marginTop="14dp"
28 28
        android:layout_marginRight="16dp"
29 29
        android:gravity="right"
30
        android:text=""
30
        android:text="东方闪电"
31 31
        android:textColor="#b2b2b2"
32 32
        android:textSize="13sp"
33
        app:layout_constraintRight_toRightOf="parent"
34
        app:layout_constraintTop_toTopOf="parent"
33 35
        tools:text="赠送金额(38元)" />
34 36
35 37
@ -37,27 +39,43 @@
37 39
        android:id="@+id/goods_time"
38 40
        android:layout_width="wrap_content"
39 41
        android:layout_height="wrap_content"
40
        android:layout_below="@+id/goods_name"
41 42
        android:layout_marginTop="6dp"
42 43
        android:text=""
43 44
        android:textColor="@color/ui_68"
44 45
        android:textSize="13sp"
46
        app:layout_constraintLeft_toLeftOf="parent"
47
        app:layout_constraintTop_toBottomOf="@+id/goods_name"
45 48
        tools:text="2017-10-22 18:09" />
46 49
47 50
    <TextView
48 51
        android:id="@+id/goods_status"
49 52
        android:layout_width="wrap_content"
50 53
        android:layout_height="wrap_content"
51
        android:layout_alignTop="@+id/goods_time"
52
        android:layout_alignParentEnd="true"
53
        android:layout_alignParentRight="true"
54
        android:layout_marginEnd="16dp"
54
        android:layout_marginTop="7dp"
55 55
        android:layout_marginRight="16dp"
56
        android:layout_marginBottom="12dp"
57 56
        android:gravity="right"
58 57
        android:text=""
59 58
        android:textColor="@color/ui_65"
60 59
        android:textSize="13sp"
60
        app:layout_constraintRight_toRightOf="parent"
61
        app:layout_constraintTop_toBottomOf="@+id/goods_coins"
61 62
        tools:text="已操作退款" />
62 63
63
</RelativeLayout>
64
    <Button
65
        android:id="@+id/cancel_refund"
66
        android:layout_width="75dp"
67
        android:layout_height="30dp"
68
        android:layout_marginRight="16dp"
69
        android:background="@drawable/cancel_refund_btn_shape"
70
        android:text="取消退款"
71
        android:textColor="#888888"
72
        android:textSize="13sp"
73
        android:layout_marginTop="7dp"
74
        app:layout_constraintBottom_toBottomOf="parent"
75
        app:layout_constraintRight_toRightOf="parent"
76
        android:visibility="gone"
77
        tools:visibility="visible"
78
        app:layout_constraintTop_toBottomOf="@+id/goods_status" />
79
80
81
</android.support.constraint.ConstraintLayout>