parent
928cd507ca
commit
1b7c8d24e4
@ -0,0 +1,154 @@
|
||||
package com.example.drink_order_system;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class BillActivity extends AppCompatActivity {
|
||||
|
||||
private String userName;
|
||||
private String number;
|
||||
private String time;
|
||||
private String shop;
|
||||
private String cost;
|
||||
private TextView txnumber;
|
||||
private TextView txtime;
|
||||
private TextView txshop;
|
||||
private TextView txcost;
|
||||
private ArrayList <String>st1=new ArrayList<>();
|
||||
private ArrayList <String>st2=new ArrayList<>();
|
||||
private RecyclerView recylerview;
|
||||
private Bill bill1;
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_bill);
|
||||
bill1 = new Bill("20240707111111", "wo", 30.2f, st1, st2);
|
||||
initData();
|
||||
|
||||
userName = getIntent().getStringExtra("userName");
|
||||
number = getIntent().getStringExtra("number");
|
||||
bundle.putString("userName", userName);
|
||||
|
||||
txnumber = findViewById(R.id.textView_number);
|
||||
txtime = findViewById(R.id.textView_time);
|
||||
txshop = findViewById(R.id.textView_shop);
|
||||
txcost = findViewById(R.id.textView_cost);
|
||||
txnumber.setText(number);
|
||||
|
||||
fetchBillInfo(number); // 在这里调用fetchBillInfo
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
recylerview = findViewById(R.id.RV_food);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
recylerview.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
recylerview.setAdapter(new MyRecylerViewAdapter());
|
||||
}
|
||||
|
||||
private class MyRecylerViewAdapter extends RecyclerView.Adapter<MyRecylerViewAdapter.ViewHolder> {
|
||||
@NonNull
|
||||
@Override
|
||||
public MyRecylerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View inflate = LayoutInflater.from(BillActivity.this).inflate(R.layout.food_list_item, parent, false);
|
||||
return new ViewHolder(inflate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyRecylerViewAdapter.ViewHolder holder, int position) {
|
||||
holder.foodname.setText(bill1.get_food().get(position));
|
||||
holder.foodnumber.setText(bill1.get_number().get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return bill1.get_food().size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private TextView foodname;
|
||||
private TextView foodnumber;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
foodname = itemView.findViewById(R.id.Text_foodname);
|
||||
foodnumber = itemView.findViewById(R.id.Text_foodnumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据订单号设置订单详情
|
||||
public void BillInfo(Bill bill) throws ParseException {
|
||||
shop = bill.get_Sname();
|
||||
cost = Float.toString(bill.get_Omaney());
|
||||
time = bill.get_no();
|
||||
String strDate = number.substring(0, 4) + "年" + number.substring(4, 6) + "月" + number.substring(6, 8) + "日 " + number.substring(8, 10) + ":" + number.substring(10, 12) + ":" + number.substring(12, 14);
|
||||
Log.e("strDate", strDate);
|
||||
|
||||
runOnUiThread(() -> {
|
||||
txshop.setText(shop);
|
||||
txcost.setText(cost);
|
||||
txtime.setText(strDate);
|
||||
recylerview.getAdapter().notifyDataSetChanged(); // 通知适配器数据已更改
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchBillInfo(final String no) {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.176:8080/warehouse_management_system_war_exploded/getPurchase" + "?Ono=" + no)
|
||||
.build();
|
||||
Log.e("BillActivity", "http://192.168.153.202:8080/warehouse_management_system_war_exploded/getPurchase" + "?Ono=" + no);
|
||||
client.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
if (response.isSuccessful()) {
|
||||
String jsonData = response.body().string();
|
||||
Gson gson = new Gson();
|
||||
Log.e("username", userName);
|
||||
Log.w("billStr", jsonData);
|
||||
|
||||
Bill bill = gson.fromJson(jsonData, Bill.class);
|
||||
bill1 = bill;
|
||||
try {
|
||||
BillInfo(bill);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}}
|
||||
|
Loading…
Reference in new issue