package com.wd.workoffice.ui.fg;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkBaseFg;
import com.wd.workoffice.bean.OrderDetail;
import com.wd.workoffice.ui.adapter.ProStockAdapter;
import com.wd.workoffice.util.MathUtils;

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

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class ProStockFragment extends WorkBaseFg {

    @BindView(R.id.rv_data)
    RecyclerView rvData;
    @BindView(R.id.tv_stock1)
    TextView tvStock1;
    @BindView(R.id.tv_stock2)
    TextView tvStock2;
    @BindView(R.id.tv_stock3)
    TextView tvStock3;
    @BindView(R.id.tv_stock4)
    TextView tvStock4;
    private ProStockAdapter dataAdapter;
    private List<OrderDetail.OrderItemsBean.StockQuantityDetailMapsBean> dataList;
    private String info;

    @Override
    protected void initView() {
        ButterKnife.bind(this, getContentView());
        rvData.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.VERTICAL, false));
    }


    @Override
    protected void initData() {
        OrderDetail.OrderItemsBean data = JSON.parseObject(info, OrderDetail.OrderItemsBean.class);
        tvStock1.setText(MathUtils.converData(data.getStoreSum(),3));
        tvStock2.setText(MathUtils.converData(data.getShipSum(),3));
        tvStock3.setText(MathUtils.converData(data.getUsedSum(),3));
        tvStock4.setText(MathUtils.converData(data.getInvoiceSum(),3));
        dataList = new ArrayList<>();
        dataAdapter = new ProStockAdapter(R.layout.item_pro_live_sotck, dataList);
        dataAdapter.bindToRecyclerView(rvData);
        dataAdapter.setEmptyView(R.layout.view_empty_content, rvData);
        dataList.addAll(data.getStockQuantityDetailMaps());
        dataAdapter.notifyDataSetChanged();
    }

    @Override
    protected void initEvent() {

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments != null) {
            info = arguments.getString("info");
        }
    }


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

}
