package com.taikor.investment.modules.customer;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.taikor.investment.R;
import com.taikor.investment.base.BaseActivity;
import com.taikor.investment.mylibrary.TAnalytics;
import com.taikor.investment.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 添加客户
 * Created by Any on 2017/4/5.
 */
public class AddCustomerActivity extends BaseActivity {

    @BindView(R.id.tv_bar_title)
    TextView tvBarTitle;//标题
    @BindView(R.id.et_cus_name)
    EditText etCusName;//客户姓名
    @BindView(R.id.rb_male)
    RadioButton rbMale;//客户性别男
    @BindView(R.id.rb_female)
    RadioButton rbFemale;//客户性别女
    @BindView(R.id.et_cus_phone)
    EditText etCusPhone;//客户手机
    @BindView(R.id.et_cus_groupName)
    EditText etCusGroupName;//组合名称
    @BindView(R.id.et_cus_tab)
    EditText etCusTab;//标签
    @BindView(R.id.et_cus_remark)
    EditText etCusRemark;//备注
    @BindView(R.id.bt_next)
    Button btNext;
    @BindView(R.id.tv_customer_info)
    TextView tvCustomerInfo;
    @BindView(R.id.tv_customer_relative)
    TextView tvCustomerRelative;
    @BindView(R.id.tv_customer_group)
    TextView tvCustomerGroup;
    @BindView(R.id.tv_customer_other)
    TextView tvCustomerOther;

    private String customer_sex = null;

    @Override
    public int getContentViewId() {
        return R.layout.activity_customer_add_customer;
    }

    @Override
    public void initView() {
        //设置drawableRight的图片大小
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.rectangle3);
        drawable.setBounds(0, 0, 10, 50);
        tvCustomerInfo.setCompoundDrawables(drawable, null, null, null);
        tvCustomerOther.setCompoundDrawables(drawable, null, null, null);
        tvCustomerGroup.setCompoundDrawables(drawable, null, null, null);
        tvCustomerRelative.setCompoundDrawables(drawable, null, null, null);
        tvBarTitle.setText("新建客户信息");
    }

    @OnClick({R.id.tv_bar_back, R.id.rb_male, R.id.rb_female, R.id.bt_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_bar_back:
                finish();
                break;
            case R.id.rb_male:
                customer_sex = "男";
                break;
            case R.id.rb_female:
                customer_sex = "女";
                break;
            case R.id.bt_next:
                transmitData();
                break;
        }
    }

    /**
     * 传递数据
     */
    private void transmitData() {
        String customer_name = etCusName.getText().toString();
        if (TextUtils.isEmpty(customer_name) || customer_sex == null) {
            ToastUtils.showShort(AddCustomerActivity.this, "姓名或者性别不能为空");
            return;
        }
        //获取参数，传递下去
        Intent intent = new Intent(this, SetStorageActivity.class);
        intent.putExtra("add_customer", true);
        intent.putExtra("customer_name", customer_name);
        intent.putExtra("customer_sex", customer_sex);
        intent.putExtra("customer_phone", etCusPhone.getText().toString());
        intent.putExtra("group_name", etCusGroupName.getText().toString());
        intent.putExtra("customer_tag", etCusTab.getText().toString());
        intent.putExtra("customer_remark", etCusRemark.getText().toString());
        startActivity(intent);
        finish();
    }

    //埋点
    @Override
    protected void onPostResume() {
        super.onPostResume();
//        TAnalytics.onPageStart("createCustomerPage");
    }

    @Override
    protected void onPause() {
        super.onPause();
//        TAnalytics.onPageLoad("createCustomerPage","customerPage","","");
    }
}
