package com.example.administrator.zhapp.activity.ajhxcgl;

import androidx.appcompat.widget.AppCompatTextView;
import android.widget.TextView;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.BaseActivity;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.entity.Gzqk;
import com.example.administrator.zhapp.entity.GzqkInfo;
import com.example.administrator.zhapp.utils.GsonUtils;
import com.example.administrator.zhapp.utils.HttpListener;
import com.example.administrator.zhapp.utils.NohttpUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;

public class GzqkPushckActivity extends BaseActivity {

    AppCompatTextView title;
    TextView tvLrr;
    TextView tvInputtime;
    TextView tvBm;
    TextView etCbs;
    TextView etGzdd;
    TextView tvStarttime;
    TextView tvMs;

    private String id;

    @Override
    public int getContentViewID() {
        return R.layout.activity_gzqk_pushck;
    }

    @Override
    protected void initView() {
        title = findViewById(R.id.title);
        tvLrr = findViewById(R.id.tv_lrr);
        tvInputtime = findViewById(R.id.tv_inputtime);
        tvBm = findViewById(R.id.tv_bm);
        etCbs = findViewById(R.id.et_cbs);
        etGzdd = findViewById(R.id.et_gzdd);
        tvStarttime = findViewById(R.id.tv_starttime);
        tvMs = findViewById(R.id.tv_ms);


        setBack();
        setTitle("工作情况查看");

        id = getIntent().getStringExtra("id");
        requestData();
    }

    @Override
    protected void initData() {

    }

    private void requestData() {

        String json = "{ \"Rows\": [ { \"id\": \"" + id + "\"} ],\"Total\": 1}";

        Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.GZQKID, RequestMethod.POST);
        request.setDefineRequestBodyForJson(json);
        NohttpUtils.getInstance().add(this, 0, request, callback, true, true, "加载中...");
    }

    private HttpListener<String> callback = new HttpListener<String>() {
        @Override
        public void onSucceed(int what, Response<String> response) {

            System.out.println("返回数据" + response.get());

            try {
                GzqkInfo info = GsonUtils.GsonToBean(response.get(), GzqkInfo.class);

                if (info != null) {
                    if (!info.getTotal().equals("0")) {
                        Gzqk gzqk = info.getRows().get(0);
                        showView(gzqk);
                    } else {
                    }
                } else {
                    showToast("数据出错");
                }
            } catch (Exception e) {
                e.printStackTrace();
                showToast("数据出错");
            }
        }

        @Override
        public void onFailed(int what, Response<String> response) {

        }
    };

    public void showView(Gzqk gzqk) {
        tvLrr.setText(gzqk.getLrrname().isEmpty() ? gzqk.getLrr() : gzqk.getLrrname());
        tvInputtime.setText(gzqk.getAddtime());
        tvBm.setText(gzqk.getBm());
        etGzdd.setText(gzqk.getGgplace());
        tvStarttime.setText(gzqk.getGgtime_s());
        tvMs.setText(gzqk.getGgcontent());
        etCbs.setText(gzqk.getCbs());
    }
}
