package com.wd.workoffice.ui.activity.mes.history;

import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wd.workoffice.R;
import com.wd.workoffice.app.BaseMesBean;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.mesBean.ImageBean;
import com.wd.workoffice.bean.mesBean.MachineDetailBean;
import com.wd.workoffice.retrofit.RtfUtils;
import com.wd.workoffice.retrofit.WorkObserver;
import com.wd.workoffice.ui.adapter.ImgAdapter;
import com.wd.workoffice.util.WorkUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import flexible.xd.android_base.network.rtfhttp.Transformer;
import io.reactivex.disposables.Disposable;

/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class HistoryThreeDetailActivity extends WorkToolBarActivity {
    @BindView(R.id.tv_pro)
    TextView tvPro;
    @BindView(R.id.rl_pro)
    RelativeLayout rlPro;
    @BindView(R.id.et_img_code)
    TextView etImgCode;
    @BindView(R.id.et_type)
    TextView etType;
    @BindView(R.id.et_spec)
    TextView etSpec;
    @BindView(R.id.tv_material)
    TextView tvMaterial;
    @BindView(R.id.tv_requirements)
    TextView tvRequirements;
    @BindView(R.id.tv_years)
    TextView tvYears;
    @BindView(R.id.tv_position)
    TextView tvPosition;
    @BindView(R.id.tv_baking_method)
    TextView tvBakingMethod;
    @BindView(R.id.tv_baking_temperature)
    TextView tvBakingTemperature;
    @BindView(R.id.tv_baking_time)
    TextView tvBakingTime;
    @BindView(R.id.rl_time)
    RelativeLayout rlTime;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.rv_img)
    RecyclerView rvImg;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    private MachineDetailBean.ProductListBean dataBean;
    private List<ImageBean> imgList;
    private ImgAdapter imgAdapter;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        rvImg.setLayoutManager(new GridLayoutManager(this, 3, RecyclerView.VERTICAL, false));

    }

    @Override
    protected void initData() {
        imgList = new ArrayList<>();
        imgAdapter = new ImgAdapter(R.layout.item_mes_ticket_img, imgList);
        imgAdapter.bindToRecyclerView(rvImg);
        getData();
    }


    @Override
    protected void initEvent() {
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_mes_user_data_three_detail;
    }

    private void getData() {
        Map<String, Object> param = WorkUtils.simpleParam();
        param.put("id",  getIntent().getStringExtra("id"));
        param.put("feedbackInfoNo",  getIntent().getStringExtra("feedback"));
        param.put("msVersion", getIntent().getStringExtra("version"));
        RtfUtils.getMesRtf().historyProductList( "1",  WorkUtils.convertMapToBody(param)).compose(Transformer.schedule()).subscribe(new WorkObserver<BaseMesBean>() {
            @Override
            public void doOnSubscribe(Disposable d) {
            }

            @Override
            public void onFail(String errorMsg) {
                hideLoading();
                toast(errorMsg);
            }

            @Override
            public void onSuccess(BaseMesBean data) {
                hideLoading();
                if (!data.isSuccess()) {
                    toast(data.getMessage());
                    return;
                }

                dataBean = JSON.parseObject(data.getData().toString(), MachineDetailBean.ProductListBean.class);
                imgList.addAll(dataBean.getAttachments());
                imgAdapter.notifyDataSetChanged();
                tvPro.setText(dataBean.getProductsName());
                etImgCode.setText(dataBean.getFigureNumber());
                etSpec.setText(dataBean.getProductsStandards());
                etType.setText(dataBean.getProductsType());
                tvMaterial.setText(dataBean.getMaterialsUsed());
                tvRequirements.setText(dataBean.getUseRequirement());
                tvYears.setText(dataBean.getUseLife());
                tvPosition.setText(dataBean.getSlagLineLocation());
                tvBakingMethod.setText(dataBean.getBakingMethod());
                tvBakingTime.setText(dataBean.getBakingDateTime()+"");
                tvBakingTemperature.setText(dataBean.getBakingTemperature());
                tvContent.setText(dataBean.getUseProblemFeedback());
                tvRemark.setText(dataBean.getRemark());
            }
        });
    }
}
