package com.wd.workoffice.ui.fg;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkBaseFg;
import com.wd.workoffice.bean.vo.BatLayoutVo;
import com.wd.workoffice.ui.activity.mes.MesFeedbackActivity;
import com.wd.workoffice.ui.activity.mes.repair.MesServiceActivity;
import com.wd.workoffice.ui.activity.mes.QualityTraceabilityActivity;
import com.wd.workoffice.ui.activity.mes.analysis.MesAnalysisActivity;
import com.wd.workoffice.ui.activity.mes.order.MesOrderProcessActivity;
import com.wd.workoffice.ui.activity.mes.report.MesReportActivity;
import com.wd.workoffice.ui.activity.mes.ticket.MesTicketActivity;
import com.wd.workoffice.ui.activity.mes.work.QualityWorkActivity;
import com.wd.workoffice.ui.adapter.BatLayoutAdapter;
import com.wd.workoffice.util.WorkUtils;

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

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class MesFragment extends WorkBaseFg {
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;
    @BindView(R.id.rv_data)
    RecyclerView rvData;
    List<BatLayoutVo> dataList = new ArrayList<>();
//    int[] dataImg = new int[]{R.mipmap.mes_icon1, R.mipmap.mes_icon2, R.mipmap.mes_icon3, R.mipmap.mes_icon4,
//            R.mipmap.mes_icon5, R.mipmap.mes_icon6, R.mipmap.mes_icon7, R.mipmap.mes_icon8,
//            R.mipmap.mes_icon9, R.mipmap.mes_icon10, R.mipmap.mes_icon10};
    int[] dataImg = new int[]{R.mipmap.mes_icon1, R.mipmap.mes_icon2, R.mipmap.mes_icon3, R.mipmap.mes_icon4,
            R.mipmap.mes_icon5, R.mipmap.mes_icon8,
            R.mipmap.mes_icon9,R.mipmap.mes_icon10};
//    String[] dataName = new String[]{"订单追踪", "质量报表", "质量分析", "质量绩效",
//            "质量追溯", "质量反馈", "过程检测", "报废管理", "检维修记录", "设备监控"
//            , "工单管理"};
    String[] dataName = new String[]{"订单追踪", "质量报表", "缺陷字典", "质量绩效",
            "质量追溯", "质量工单","检维修记录"
            , "市场服务"};


    @Override
    protected void initView() {
        ButterKnife.bind(this, getContentView());
        addDate(dataList, dataImg, dataName);
        initRvLayout(rvData, dataList);
    }


    @Override
    protected void initData() {
        WorkUtils.getMesMenu();
    }


    @Override
    protected void initEvent() {
        srlRefresh.setOnRefreshListener(refreshLayout -> {
            srlRefresh.finishRefresh();
        });
    }

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

    private void addDate(List<BatLayoutVo> saleList, int[] saleImg, String[] saleName) {
        for (int i = 0; i < saleImg.length; i++) {
            BatLayoutVo batLayoutVo = new BatLayoutVo();
            batLayoutVo.setImg(saleImg[i]);
            batLayoutVo.setName(saleName[i]);
            saleList.add(batLayoutVo);
        }

    }

    /**
     * 初始化布局
     *
     * @param rvSale
     * @param saleList
     */
    private void initRvLayout(RecyclerView rvSale, List<BatLayoutVo> saleList) {
        rvSale.setLayoutManager(new GridLayoutManager(getActivity(), 3, RecyclerView.VERTICAL,
                false));
        BatLayoutAdapter batLayoutAdapter = new BatLayoutAdapter(R.layout.item_mes_layout, saleList);
        batLayoutAdapter.bindToRecyclerView(rvSale);
        batLayoutAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(MesOrderProcessActivity.class);
                        break;
                    case 1:
                        startActivity(MesReportActivity.class);
                        break;
                    case 2:
                        startActivity(MesAnalysisActivity.class);
                        break;
                    case 3:
                        break;
                    case 4:
                        startActivity(QualityTraceabilityActivity.class);
                        break;
                    case 5:
//                        startActivity(MesFeedbackActivity.class);
                        startActivity(QualityWorkActivity.class);
                        break;
                    case 6:
//                        startActivity(MesProcessActivity.class);
                        startActivity(MesServiceActivity.class);
                        break;
                    case 7:
//                        startActivity(MesScrappedActivity.class);
                        startActivity(MesTicketActivity.class);
                        break;
                    case 8:
//                        startActivity(MesServiceActivity.class);
                        break;
                    case 9:
                        break;
                    case 10:
//                        startActivity(MesTicketActivity.class);
                        break;
                }
            }
        });
    }

}
