package com.wd.workoffice.ui.adapter;


import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.OrderCheckStatusBean;
import com.wd.workoffice.bean.OrderDetail;
import com.wd.workoffice.bean.workEnum.PagePermissionType;
import com.wd.workoffice.util.MathUtils;
import com.wd.workoffice.util.WorkUtils;

import java.util.List;

/**
 * Created by flexible on 2018/8/13.
 */

public class OrderDetailProductAdapter extends BaseQuickAdapter<OrderDetail.OrderItemsBean, BaseViewHolder> {
    int status;
    int attr;
    List<OrderCheckStatusBean.ItemsBean> proStatusList;
    String isCrucible;

    public OrderDetailProductAdapter(int layoutResId, List data, Integer status) {
        super(layoutResId, data);
        this.status = status;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderDetail.OrderItemsBean item) {
        helper.setText(R.id.tv_name, item.getProductName());
        helper.setText(R.id.tv_card, item.getProductSoleCode());
        helper.setText(R.id.tv_card_name, item.getProductSimpleCode());
        helper.setText(R.id.tv_spec, item.getProductSpec());
        helper.setText(R.id.tv_price, "￥".concat(MathUtils.converData(item.getInnerPrice(), 3)));
        helper.setText(R.id.tv_all_price, "￥".concat(MathUtils.multiply(MathUtils.converData(item.getProductCount(), 3),
                MathUtils.converData(item.getInnerPrice(), 3), 3)));
        helper.setText(R.id.tv_unit, item.getProductUnit());
        helper.setText(R.id.tv_from, WorkUtils.getOrderFrom(item.getType()));
        helper.setText(R.id.tv_num, MathUtils.converData(item.getProductCount(), 3));
        helper.setText(R.id.tv_return, "退货/报废");
//        helper.setGone(R.id.rl_receive_order,true);
////        {"接单方生产", "接单方采购"};
//        if (!TextUtils.isEmpty(item.getProvideMethod())){
//            helper.setText(R.id.tv_receive_order, TextUtils.equals(item.getProvideMethod(),"1")?"接单方生产":"接单方采购");
//        }
        if (!TextUtils.isEmpty(item.getAnnex())) {
            helper.setText(R.id.tv_annex,"附件");
//            helper.setText(R.id.tv_annex, item.getAnnex().substring(1));
        }
        helper.addOnClickListener(R.id.ll_annex);
        helper.addOnClickListener(R.id.tv_get);
        helper.addOnClickListener(R.id.tv_return);
        helper.addOnClickListener(R.id.tv_flow);
        helper.addOnClickListener(R.id.tv_add);
        helper.addOnClickListener(R.id.tv_mark);
        helper.setVisible(R.id.tv_mark, true);
        switch (status) {
//            private String tab[] = {
//            "全部", "待审核", "待接单", "待生产", "已入库",
//            "已交付"};
//    private String order[] = {
//            "", "100", "200", "710", "500",
//            "600"};
            case 100:
                if (item.getProductBeyondCount() == 0d) {
                    helper.setVisible(R.id.tv_stock_desc, false);
                } else {
                    helper.setVisible(R.id.tv_stock_desc, true);
                }
                break;
            case 200:
                break;
            case 300:
                helper.setGone(R.id.ll_btn, true);
                break;
            case 410:
                helper.setGone(R.id.ll_btn, true);
                break;
            case 420:
                helper.setGone(R.id.ll_btn, true);
                if (attr == 400) {
                    helper.setGone(R.id.ll_btn, false);
                }
                break;
            case 500:
                helper.setGone(R.id.ll_btn, true);
                break;
            case 600:
                helper.setGone(R.id.ll_btn, true);
                break;
        }
        if (WorkUtils.hasPermission(PagePermissionType.SO_ENTER_PAGE.getPermission())) {
            helper.setGone(R.id.fl_add, true);
        } else {
            helper.setGone(R.id.fl_add, false);
        }
        if (WorkUtils.hasPermission(PagePermissionType.SO_RETURN_APPLY_LIST.getPermission())) {
            helper.setGone(R.id.fl_return, true);
        } else {
            helper.setGone(R.id.fl_return, false);
        }
        if (WorkUtils.hasPermission(PagePermissionType.SO_USE_APPLY_LIST.getPermission())) {
            helper.setGone(R.id.fl_get, true);
        } else {
            helper.setGone(R.id.fl_get, false);
        }
        changeStats(helper, item.getProductId());
        if (TextUtils.equals(isCrucible, "1")) {//坩埚销售订单，入库和领用不展示
            helper.setGone(R.id.fl_add, false);
            helper.setGone(R.id.fl_get, false);
        }
    }

    private void changeStats(BaseViewHolder helper, int productId) {
        if (getProStatusList() != null) {
            for (OrderCheckStatusBean.ItemsBean itemsBean : getProStatusList()) {
                if (productId == itemsBean.getProductId()) {
                    helper.setGone(R.id.view_add, itemsBean.isInStore());
                    helper.setGone(R.id.view_get, itemsBean.isUsed());
                    helper.setGone(R.id.view_quality, itemsBean.isQualityInspection());
                    helper.setGone(R.id.view_return, itemsBean.isReturnX());
                }
            }
        }
    }


    public int getAttr() {
        return attr;
    }

    public void setAttr(int attr) {
        this.attr = attr;
    }

    public List<OrderCheckStatusBean.ItemsBean> getProStatusList() {
        return proStatusList;
    }

    public void setProStatusList(List<OrderCheckStatusBean.ItemsBean> proStatusList) {
        this.proStatusList = proStatusList;
        notifyDataSetChanged();
    }

    public String getIsCrucible() {
        return isCrucible;
    }

    public void setIsCrucible(String isCrucible) {
        this.isCrucible = isCrucible;
    }
}

