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

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 java.util.ArrayList;
import java.util.List;

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 MesOtherSupplierDetailActivity extends WorkToolBarActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_years)
    TextView tvYears;
    @BindView(R.id.tv_supply_num)
    TextView tvSupplyNum;
    @BindView(R.id.tv_stock_num)
    TextView tvStockNum;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.rv_img)
    RecyclerView rvImg;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    private MachineDetailBean.OtherSupListBean 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_other_supplier_detail;
    }

    private void getData() {
        RtfUtils.getMesRtf().supplierDetail(getIntent().getStringExtra("id"), "1").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.OtherSupListBean.class);
                imgList.addAll(dataBean.getAttachments());
                imgAdapter.notifyDataSetChanged();
                tvName.setText(dataBean.getSupplierName());
                tvSupplyNum.setText(dataBean.getSupplyNumber());
                tvStockNum.setText(dataBean.getStockNumber());
                tvYears.setText(dataBean.getUseLife());
                tvContent.setText(dataBean.getOtherSituationDescription());
                tvRemark.setText(dataBean.getRemark());
            }
        });
    }

}
