package com.wd.workoffice.ui.activity.mes.quality;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.bean.mesBean.ChooseMachineBean;
import com.wd.workoffice.util.WorkUtils;

import java.util.Map;

import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class MesQualityConditionActivity extends WorkToolBarActivity {
    @BindView(R.id.et_no)
    EditText etNo;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_manager)
    EditText etManager;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_pro_code)
    EditText etProCode;
    @BindView(R.id.et_pro_name)
    EditText etProName;
    @BindView(R.id.et_spec)
    EditText etSpec;
    @BindView(R.id.et_img_code)
    EditText etImgCode;
    @BindView(R.id.et_box)
    EditText etBox;
    @BindView(R.id.et_num)
    EditText etNum;
    @BindView(R.id.rl_machine)
    RelativeLayout rlMachine;
    @BindView(R.id.srl_refresh)
    NestedScrollView srlRefresh;
    @BindView(R.id.tv_machine)
    TextView tvMachine;
    @BindView(R.id.tv_steel)
    TextView tvSteel;
    private Map<String, Object> param;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        param = WorkUtils.simpleParam();
    }


    @Override
    protected void initData() {
    }

    @Override
    protected void initEvent() {
    }

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_finish, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.finish:

                if (!TextUtils.isEmpty(etNo.getText().toString())) {
                    param.put("feedbackCode", etNo.getText().toString());
                }
                if (!TextUtils.isEmpty(etName.getText().toString())) {
                    param.put("customerName", etName.getText().toString());
                }
                if (!TextUtils.isEmpty(etManager.getText().toString())) {
                    param.put("saleUserName", etManager.getText().toString());
                }
                if (!TextUtils.isEmpty(etPhone.getText().toString())) {
                    param.put("phoneNumber", etPhone.getText().toString());
                }
                if (!TextUtils.isEmpty(etProCode.getText().toString())) {
                    param.put("procedureCode", etProCode.getText().toString());
                }
                if (!TextUtils.isEmpty(etProName.getText().toString())) {
                    param.put("productName", etProName.getText().toString());
                }
                if (!TextUtils.isEmpty(etSpec.getText().toString())) {
                    param.put("specification", etSpec.getText().toString());
                }
                if (!TextUtils.isEmpty(etImgCode.getText().toString())) {
                    param.put("drawingNumber", etImgCode.getText().toString());
                }
                if (!TextUtils.isEmpty(etName.getText().toString())) {
                    param.put("salesCompanyName", etName.getText().toString());
                }
                if (!TextUtils.isEmpty(etNum.getText().toString())) {
                    param.put("defectCount", etNum.getText().toString());
                }
                if (!TextUtils.isEmpty(etBox.getText().toString())) {
                    param.put("boxCode", etBox.getText().toString());
                }
                Intent intent = new Intent();
                intent.putExtra("param", JSON.toJSONString(param));
                setResult(10001, intent);
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    @OnClick(R.id.rl_machine)
    public void onViewClicked() {
        startActivityForResult(MesChooseMachineActivity.class,
                10002, "code", "");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 10002 && resultCode == 10001) {
            ChooseMachineBean chooseMachine = JSON.parseObject(data.getStringExtra("data"), ChooseMachineBean.class);
            tvMachine.setText(chooseMachine.getCasterName());
            tvSteel.setText(chooseMachine.getSteelTypeId());
            param.put("steelTypeId", chooseMachine.getSteelTypeId());
            param.put("casterName", chooseMachine.getCasterName());
        }
    }

}