package com.qhclh.ytzh.work.productiondailyw;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseFragment;


import java.math.BigDecimal;

import butterknife.BindView;

/**
 * Created by 青花瓷 on 2017/12/4.
 */

public class DetailsofdocumentsFragment extends BaseFragment {
    private ProductiondailywActivity act;
    @BindView(R.id.detaild_buildinghome)
    TextView detaild_buildinghome;
    @BindView(R.id.detaild_dayage)
    EditText detaild_dayage;
    @BindView(R.id.detaild_survival)
    EditText detaild_survival;
    @BindView(R.id.detaild_death)
    EditText detaild_death;
    @BindView(R.id.detaild_eliminate)
    EditText detaild_eliminate;
    @BindView(R.id.detaild_water)
    EditText detaild_water;
    @BindView(R.id.detaild_weight)
    EditText detaild_weight;

    @Override
    protected int setLayout() {
        return R.layout.fragment_detailsofdoc;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        act = (ProductiondailywActivity) getActivity();


    }

    @Override
    protected void initOper() {
        detaild_buildinghome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int size = BasicattributesFragment.houseNameList.size();
                final String items[] = BasicattributesFragment.houseNameList.toArray(new String[size]);
                new AlertDialog.Builder(getActivity())
                        .setTitle("请选择栋舍")
                        .setIcon(R.mipmap.ic_launcher)
                        .setSingleChoiceItems(items, 0,
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        detaild_buildinghome.setText(items[which]);
                                        act.setHouseid(Long.parseLong(BasicattributesFragment.houseIdList.get(which)));
                                        dialog.dismiss();
                                    }
                                }
                        )
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        })
                        .show();
            }
        });


        detaild_dayage.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setDays(Integer.parseInt(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });

        detaild_survival.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setCunhuolv(new BigDecimal(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });

        detaild_death.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setDienum(Integer.parseInt(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });
        detaild_eliminate.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setTaotai(Integer.parseInt(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });

        detaild_water.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setWater(new BigDecimal(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });

        detaild_weight.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    act.setWeight(new BigDecimal(editable.toString().trim()));
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });


    }
}
