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

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.IdRes;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
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.HmLbBean;
import com.example.administrator.zhapp.entity.ResultBean;
import com.example.administrator.zhapp.entity.requestbean;
import com.example.administrator.zhapp.utils.GsonUtils;
import com.example.administrator.zhapp.utils.HttpListener;
import com.example.administrator.zhapp.utils.NohttpUtils;
import com.example.administrator.zhapp.utils.SPUtils;
import com.example.administrator.zhapp.weight.InputLayout;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;

/**
 * Created by ruihong on 2019/8/19.
 */

public class HmShLbinfoActivity extends BaseActivity {


    InputLayout ilJhmc;
    InputLayout ilKssj;
    InputLayout ilJssj;
    InputLayout ilSqr;
    InputLayout ilSqsj;
    InputLayout ilSpr;
    InputLayout ilSpsj;
    InputLayout ilHmbz;
    InputLayout ilHmzt;
    Button btnTj;
    RadioButton rbDw2;
    RadioButton rbDw3;
    RadioGroup rgDw;
    private String DwResult = " ", SHZT;

    private HmLbBean.DataBean list;

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

    @Override
    public void initData() {
        Intent intent = getIntent();
        list = (HmLbBean.DataBean) intent.getExtras().get("list");
        ilJhmc.setContent(list.getJHMC());

        ilKssj.setContent(list.getST());


        ilJssj.setContent(list.getET());


        ilSqr.setContent(list.getSQR());


        ilSqsj.setContent(list.getSQSJ());


        ilSpr.setContent(list.getSPR());

        ilSpsj.setContent(list.getSQSJ());


        ilHmbz.setContent(list.getHMBZ());


        ilHmzt.setContent(list.getSPZT());

        rgDw.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                RadioButton radioButton = (RadioButton) group.findViewById(checkedId);
                DwResult = radioButton.getText().toString();
            }
        });
        btnTj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (DwResult.equals(" ")) {
                    showToast("请选择状态");
                } else {
                    if (DwResult.equals("审批通过")) {
                        SHZT = "2";
                    } else if (DwResult.equals("审批拒绝")) {
                        SHZT = "3";
                    }
                    requestDatas();
                }
            }
        });

    }

    private void requestDatas() {


        final Request<String> requset = NoHttp.createStringRequest(Contans.IP + Contans.HM, RequestMethod.POST);

        requset.setDefineRequestBodyForJson(createJson());

        NohttpUtils.getInstance().add(this, 0, requset, new HttpListener<String>() {
            @Override
            public void onSucceed(int what, Response<String> response) {
                ResultBean bean = GsonUtils.GsonToBean(response.get(), ResultBean.class);
                if (bean.getState() == 1) {
                    showToast(bean.getMsg());
                    Intent intent = new Intent();
                    intent.putExtra("STATE", SHZT);
                    setResult(Activity.RESULT_OK, intent);
                    finish();
                } else {
                    finish();
                }
            }

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

            }
        });
    }

    private String createJson() {
        String USERNAME = (String) SPUtils.get(context, Contans.USERNAME, "");
        requestbean info = new requestbean();
        info.setAction("GC_HMJL_SP");
        info.setYHID(USERNAME);
        info.setHMID(list.getID());
        info.setSPZT(SHZT);
        String json = GsonUtils.GsonString(info);
        return json;
    }

    @Override
    protected void initView() {
        ilJhmc = findViewById(R.id.il_jhmc);
        ilKssj = findViewById(R.id.il_kssj);
        ilJssj = findViewById(R.id.il_jssj);
        ilSqr = findViewById(R.id.il_sqr);
        ilSqsj = findViewById(R.id.il_sqsj);
        ilSpr = findViewById(R.id.il_spr);
        ilSpsj = findViewById(R.id.il_spsj);
        ilHmbz = findViewById(R.id.il_hmbz);
        ilHmzt = findViewById(R.id.il_hmzt);
        btnTj = findViewById(R.id.btn_tj);
        rbDw2 = findViewById(R.id.rb_dw2);
        rbDw3 = findViewById(R.id.rb_dw3);
        rgDw = findViewById(R.id.rg_dw);

        setBack();
        setTitle("豁免原因填写");
    }
}
