package eVVM.apk.ui.login; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.hjq.dialog.MessageDialog; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity; import cn.bingoogolapple.photopicker.imageloader.BGAImage; import eVVM.apk.R; import eVVM.apk.helper.InputTextHelper; import eVVM.apk.helper.basepicker.DataPickerDialog; import eVVM.apk.mvp.MvpActivity; import eVVM.apk.ui.bean.VerificationCodeBean; import eVVM.apk.ui.launcher.LikeActivity; import eVVM.apk.ui.login.authentication.AttctContract; import eVVM.apk.ui.login.authentication.AttctPresenter; import me.jessyan.autosize.utils.AutoSizeUtils; /** * 实名认证页 */ public class AuthenticationActivity extends MvpActivity implements AttctContract.View { @BindView(R.id.attc_et_phone) EditText attcEtPhone; @BindView(R.id.attc_et_name) EditText attcEtName; @BindView(R.id.attc_et_code) EditText attcEtCode; @BindView(R.id.attc_et_email) EditText attcEtEmail; @BindView(R.id.attc_et_license) ImageView attcEtLicense; @BindView(R.id.attc_et_prove) ImageView attcEtProve; @BindView(R.id.attc_btn_register) Button attcBtnRegister; @BindView(R.id.tv_information_hospital) TextView tvInformationHospital; @BindView(R.id.tv_information_factory) TextView tvInformationFactory; @BindView(R.id.attc_ll_license) LinearLayout attcLlLicense; @BindView(R.id.attc_ll_prove) LinearLayout attcLlProve; private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM"); private static final int REQUEST_LICENSE_CHOOSE_FROM_GALLERY = 1325; private static final int REQUEST_PROVE_CHOOSE_FROM_GALLERY = 1326; private String registerUserId; @Override protected int getLayoutId() { return R.layout.activity_authentication; } @Override protected int getTitleId() { return R.id.attc_title; } @Override public void onLeftClick(View v) { new MessageDialog.Builder(this) .setTitle("") // 标题可以不用填写 .setMessage("您未完成实名认证,是否退出") .setConfirm("确定") .setCancel("取消") // 设置 null 表示不显示取消按钮 //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框 .setListener(new MessageDialog.OnListener() { @Override public void onConfirm(Dialog dialog) { finish(); } @Override public void onCancel(Dialog dialog) { //toast("取消了"); } }) .show(); } @Override protected void initView() { new InputTextHelper.Builder(this) .setMain(attcBtnRegister) .addView(attcEtPhone) .addView(attcEtName) .addView(attcEtCode) .addView(attcEtEmail) .addView(tvInformationHospital) .addView(tvInformationFactory) .build(); Intent in = getIntent(); registerUserId = in.getStringExtra("registerUserId"); } @Override protected void initData() { } @OnClick({R.id.attc_et_license, R.id.attc_et_prove, R.id.attc_btn_register, R.id.tv_information_hospital, R.id.tv_information_factory}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.attc_et_license: //上传营业执照 /* 从相册选取二维码图片,这里为了方便演示,使用的是 https://github.com/bingoogolapple/BGAPhotoPicker-Android 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片 */ Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this) .cameraFileDir(takePhotoDir) .maxChooseCount(1) .selectedPhotos(null) .pauseOnScroll(false) .build(); startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY); break; case R.id.attc_et_prove: //上传授权证明 if (uploadimgpaths.size() == 0) { toast("请先上传营业执照"); } else { Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this) .cameraFileDir(takePhotoDir) .maxChooseCount(1) .selectedPhotos(null) .pauseOnScroll(false) .build(); startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY); } break; case R.id.attc_btn_register: //进行实名认证 if ("预防接种机构".equals(tvInformationHospital.getText().toString())){ if (uploadimgpaths.size() < 2) { toast("请上传营业执照及授权证明"); } else { //String user_id = (String) SPUtils.get("USER_ID", ""); if (TextUtils.isEmpty(registerUserId)) { } else { getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString() , attcEtName.getText().toString(), attcEtCode.getText().toString(), attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "", 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths); } } }else { if (TextUtils.isEmpty(registerUserId)) { } else { getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString() , attcEtName.getText().toString(), attcEtCode.getText().toString(), attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "", 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths); } } break; case R.id.tv_information_hospital: DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this); List data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"}); /*List parentlist = new ArrayList<>(); parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业")); parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构")); parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者")); parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/ DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题") .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() { @Override public void onDataSelected(String itemValue) { if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) { tvInformationFactory.setText(""); } tvInformationHospital.setText(itemValue + ""); if ("预防接种机构".equals(itemValue)){ attcLlLicense.setVisibility(View.VISIBLE); attcLlProve.setVisibility(View.VISIBLE); }else { attcLlLicense.setVisibility(View.GONE); attcLlProve.setVisibility(View.GONE); } } }).create(); dialog.show(); break; case R.id.tv_information_factory: if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) { toast("请先选择所属类型"); return; } else { int roleParentId = getRoleParentId(tvInformationHospital.getText().toString()); List roleType = getRoleType(roleParentId); DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this); /*List data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属", "管理人员", "操作人员","后台管理者"});*/ DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务") .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() { @Override public void onDataSelected(String itemValue) { tvInformationFactory.setText(itemValue + ""); //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show(); } }).create(); dialog2.show(); } break; } } //根据parent名字返回id private int getRoleParentId(String name) { if ("医药企业".equals(name)) return 6; if ("预防接种机构".equals(name)) return 7; if ("预防接受种者".equals(name)) return 8; if ("物流公司".equals(name)) return 9; return 0; } //根据id返回字列表 private List getRoleType(int parentId) { List list = new ArrayList<>(); switch (parentId) { case 6: list.clear(); list.add("管理员"); list.add("操作员"); list.add("品控人员"); list.add("生产人员"); list.add("物流人员"); list.add("后台管理员"); return list; case 7: list.clear(); list.add("医生"); list.add("管理人员"); list.add("护士"); return list; case 8: list.clear(); list.add("受种者本人"); list.add("受种者家属"); return list; case 9: list.clear(); list.add("管理人员"); list.add("操作人员"); return list; default: return null; } } //根据名字返回id private int getRoleId(String name) { if ("超级管理员".equals(name)) return 1; if ("医生".equals(name)) return 2; if ("管理员".equals(name)) return 3; if ("操作员".equals(name)) return 4; if ("受种着本人".equals(name)) return 5; if ("医药企业".equals(name)) return 6; if ("预防接种机构".equals(name)) return 7; if ("预防接种者".equals(name)) return 8; if ("物流公司".equals(name)) return 9; if ("其他".equals(name)) return 10; if ("品控人员".equals(name)) return 11; if ("生产人员".equals(name)) return 12; if ("物流人员".equals(name)) return 13; if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString())) return 14; if ("护士".equals(name)) return 15; if ("受种者家属".equals(name)) return 16; if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString())) return 17; if ("操作人员".equals(name)) return 18; if ("后台管理者".equals(name)) return 19; return 0; } @Override protected AttctPresenter createPresenter() { return new AttctPresenter(); } @Override public void attctError(String msg) { toast(msg); } @Override public void attctSuccess(VerificationCodeBean data) { toast("注册成功"); Intent in = new Intent(this,LikeActivity.class); in.putExtra("LikeUserId",""+Double.valueOf(String.valueOf(data.getData())).intValue()); in.putExtra("LikeRoleId",getRoleId(tvInformationFactory.getText().toString()) + ""); startActivityFinish(in); } private List uploadimgpaths = new ArrayList<>(); @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) { //营业执照回调 String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0); if (uploadimgpaths.size() == 0) { //这里主要是为了让第一张图片必须是营业执照 第二张是授权证明 uploadimgpaths.add(picturePath); } else if (uploadimgpaths.size() > 0) { uploadimgpaths.remove(0); uploadimgpaths.add(0, picturePath); } BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43)); Log.e("uploadimgpaths1", "" + uploadimgpaths.toString()); } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) { //授权证明回调 String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0); if (uploadimgpaths.size() == 2) { uploadimgpaths.remove(1); uploadimgpaths.add(picturePath); } else { uploadimgpaths.add(picturePath); } BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43)); Log.e("uploadimgpaths2", "" + uploadimgpaths.toString()); } } }