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

import android.content.Intent;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

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.MarkBean;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.retrofit.RtfUtils;
import com.wd.workoffice.retrofit.WorkObserver;
import com.wd.workoffice.util.WorkUtils;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import flexible.xd.android_base.network.rtfhttp.Transformer;
import io.reactivex.disposables.Disposable;

/**
 * 唛头详情
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class OrderMarkActivity extends WorkToolBarActivity {

    @BindView(R.id.et_company)
    EditText etCompany;
    @BindView(R.id.et_factory)
    EditText etFactory;
    @BindView(R.id.et_machine)
    EditText etMachine;
    @BindView(R.id.et_pro_name)
    EditText etProName;
    @BindView(R.id.et_img_code)
    EditText etImgCode;
    @BindView(R.id.et_spec)
    EditText etSpec;
    @BindView(R.id.et_send_company)
    EditText etSendCompany;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.et_box)
    EditText etBox;
    @BindView(R.id.et_supplies_code)
    EditText etSuppliesCode;
    @BindView(R.id.et_contract)
    EditText etContract;
    @BindView(R.id.et_country_company)
    EditText etCountryCompany;
    @BindView(R.id.et_app_name)
    EditText etAppName;
    @BindView(R.id.et_use)
    EditText etUse;
    private MarkBean markBean;
    private ProductBean.RecordsBean product;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        etCompany.setEnabled(false);
        etFactory.setEnabled(false);
        etMachine.setEnabled(false);
        etProName.setEnabled(false);
        etImgCode.setEnabled(false);
        etSpec.setEnabled(false);
        etSendCompany.setEnabled(false);
        etCode.setEnabled(false);
        etBox.setEnabled(false);
        etSuppliesCode.setEnabled(false);
        etContract.setEnabled(false);
        etCountryCompany.setEnabled(false);
        etAppName.setEnabled(false);
        etUse.setEnabled(false);
    }

    @Override
    protected void initData() {
        getOrderMark();
    }


    @Override
    protected void initEvent() {
    }


    private void getOrderMark() {
        Map<String, Object> param = WorkUtils.simpleParam();
        param.put("productId", getIntent().getStringExtra("productId"));
        param.put("customerId", getIntent().getStringExtra("customerId"));
        param.put("orderId", getIntent().getStringExtra("orderId"));
        RtfUtils.getRtf().getOrderMark(param).compose(Transformer.schedule()).subscribe(new WorkObserver<BaseBean>() {
            @Override
            public void doOnSubscribe(Disposable d) {
            }

            @Override
            public void onFail(String errorMsg) {
                hideLoading();
                toast(errorMsg);
            }

            @Override
            public void onSuccess(BaseBean data) {
                hideLoading();
                if (data.getCode() != 0) {
                    toast(data.getMessage());
                    return;
                }
                if (null!=data.getData()){
                    markBean = JSON.parseObject(data.getData().toString(), MarkBean.class);
                    changeView();
                }
            }
        });
    }

    private void changeView() {
        if (null == markBean) {
            return;
        }
        etCompany.setText(markBean.getReceiveCompany());
        etFactory.setText(markBean.getCustomerBranchFactory());
        etMachine.setText(markBean.getContinuousCastingMachine());
        etProName.setText(markBean.getProductName());
        etImgCode.setText(markBean.getProductSimpleCode());
        etSpec.setText(markBean.getProductSpec());
        etSendCompany.setText(markBean.getShipCompany());
        etCode.setText(markBean.getMaterialCode());
        etBox.setText(markBean.getBoxCode());
        etSuppliesCode.setText(markBean.getMaterialCodeOther());
        etContract.setText(markBean.getForeignTradeContractNumber());
        etCountryCompany.setText(markBean.getDomesticShipCompany());
        etAppName.setText(markBean.getProjectName());
        etUse.setText(markBean.getUseLocation());
    }

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