040c8403e6f384f12f29c194cee8e3a22c14cd69.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package eVVM.apk.ui.login;
  2. import android.app.Activity;
  3. import android.app.Dialog;
  4. import android.content.Intent;
  5. import android.os.Build;
  6. import android.os.Bundle;
  7. import android.os.Environment;
  8. import android.support.annotation.Nullable;
  9. import android.text.TextUtils;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.ImageView;
  15. import android.widget.LinearLayout;
  16. import android.widget.TextView;
  17. import com.hjq.dialog.MessageDialog;
  18. import java.io.File;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.List;
  22. import butterknife.BindView;
  23. import butterknife.ButterKnife;
  24. import butterknife.OnClick;
  25. import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity;
  26. import cn.bingoogolapple.photopicker.imageloader.BGAImage;
  27. import eVVM.apk.R;
  28. import eVVM.apk.helper.InputTextHelper;
  29. import eVVM.apk.helper.basepicker.DataPickerDialog;
  30. import eVVM.apk.mvp.MvpActivity;
  31. import eVVM.apk.ui.bean.VerificationCodeBean;
  32. import eVVM.apk.ui.launcher.LikeActivity;
  33. import eVVM.apk.ui.login.authentication.AttctContract;
  34. import eVVM.apk.ui.login.authentication.AttctPresenter;
  35. import me.jessyan.autosize.utils.AutoSizeUtils;
  36. /**
  37. * 实名认证页
  38. */
  39. public class AuthenticationActivity extends MvpActivity<AttctPresenter> implements AttctContract.View {
  40. @BindView(R.id.attc_et_phone)
  41. EditText attcEtPhone;
  42. @BindView(R.id.attc_et_name)
  43. EditText attcEtName;
  44. @BindView(R.id.attc_et_code)
  45. EditText attcEtCode;
  46. @BindView(R.id.attc_et_email)
  47. EditText attcEtEmail;
  48. @BindView(R.id.attc_et_license)
  49. ImageView attcEtLicense;
  50. @BindView(R.id.attc_et_prove)
  51. ImageView attcEtProve;
  52. @BindView(R.id.attc_btn_register)
  53. Button attcBtnRegister;
  54. @BindView(R.id.tv_information_hospital)
  55. TextView tvInformationHospital;
  56. @BindView(R.id.tv_information_factory)
  57. TextView tvInformationFactory;
  58. @BindView(R.id.attc_ll_license)
  59. LinearLayout attcLlLicense;
  60. @BindView(R.id.attc_ll_prove)
  61. LinearLayout attcLlProve;
  62. private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM");
  63. private static final int REQUEST_LICENSE_CHOOSE_FROM_GALLERY = 1325;
  64. private static final int REQUEST_PROVE_CHOOSE_FROM_GALLERY = 1326;
  65. private String registerUserId;
  66. @Override
  67. protected int getLayoutId() {
  68. return R.layout.activity_authentication;
  69. }
  70. @Override
  71. protected int getTitleId() {
  72. return R.id.attc_title;
  73. }
  74. @Override
  75. public void onLeftClick(View v) {
  76. new MessageDialog.Builder(this)
  77. .setTitle("") // 标题可以不用填写
  78. .setMessage("您未完成实名认证,是否退出")
  79. .setConfirm("确定")
  80. .setCancel("取消") // 设置 null 表示不显示取消按钮
  81. //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
  82. .setListener(new MessageDialog.OnListener() {
  83. @Override
  84. public void onConfirm(Dialog dialog) {
  85. finish();
  86. }
  87. @Override
  88. public void onCancel(Dialog dialog) {
  89. //toast("取消了");
  90. }
  91. })
  92. .show();
  93. }
  94. @Override
  95. protected void initView() {
  96. new InputTextHelper.Builder(this)
  97. .setMain(attcBtnRegister)
  98. .addView(attcEtPhone)
  99. .addView(attcEtName)
  100. .addView(attcEtCode)
  101. .addView(attcEtEmail)
  102. .addView(tvInformationHospital)
  103. .addView(tvInformationFactory)
  104. .build();
  105. Intent in = getIntent();
  106. registerUserId = in.getStringExtra("registerUserId");
  107. }
  108. @Override
  109. protected void initData() {
  110. }
  111. @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})
  112. public void onViewClicked(View view) {
  113. switch (view.getId()) {
  114. case R.id.attc_et_license:
  115. //上传营业执照
  116. /*
  117. 从相册选取二维码图片,这里为了方便演示,使用的是
  118. https://github.com/bingoogolapple/BGAPhotoPicker-Android
  119. 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片
  120. */
  121. Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  122. .cameraFileDir(takePhotoDir)
  123. .maxChooseCount(1)
  124. .selectedPhotos(null)
  125. .pauseOnScroll(false)
  126. .build();
  127. startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  128. break;
  129. case R.id.attc_et_prove:
  130. //上传授权证明
  131. if (uploadimgpaths.size() == 0) {
  132. toast("请先上传营业执照");
  133. } else {
  134. Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  135. .cameraFileDir(takePhotoDir)
  136. .maxChooseCount(1)
  137. .selectedPhotos(null)
  138. .pauseOnScroll(false)
  139. .build();
  140. startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY);
  141. }
  142. break;
  143. case R.id.attc_btn_register:
  144. //进行实名认证
  145. if ("预防接种机构".equals(tvInformationHospital.getText().toString())){
  146. if (uploadimgpaths.size() < 2) {
  147. toast("请上传营业执照及授权证明");
  148. } else {
  149. //String user_id = (String) SPUtils.get("USER_ID", "");
  150. if (TextUtils.isEmpty(registerUserId)) {
  151. } else {
  152. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  153. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  154. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  155. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths);
  156. }
  157. }
  158. }else {
  159. if (TextUtils.isEmpty(registerUserId)) {
  160. } else {
  161. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  162. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  163. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  164. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths);
  165. }
  166. }
  167. break;
  168. case R.id.tv_information_hospital:
  169. DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this);
  170. List<String> data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"});
  171. /*List<RoleTypeBean.RoleParen> parentlist = new ArrayList<>();
  172. parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业"));
  173. parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构"));
  174. parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者"));
  175. parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/
  176. DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题")
  177. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  178. @Override
  179. public void onDataSelected(String itemValue) {
  180. if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  181. tvInformationFactory.setText("");
  182. }
  183. tvInformationHospital.setText(itemValue + "");
  184. if ("预防接种机构".equals(itemValue)){
  185. attcLlLicense.setVisibility(View.VISIBLE);
  186. attcLlProve.setVisibility(View.VISIBLE);
  187. }else {
  188. attcLlLicense.setVisibility(View.GONE);
  189. attcLlProve.setVisibility(View.GONE);
  190. }
  191. }
  192. }).create();
  193. dialog.show();
  194. break;
  195. case R.id.tv_information_factory:
  196. if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  197. toast("请先选择所属类型");
  198. return;
  199. } else {
  200. int roleParentId = getRoleParentId(tvInformationHospital.getText().toString());
  201. List<String> roleType = getRoleType(roleParentId);
  202. DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this);
  203. /*List<String> data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属",
  204. "管理人员", "操作人员","后台管理者"});*/
  205. DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务")
  206. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  207. @Override
  208. public void onDataSelected(String itemValue) {
  209. tvInformationFactory.setText(itemValue + "");
  210. //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show();
  211. }
  212. }).create();
  213. dialog2.show();
  214. }
  215. break;
  216. }
  217. }
  218. //根据parent名字返回id
  219. private int getRoleParentId(String name) {
  220. if ("医药企业".equals(name))
  221. return 6;
  222. if ("预防接种机构".equals(name))
  223. return 7;
  224. if ("预防接受种者".equals(name))
  225. return 8;
  226. if ("物流公司".equals(name))
  227. return 9;
  228. return 0;
  229. }
  230. //根据id返回字列表
  231. private List<String> getRoleType(int parentId) {
  232. List<String> list = new ArrayList<>();
  233. switch (parentId) {
  234. case 6:
  235. list.clear();
  236. list.add("管理员");
  237. list.add("操作员");
  238. list.add("品控人员");
  239. list.add("生产人员");
  240. list.add("物流人员");
  241. list.add("后台管理员");
  242. return list;
  243. case 7:
  244. list.clear();
  245. list.add("医生");
  246. list.add("管理人员");
  247. list.add("护士");
  248. return list;
  249. case 8:
  250. list.clear();
  251. list.add("受种者本人");
  252. list.add("受种者家属");
  253. return list;
  254. case 9:
  255. list.clear();
  256. list.add("管理人员");
  257. list.add("操作人员");
  258. return list;
  259. default:
  260. return null;
  261. }
  262. }
  263. //根据名字返回id
  264. private int getRoleId(String name) {
  265. if ("超级管理员".equals(name))
  266. return 1;
  267. if ("医生".equals(name))
  268. return 2;
  269. if ("管理员".equals(name))
  270. return 3;
  271. if ("操作员".equals(name))
  272. return 4;
  273. if ("受种着本人".equals(name))
  274. return 5;
  275. if ("医药企业".equals(name))
  276. return 6;
  277. if ("预防接种机构".equals(name))
  278. return 7;
  279. if ("预防接种者".equals(name))
  280. return 8;
  281. if ("物流公司".equals(name))
  282. return 9;
  283. if ("其他".equals(name))
  284. return 10;
  285. if ("品控人员".equals(name))
  286. return 11;
  287. if ("生产人员".equals(name))
  288. return 12;
  289. if ("物流人员".equals(name))
  290. return 13;
  291. if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString()))
  292. return 14;
  293. if ("护士".equals(name))
  294. return 15;
  295. if ("受种者家属".equals(name))
  296. return 16;
  297. if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString()))
  298. return 17;
  299. if ("操作人员".equals(name))
  300. return 18;
  301. if ("后台管理者".equals(name))
  302. return 19;
  303. return 0;
  304. }
  305. @Override
  306. protected AttctPresenter createPresenter() {
  307. return new AttctPresenter();
  308. }
  309. @Override
  310. public void attctError(String msg) {
  311. toast(msg);
  312. }
  313. @Override
  314. public void attctSuccess(VerificationCodeBean data) {
  315. toast("注册成功");
  316. startActivityFinish(LikeActivity.class);
  317. }
  318. private List<String> uploadimgpaths = new ArrayList<>();
  319. @Override
  320. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  321. super.onActivityResult(requestCode, resultCode, data);
  322. if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) {
  323. //营业执照回调
  324. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  325. if (uploadimgpaths.size() == 0) { //这里主要是为了让第一张图片必须是营业执照 第二张是授权证明
  326. uploadimgpaths.add(picturePath);
  327. } else if (uploadimgpaths.size() > 0) {
  328. uploadimgpaths.remove(0);
  329. uploadimgpaths.add(0, picturePath);
  330. }
  331. BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  332. Log.e("uploadimgpaths1", "" + uploadimgpaths.toString());
  333. } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) {
  334. //授权证明回调
  335. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  336. if (uploadimgpaths.size() == 2) {
  337. uploadimgpaths.remove(1);
  338. uploadimgpaths.add(picturePath);
  339. } else {
  340. uploadimgpaths.add(picturePath);
  341. }
  342. BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  343. Log.e("uploadimgpaths2", "" + uploadimgpaths.toString());
  344. }
  345. }
  346. }