package com.wd.workoffice.ui.activity.bat.work;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wd.workoffice.R;
import com.wd.workoffice.app.BaseBean;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.ReturnApplyBean;
import com.wd.workoffice.bean.event.CheckReturnEvent;
import com.wd.workoffice.bean.workEnum.OrderType;
import com.wd.workoffice.bean.workEnum.PagePermissionType;
import com.wd.workoffice.retrofit.RtfUtils;
import com.wd.workoffice.retrofit.WorkObserver;
import com.wd.workoffice.ui.activity.bat.order.OutOrderDetailActivity;
import com.wd.workoffice.ui.activity.bat.order.ReturnApplyHistoryActivity;
import com.wd.workoffice.ui.activity.bat.order.SaleOrderDetailActivity;
import com.wd.workoffice.util.WorkUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.Map;

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

/**
 * 退件详情
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class ContactsReturnDetailActivity extends WorkToolBarActivity {
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.ll_top)
    RelativeLayout llTop;
    @BindView(R.id.tv_refuse)
    TextView tvRefuse;
    @BindView(R.id.tv_agree)
    TextView tvAgree;
    @BindView(R.id.ll_check)
    LinearLayout llCheck;
    @BindView(R.id.ll_bottom)
    LinearLayout llBottom;
    @BindView(R.id.rv_process)
    RecyclerView rvProcess;
    @BindView(R.id.rl_history)
    RelativeLayout rlHistory;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_pro_code)
    TextView tvProCode;
    @BindView(R.id.tv_pro_name)
    TextView tvProName;
    @BindView(R.id.tv_return_num)
    TextView tvReturnNum;
    @BindView(R.id.tv_return_type)
    TextView tvReturnType;
    @BindView(R.id.tv_stock)
    TextView tvStock;
    @BindView(R.id.tv_person)
    TextView tvPerson;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    @BindView(R.id.rl_order)
    RelativeLayout rlOrder;
    @BindView(R.id.tv_top1)
    TextView tvTop1;
    @BindView(R.id.tv_top2)
    TextView tvTop2;
    @BindView(R.id.tv_top3)
    TextView tvTop3;
    @BindView(R.id.tv_top4)
    TextView tvTop4;
    @BindView(R.id.tv_top5)
    TextView tvTop5;
    @BindView(R.id.view_node1)
    View viewNode1;
    @BindView(R.id.view_line1)
    View viewLine1;
    @BindView(R.id.view_node2)
    View viewNode2;
    @BindView(R.id.view_line2)
    View viewLine2;
    @BindView(R.id.view_node3)
    View viewNode3;
    @BindView(R.id.view_line3)
    View viewLine3;
    @BindView(R.id.view_node4)
    View viewNode4;
    @BindView(R.id.view_line4)
    View viewLine4;
    @BindView(R.id.view_node5)
    View viewNode5;
    @BindView(R.id.view_line5)
    View viewLine5;
    @BindView(R.id.tv_dep1)
    TextView tvDep1;
    @BindView(R.id.tv_dep2)
    TextView tvDep2;
    @BindView(R.id.tv_dep3)
    TextView tvDep3;
    @BindView(R.id.tv_dep4)
    TextView tvDep4;
    @BindView(R.id.tv_dep5)
    TextView tvDep5;
    @BindView(R.id.ll_process)
    LinearLayout llProcess;
    private ReturnApplyBean.RecordsBean info;
    private String orderType;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        llProcess.setVisibility(View.GONE);
        llTop.setVisibility(View.GONE);
        llBottom.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
        info = JSON.parseObject(getIntent().getStringExtra("info"), ReturnApplyBean.RecordsBean.class);
        orderType = info.getOrderType();
        changeView();

    }

    private void changeView() {
        tvName.setText(info.getProductSimpleCode());
        tvProName.setText(info.getProductName());
        tvProCode.setText(info.getProductSoleCode());
        tvReturnNum.setText(String.valueOf(info.getProductAmount()));
        tvReturnType.setText(info.getReturnTypeName());
        tvStock.setText(info.getBackStockName());
        tvPerson.setText(String.valueOf(info.getCreatedByName()));
        tvTime.setText(info.getCreatedTime());
        tvRemark.setText(String.valueOf(info.getApplyRemark()));
        tvStatus.setText(WorkUtils.getReturnStatus(Integer.valueOf(info.getStatus())));
    }


    @Override
    protected void initEvent() {
    }

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


    @OnClick({R.id.tv_refuse, R.id.tv_agree, R.id.rl_history, R.id.rl_order})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_refuse:
                break;
            case R.id.tv_agree:
                break;
            case R.id.rl_history:
                break;
            case R.id.rl_order:
                if (TextUtils.equals(orderType, OrderType.SALE.getCode())) {
                    if (!WorkUtils.hasPermission(PagePermissionType.SALE_ORDER_DETAIL.getPermission())) {
                        toast(R.string.permission);
                        return;
                    }
                    startActivity(SaleOrderDetailActivity.class,
                            "identity", "1",
                            "id", info.getOrderId());
                } else if (TextUtils.equals(orderType, OrderType.OUT_BUY.getCode())) {
                    if (!WorkUtils.hasPermission(PagePermissionType.PO_PURCHASE_DETAILS.getPermission())) {
                        toast(R.string.permission);
                        return;
                    }
                    startActivity(OutOrderDetailActivity.class,
                            "identity", "1",
                            "id", info.getOrderId());
                }
                break;
        }
    }
}
