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

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.DepBean;
import com.wd.workoffice.bean.workEnum.PermissionType;
import com.wd.workoffice.ui.activity.bat.store.StoreSaleClientActivity;
import com.wd.workoffice.ui.activity.bat.store.StoreSaleProductActivity;
import com.wd.workoffice.util.UserKeeper;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 生成坩埚销售订单
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class AddCrucibleActivity extends WorkToolBarActivity {
    @BindView(R.id.tv_client)
    TextView tvClient;
    @BindView(R.id.rl_client)
    RelativeLayout rlClient;
    @BindView(R.id.tv_stock)
    TextView tvStock;
    @BindView(R.id.rl_stock)
    RelativeLayout rlStock;
    @BindView(R.id.tv_product)
    TextView tvProduct;
    @BindView(R.id.rl_product)
    RelativeLayout rlProduct;
    private Integer clientId;
    private Integer stockId;
    private String orderId;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {
        orderId = getIntent().getStringExtra("orderId");
    }

    @Override
    protected void initEvent() {
    }

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


    @OnClick({R.id.rl_client, R.id.rl_stock, R.id.rl_product})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_client:
                startActivityForResult(StoreSaleClientActivity.class,
                        10001, "flag", "1", "code", "CUSTOMER","depId", UserKeeper.getInstance().getUserDepId());
                break;
            case R.id.rl_stock:
                if (clientId == null) {
                    toast("请选择客户");
                    return;
                }
                startActivityForResult(AddCrucibleStockActivity.class,
                        10002, "id", clientId.toString());
                break;
            case R.id.rl_product:
                if (clientId == null) {
                    toast("请选择客户");
                    return;
                }
                if (stockId == null) {
                    toast("请选择代管库");
                    return;
                }
                startActivity(AddCrucibleProductActivity.class,
                        "procedureOrderId", orderId,
                        "pro", getIntent().getStringExtra("pro"),
                        "customerId", clientId.toString(),
                        "stockId", stockId.toString(),
                        "code", PermissionType.CRUCIBLE_SELL.getCode());
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 10001 && resultCode == 10001) {
            String clientName = data.getStringExtra("clientName");
            clientId = data.getIntExtra("id", 0);
            tvClient.setText(clientName);
        }else if (requestCode == 10002 && resultCode == 10002){
            String clientName = data.getStringExtra("stockName");
            stockId = data.getIntExtra("id", 0);
            tvStock.setText(clientName);
        }
    }

}
