package com.tejia.lijin.app.ui.mine;
|
|
import android.content.Intent;
|
import android.os.Bundle;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.entity.UserInfo;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
|
import com.tejia.lijin.app.util.TopStatusSettings;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
/**
|
* 订单统计
|
*/
|
public class OrderSatisticsActivity extends BaseActivity implements View.OnClickListener {
|
|
private TextView tv_left, tv_middle, tv_user_id, tv_all_order_form_num, tv_rebate_order_num,
|
tv_share_order_num, tv_invite_order_num;
|
//今天
|
private TextView tv_all_order_num_today, tv_rebate_order_num_today,
|
tv_share_order_num_today, tv_invite_order_num_today;
|
|
//昨天
|
private TextView tv_all_order_num_yestoday,
|
tv_rebate_order_num_yestoday, tv_share_order_num_yestoday, tv_invite_order_num_yestoday;
|
|
//本月
|
private TextView tv_all_order_num_month,
|
tv_rebate_order_num_month, tv_share_order_num_month, tv_invite_order_num_month;
|
//上月
|
private TextView tv_all_order_num_last_month,
|
tv_rebate_order_num_last_month, tv_share_order_num_last_month, tv_invite_order_num_last_month;
|
|
|
private TextView tv_filter_all_order, tv_filter_tb_order, tv_filter_jd_order, tv_filter_pdd_order, tv_filter_vip_order, tv_filter_suning_order;
|
private FrameLayout fl_filter_all_order, fl_filter_tb_order, fl_filter_jd_order, fl_filter_pdd_order, fl_filter_vip_order, fl_filter_suning_order;
|
private View v_filter_all_order, v_filter_tb_order, v_filter_jd_order, v_filter_pdd_order, v_filter_vip_order, v_filter_suning_order;
|
private ImageView iv_portrait, iv_level, iv_user_level;
|
private DisplayImageOptions options;
|
ShapeLoadingDialog dialog;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_order_statistics);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
initView();
|
addListener();
|
|
getOrderStatistics();
|
}
|
|
private void initView() {
|
tv_left = findViewById(R.id.tv_top_bar_left);
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
tv_user_id = findViewById(R.id.tv_user_id);
|
tv_all_order_form_num = findViewById(R.id.tv_all_order_form_num);
|
tv_rebate_order_num = findViewById(R.id.tv_rebate_order_num);
|
tv_share_order_num = findViewById(R.id.tv_share_order_num);
|
tv_invite_order_num = findViewById(R.id.tv_invite_order_num);
|
tv_all_order_num_today = findViewById(R.id.tv_all_order_num_today);
|
tv_rebate_order_num_today = findViewById(R.id.tv_rebate_order_num_today);
|
tv_share_order_num_today = findViewById(R.id.tv_share_order_num_today);
|
tv_invite_order_num_today = findViewById(R.id.tv_invite_order_num_today);
|
tv_all_order_num_yestoday = findViewById(R.id.tv_all_order_num_yestoday);
|
tv_rebate_order_num_yestoday = findViewById(R.id.tv_rebate_order_num_yestoday);
|
tv_share_order_num_yestoday = findViewById(R.id.tv_share_order_num_yestoday);
|
tv_invite_order_num_yestoday = findViewById(R.id.tv_invite_order_num_yestoday);
|
|
tv_all_order_num_month = findViewById(R.id.tv_all_order_num_month);
|
tv_rebate_order_num_month = findViewById(R.id.tv_rebate_order_num_month);
|
tv_share_order_num_month = findViewById(R.id.tv_share_order_num_month);
|
tv_invite_order_num_month = findViewById(R.id.tv_invite_order_num_month);
|
|
tv_all_order_num_last_month = findViewById(R.id.tv_all_order_num_last_month);
|
tv_rebate_order_num_last_month = findViewById(R.id.tv_rebate_order_num_last_month);
|
tv_share_order_num_last_month = findViewById(R.id.tv_share_order_num_last_month);
|
tv_invite_order_num_last_month = findViewById(R.id.tv_invite_order_num_last_month);
|
|
|
tv_filter_all_order = findViewById(R.id.tv_filter_all_order);
|
tv_filter_tb_order = findViewById(R.id.tv_filter_tb_order);
|
tv_filter_jd_order = findViewById(R.id.tv_filter_jd_order);
|
tv_filter_pdd_order = findViewById(R.id.tv_filter_pdd_order);
|
tv_filter_vip_order = findViewById(R.id.tv_filter_vip_order);
|
tv_filter_suning_order = findViewById(R.id.tv_filter_suning_order);
|
fl_filter_all_order = findViewById(R.id.fl_filter_all_order);
|
fl_filter_tb_order = findViewById(R.id.fl_filter_tb_order);
|
fl_filter_jd_order = findViewById(R.id.fl_filter_jd_order);
|
fl_filter_pdd_order = findViewById(R.id.fl_filter_pdd_order);
|
fl_filter_vip_order = findViewById(R.id.fl_filter_vip_order);
|
fl_filter_suning_order = findViewById(R.id.fl_filter_suning_order);
|
v_filter_all_order = findViewById(R.id.v_filter_all_order);
|
v_filter_tb_order = findViewById(R.id.v_filter_tb_order);
|
v_filter_jd_order = findViewById(R.id.v_filter_jd_order);
|
v_filter_pdd_order = findViewById(R.id.v_filter_pdd_order);
|
v_filter_vip_order = findViewById(R.id.v_filter_vip_order);
|
v_filter_suning_order = findViewById(R.id.v_filter_suning_order);
|
|
|
iv_portrait = findViewById(R.id.iv_portrait);
|
iv_level = findViewById(R.id.iv_level);
|
iv_user_level = findViewById(R.id.iv_user_level);
|
|
tv_middle.setText("订单统计");
|
this.options = new DisplayImageOptions.Builder()
|
.showImageForEmptyUri(R.drawable.ic_default_portrait)
|
.showImageOnFail(R.drawable.ic_default_portrait)
|
.showImageOnLoading(R.drawable.ic_default_portrait)
|
.resetViewBeforeLoading(true)
|
.cacheInMemory(true)
|
.cacheOnDisk(true)
|
.imageScaleType(ImageScaleType.EXACTLY)
|
.considerExifParams(true)
|
.displayer(new CircleBitmapDisplayer(300))
|
.build();
|
}
|
|
private void addListener() {
|
tv_left.setOnClickListener(this);
|
iv_user_level.setOnClickListener(this);
|
fl_filter_all_order.setOnClickListener(this);
|
fl_filter_tb_order.setOnClickListener(this);
|
fl_filter_jd_order.setOnClickListener(this);
|
fl_filter_pdd_order.setOnClickListener(this);
|
fl_filter_vip_order.setOnClickListener(this);
|
fl_filter_suning_order.setOnClickListener(this);
|
}
|
|
/**
|
* 获取订单统计数据
|
*/
|
private void getOrderStatistics() {
|
if (null == dialog)
|
dialog = new ShapeLoadingDialog.Builder(OrderSatisticsActivity.this).build();
|
dialog.show();
|
ShoppingApi.getOrderStatistics(this, UserUtil.getUid(ShoppingApplication.application), 0, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
Gson gson = new GsonBuilder().serializeNulls().create();
|
UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
|
}.getType());
|
Glide.with(OrderSatisticsActivity.this).load(info.getRankIcon()).into(iv_level);
|
ImageLoader.getInstance().displayImage(info.getPortrait(), iv_portrait, options);
|
Glide.with(OrderSatisticsActivity.this).load(info.getRankNamePicture()).into(iv_user_level);
|
tv_user_id.setText("ID:" + info.getId());
|
tv_all_order_form_num.setText("共" + jsonObject.optJSONObject("data").optString("total") + "单");
|
tv_rebate_order_num.setText(jsonObject.optJSONObject("data").optString("self"));
|
tv_share_order_num.setText(jsonObject.optJSONObject("data").optString("shared"));
|
tv_invite_order_num.setText(jsonObject.optJSONObject("data").optString("invite"));
|
|
initDateOrderData(jsonObject);
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
dialog.dismiss();
|
}
|
});
|
|
}
|
|
/**
|
* 设置日期订单统计数据
|
*
|
* @param jsonObject
|
*/
|
private void initDateOrderData(JSONObject jsonObject) {
|
tv_all_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("total"));
|
tv_rebate_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("self"));
|
tv_share_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("shared"));
|
tv_invite_order_num_today.setText(jsonObject.optJSONObject("data").optJSONObject("today").optString("invite"));
|
|
tv_all_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("total"));
|
tv_rebate_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("self"));
|
tv_share_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("shared"));
|
tv_invite_order_num_yestoday.setText(jsonObject.optJSONObject("data").optJSONObject("yesterday").optString("invite"));
|
|
|
tv_all_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("total"));
|
tv_rebate_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("self"));
|
tv_share_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("shared"));
|
tv_invite_order_num_month.setText(jsonObject.optJSONObject("data").optJSONObject("thisMonth").optString("invite"));
|
|
tv_all_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("total"));
|
tv_rebate_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("self"));
|
tv_share_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("shared"));
|
tv_invite_order_num_last_month.setText(jsonObject.optJSONObject("data").optJSONObject("lastMonth").optString("invite"));
|
}
|
|
/*
|
订单统计:今日、昨日
|
*/
|
private void getNearOrderNum(int goodsType) {
|
if (null == dialog)
|
dialog = new ShapeLoadingDialog.Builder(OrderSatisticsActivity.this).build();
|
dialog.show();
|
|
ShoppingApi.getOrderStatistics(this, UserUtil.getUid(ShoppingApplication.application), goodsType, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
initDateOrderData(jsonObject);
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
dialog.dismiss();
|
}
|
});
|
|
|
}
|
|
private void orderPlatformFilter(int goodsType) {
|
tv_filter_all_order.setTextColor(goodsType == 0 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_all_order.setVisibility(goodsType == 0 ? View.VISIBLE : View.GONE);
|
tv_filter_tb_order.setTextColor(goodsType == 1 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_tb_order.setVisibility(goodsType == 1 ? View.VISIBLE : View.GONE);
|
tv_filter_jd_order.setTextColor(goodsType == 2 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_jd_order.setVisibility(goodsType == 2 ? View.VISIBLE : View.GONE);
|
tv_filter_pdd_order.setTextColor(goodsType == 3 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_pdd_order.setVisibility(goodsType == 3 ? View.VISIBLE : View.GONE);
|
|
tv_filter_vip_order.setTextColor(goodsType == 4 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_vip_order.setVisibility(goodsType == 4 ? View.VISIBLE : View.GONE);
|
|
tv_filter_suning_order.setTextColor(goodsType == 5 ? getResources()
|
.getColor(R.color.main_text_color) : getResources().getColor(R.color.black));
|
v_filter_suning_order.setVisibility(goodsType == 5 ? View.VISIBLE : View.GONE);
|
|
|
if (goodsType == 0) {
|
getOrderStatistics();
|
} else {
|
getNearOrderNum(goodsType);
|
}
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.iv_user_level:
|
startActivity(new Intent(OrderSatisticsActivity.this, AccountGradeActivity.class));
|
break;
|
case R.id.fl_filter_all_order:
|
orderPlatformFilter(0);
|
break;
|
case R.id.fl_filter_tb_order:
|
orderPlatformFilter(1);
|
break;
|
case R.id.fl_filter_jd_order:
|
orderPlatformFilter(2);
|
break;
|
case R.id.fl_filter_pdd_order:
|
orderPlatformFilter(3);
|
break;
|
case R.id.fl_filter_vip_order:
|
orderPlatformFilter(4);
|
break;
|
case R.id.fl_filter_suning_order:
|
orderPlatformFilter(5);
|
break;
|
}
|
}
|
}
|