コード例 #1
0
  @Override
  protected void getData() {
    Request<JSONObject> request = new NyppJsonRequest(ServerConfig.QUERY_DEFAULT_ADDRESS);
    Map<String, String> postData = new HashMap<String, String>();
    postData.put("sign", TApplication.getInstance().getUserSign());
    postData.put("memberNo", TApplication.getInstance().getMemberId());
    request.setRequestBody(new Gson().toJson(postData));
    CallServer.getRequestInstance()
        .add(
            context,
            0,
            request,
            new HttpListener<JSONObject>() {

              @Override
              public void onSucceed(int what, Response<JSONObject> response) {

                JSONObject result = response.get();
                if ("200".equals(result.optString("status"))) {
                  CommonResult<AddressBean> addressBean =
                      CommonResult.fromJson(result.toString(), AddressBean.class);
                  addrData = addressBean.getData();
                  if (addrData != null) {
                    setAddr();
                  }
                }
              }

              @Override
              public void onFailed(
                  int what,
                  String url,
                  Object tag,
                  Exception exception,
                  int responseCode,
                  long networkMillis) {}
            },
            false,
            true);
  }
コード例 #2
0
  @Override
  protected void initData() {
    titleView.setTitle("确认订单");

    Bundle bundle = getIntent().getExtras();
    cartList = (List<GoodsCartBean>) bundle.getSerializable("orderList");
    quantity = bundle.getInt("quantity", 0);
    minimum = bundle.getInt("minimum", 0);

    setMoney();
    options = TApplication.getInstance().getAllOptionsNoAmi(R.drawable.bg_defualt_118);
    ordersAdapter =
        new CommAdapter<GoodsCartBean>(context, cartList, R.layout.item_sure_order_cart) {

          @Override
          public void onGetView(int position, View convertView, final GoodsCartBean cartData) {

            ImageLoader.getInstance()
                .displayImage(
                    cartData.image,
                    (ImageView) convertView.findViewById(R.id.cart_pic_img),
                    options);
            setText(convertView, R.id.item_order_position, "产品" + (position + 1));
            setText(convertView, R.id.item_cart_title_tv, cartData.title);
            setText(convertView, R.id.item_order_quantity, "" + cartData.allQua);
            setText(convertView, R.id.item_order_price, "¥" + cartData.allPri);

            AutoSizeListView sukListView =
                (AutoSizeListView) convertView.findViewById(R.id.item_order_lv);
            ordersSukAdapter =
                new CommAdapter<GoodsCartSukBean>(
                    context, cartData.sukList, R.layout.item_sure_order_suk_cart) {

                  @Override
                  public void onGetView(
                      int position, View convertView, final GoodsCartSukBean data) {
                    setText(convertView, R.id.cart_suk_color, "颜色:" + data.colour);
                    setText(convertView, R.id.cart_suk_size, "尺码:" + data.size);
                    setText(
                        convertView,
                        R.id.cart_suk_price,
                        "单价:" + String.format("%.2f", data.preferentialPrice) + "/件");
                    setText(
                        convertView,
                        R.id.cart_suk_money,
                        "¥" + String.format("%.2f", data.preferentialPrice * data.quantity));
                    StockChangeView stockCv =
                        (StockChangeView) convertView.findViewById(R.id.cart_suk_change);
                    if (quantity == 0) {
                      stockCv.isChange(false);
                      stockCv.notifyNum(data.quantity, data.detailId);
                    } else {
                      stockCv.isChange(true);
                      stockCv.notifyNum(
                          data.quantity,
                          minimum,
                          quantity,
                          new OnNumChangeListenner() {

                            @Override
                            public void changeNum(int num) {
                              data.quantity = num;
                              setMoney();
                            }
                          });
                    }
                  }
                };
            sukListView.setAdapter(ordersSukAdapter);
          }
        };
    orderLv.setAdapter(ordersAdapter);

    // 解决ScrollView下嵌套ListView进页面不在顶部的问题
    nameTv.setFocusable(true);
    nameTv.setFocusableInTouchMode(true);
    nameTv.requestFocus();
  }
コード例 #3
0
  private void submitOrders() {
    if (addrData == null) {
      ToastUtil.show("请您去选择收货地址");
      return;
    }
    Request<JSONObject> request = new NyppJsonRequest(ServerConfig.SUBMIT_ORDERS);
    JSONObject postJson = null;
    try {
      postJson = new JSONObject();
      postJson.put("sign", TApplication.getInstance().getUserSign());
      postJson.put("memberId", TApplication.getInstance().getMemberId());
      postJson.put("contactName", addrData.name); // 姓名
      postJson.put("contactPhone", addrData.mobile);
      postJson.put("province", addrData.provinceId);
      postJson.put("city", addrData.cityId);
      postJson.put("district", addrData.districtId);
      postJson.put("address", addrData.address);
      postJson.put("message", msgEt.getText().toString());
      postJson.put("orderAmount", allMoney);
      postJson.put("logisticsFees", logistics);
      postJson.put("discountAmount", 0); // 优惠金额

      JSONArray array = new JSONArray();
      for (GoodsCartBean cartBean : cartList) {
        JSONObject object = new JSONObject();
        object.put("cartId", "");
        object.put("productId", cartBean.pid);
        JSONArray sukArray = new JSONArray();
        for (GoodsCartSukBean sukBean : cartBean.sukList) {
          JSONObject sukobject = new JSONObject();
          sukobject.put("sukId", sukBean.sukId);
          sukobject.put("number", sukBean.quantity);
          sukobject.put("cartDetailId", sukBean.detailId);
          sukArray.put(sukobject);
        }
        object.put("sukList", sukArray);
        array.put(object);
      }

      postJson.put("productIds", array);
    } catch (Exception e) {
      return;
    }
    request.setRequestBody(postJson.toString());
    CallServer.getRequestInstance()
        .add(
            context,
            0,
            request,
            new HttpListener<JSONObject>() {

              @Override
              public void onSucceed(int what, Response<JSONObject> response) {
                JSONObject result = response.get(); // 响应结果
                if ("200".equals(result.optString("status"))) {
                  Intent intent = new Intent(context, PayModeActivity.class);
                  intent.putExtra("orderId", result.optString("data")); // 订单编号
                  intent.putExtra("orderMoney", allMoney); // 订单价格
                  startActivityForResult(intent, SELECT_ADDR);
                  EventBus.getDefault().post("getOrderData");
                } else {
                  String resultStr = result.optString("declare", "定单提交失败");
                  ToastUtil.show(resultStr);
                }
              }

              @Override
              public void onFailed(
                  int what,
                  String url,
                  Object tag,
                  Exception exception,
                  int responseCode,
                  long networkMillis) {}
            },
            false,
            true);
  }