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

import android.content.DialogInterface;
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.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkToolBarActivity;
import com.wd.workoffice.util.DialogUtils;
import com.wd.workoffice.util.WorkUtils;

import java.util.Map;

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 MesSearchConditionActivity extends WorkToolBarActivity {
    @BindView(R.id.et_type)
    TextView etType;
    @BindView(R.id.rl_status)
    RelativeLayout rlStatus;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_img_code)
    EditText etImgCode;
    @BindView(R.id.et_spec)
    EditText etSpec;
    @BindView(R.id.et_series)
    EditText etSeries;
    @BindView(R.id.et_weight)
    EditText etWeight;
    @BindView(R.id.et_client)
    EditText etClient;
    @BindView(R.id.et_years)
    EditText etYears;
    @BindView(R.id.et_drawing)
    EditText etDrawing;
    @BindView(R.id.et_section)
    EditText etSection;
    @BindView(R.id.et_steel)
    EditText etSteel;
    @BindView(R.id.srl_refresh)
    NestedScrollView srlRefresh;
    private Map<String, Object> param;
    private QMUIDialog.MenuDialogBuilder statusDialog;
    private String[] statusList = new String[]{"成品", "辅件", "模具", "泥料"};
    private Integer[] statusValue = new Integer[]{0, 1, 2, 3};

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        param = WorkUtils.simpleParam();
        statusDialog = DialogUtils.listDialog(this);
        statusDialog.addItems(statusList, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                etType.setText(statusList[which]);
                dialog.dismiss();
                param.put("productType", statusValue[which]);
            }
        });
    }


    @Override
    protected void initData() {
    }


    @Override
    protected void initEvent() {
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_mes_search_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(etClient.getText().toString())) {
                    param.put("customerUserName", etClient.getText().toString());
                }
                if (!TextUtils.isEmpty(etDrawing.getText().toString())) {
                    param.put("drawingNumberProc", etDrawing.getText().toString());
                }
                if (!TextUtils.isEmpty(etImgCode.getText().toString())) {
                    param.put("drawingNumberProd", etImgCode.getText().toString());
                }
                if (!TextUtils.isEmpty(etName.getText().toString())) {
                    param.put("productName", etName.getText().toString());
                }
                if (!TextUtils.isEmpty(etSection.getText().toString())) {
                    param.put("fractureSurface", etSection.getText().toString());
                }
                if (!TextUtils.isEmpty(etSeries.getText().toString())) {
                    param.put("seriesName", etSeries.getText().toString());
                }
                if (!TextUtils.isEmpty(etSpec.getText().toString())) {
                    param.put("specification", etSpec.getText().toString());
                }
                if (!TextUtils.isEmpty(etSteel.getText().toString())) {
                    param.put("steelGrade", etSteel.getText().toString());
                }
                if (!TextUtils.isEmpty(etWeight.getText().toString())) {
                    param.put("weight", etWeight.getText().toString());
                }
                if (!TextUtils.isEmpty(etYears.getText().toString())) {
                    param.put("designedLife", etYears.getText().toString());
                }
                param.put("materialCode", "306");
                Intent intent = new Intent();
                intent.putExtra("param", JSON.toJSONString(param));
                setResult(10001, intent);
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    @OnClick(R.id.rl_status)
    public void onViewClicked() {
        statusDialog.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
