a5868e6ce6af52c687c82ab958561ea91615be23.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. package eVVM.apk.ui.login;
  2. import android.Manifest;
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Intent;
  6. import android.content.pm.PackageManager;
  7. import android.os.Build;
  8. import android.os.Environment;
  9. import android.support.annotation.NonNull;
  10. import android.support.annotation.Nullable;
  11. import android.support.v4.app.ActivityCompat;
  12. import android.support.v4.content.ContextCompat;
  13. import android.text.TextUtils;
  14. import android.util.Log;
  15. import android.view.View;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.ImageView;
  19. import android.widget.LinearLayout;
  20. import android.widget.TextView;
  21. import com.allen.library.RxHttpUtils;
  22. import com.allen.library.download.DownloadObserver;
  23. import com.hjq.dialog.MessageDialog;
  24. import java.io.File;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.List;
  28. import butterknife.BindView;
  29. import butterknife.OnClick;
  30. import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity;
  31. import cn.bingoogolapple.photopicker.imageloader.BGAImage;
  32. import eVVM.apk.R;
  33. import eVVM.apk.api.ApiUrl;
  34. import eVVM.apk.helper.ImgDonwloads;
  35. import eVVM.apk.helper.InputTextHelper;
  36. import eVVM.apk.helper.basepicker.DataPickerDialog;
  37. import eVVM.apk.mvp.MvpActivity;
  38. import eVVM.apk.ui.bean.VerificationCodeBean;
  39. import eVVM.apk.ui.launcher.LikeActivity;
  40. import eVVM.apk.ui.login.authentication.AttctContract;
  41. import eVVM.apk.ui.login.authentication.AttctPresenter;
  42. import me.jessyan.autosize.utils.AutoSizeUtils;
  43. /**
  44. * 实名认证页
  45. */
  46. public class AuthenticationActivity extends MvpActivity<AttctPresenter> implements AttctContract.View {
  47. @BindView(R.id.attc_et_phone)
  48. EditText attcEtPhone;
  49. @BindView(R.id.attc_et_name)
  50. EditText attcEtName;
  51. @BindView(R.id.attc_et_code)
  52. EditText attcEtCode;
  53. @BindView(R.id.attc_et_email)
  54. EditText attcEtEmail;
  55. @BindView(R.id.attc_et_license)
  56. ImageView attcEtLicense;
  57. @BindView(R.id.attc_et_prove)
  58. ImageView attcEtProve;
  59. @BindView(R.id.attc_btn_register)
  60. Button attcBtnRegister;
  61. @BindView(R.id.tv_information_hospital)
  62. TextView tvInformationHospital;
  63. @BindView(R.id.tv_information_factory)
  64. TextView tvInformationFactory;
  65. @BindView(R.id.attc_ll_license)
  66. LinearLayout attcLlLicense;
  67. @BindView(R.id.attc_ll_prove)
  68. LinearLayout attcLlProve;
  69. @BindView(R.id.attc_et_imgcount)
  70. TextView attcEtImgcount;
  71. private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM");
  72. private static final int REQUEST_LICENSE_CHOOSE_FROM_GALLERY = 1325;
  73. private static final int REQUEST_PROVE_CHOOSE_FROM_GALLERY = 1326;
  74. private String registerUserId;
  75. @Override
  76. protected int getLayoutId() {
  77. return R.layout.activity_authentication;
  78. }
  79. @Override
  80. protected int getTitleId() {
  81. return R.id.attc_title;
  82. }
  83. @Override
  84. public void onLeftClick(View v) {
  85. new MessageDialog.Builder(this)
  86. .setTitle("") // 标题可以不用填写
  87. .setMessage("您未完成实名认证,是否退出")
  88. .setConfirm("确定")
  89. .setCancel("取消") // 设置 null 表示不显示取消按钮
  90. //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
  91. .setListener(new MessageDialog.OnListener() {
  92. @Override
  93. public void onConfirm(Dialog dialog) {
  94. finish();
  95. }
  96. @Override
  97. public void onCancel(Dialog dialog) {
  98. //toast("取消了");
  99. }
  100. })
  101. .show();
  102. }
  103. @Override
  104. protected void initView() {
  105. new InputTextHelper.Builder(this)
  106. .setMain(attcBtnRegister)
  107. .addView(attcEtPhone)
  108. .addView(attcEtName)
  109. .addView(attcEtCode)
  110. .addView(attcEtEmail)
  111. .addView(tvInformationHospital)
  112. .addView(tvInformationFactory)
  113. .build();
  114. Intent in = getIntent();
  115. registerUserId = in.getStringExtra("registerUserId");
  116. Button downloadBtn = (Button) findViewById(R.id.download_btn);
  117. // download() ;
  118. downloadBtn.setOnClickListener(new View.OnClickListener() {
  119. @Override
  120. public void onClick(View v) {
  121. List<String> permissionList = new ArrayList<>();
  122. if (ContextCompat.checkSelfPermission(AuthenticationActivity.this,
  123. Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
  124. permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
  125. }
  126. if (!permissionList.isEmpty()) {
  127. String[] permissions = permissionList.toArray(new String[permissionList.size()]);
  128. ActivityCompat.requestPermissions(AuthenticationActivity.this, permissions, 1);
  129. } else {
  130. ImgDonwloads.donwloadImg(AuthenticationActivity.this, ApiUrl.authPath);//iPath
  131. }
  132. }
  133. });
  134. }
  135. @Override
  136. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  137. switch (requestCode) {
  138. case 1:
  139. if (grantResults.length > 0) {
  140. for (int result : grantResults) {
  141. if (result != PackageManager.PERMISSION_GRANTED) {
  142. toast("拒绝了权限");
  143. return;
  144. }
  145. }
  146. ImgDonwloads.donwloadImg(AuthenticationActivity.this, "");
  147. } else {
  148. toast("发生未知错误");
  149. }
  150. break;
  151. default:
  152. }
  153. }
  154. @Override
  155. protected void initData() {
  156. }
  157. @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})
  158. public void onViewClicked(View view) {
  159. switch (view.getId()) {
  160. case R.id.attc_et_license:
  161. //上传营业执照
  162. /*
  163. 从相册选取二维码图片,这里为了方便演示,使用的是
  164. https://github.com/bingoogolapple/BGAPhotoPicker-Android
  165. 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片
  166. */
  167. Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  168. .cameraFileDir(takePhotoDir)
  169. .maxChooseCount(3)
  170. .selectedPhotos(null)
  171. .pauseOnScroll(false)
  172. .build();
  173. startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  174. break;
  175. case R.id.attc_et_prove:
  176. //上传授权证明
  177. if (uploadimgpaths1.size() == 0) {
  178. toast("请先选择营业执照");
  179. } else {
  180. Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  181. .cameraFileDir(takePhotoDir)
  182. .maxChooseCount(1)
  183. .selectedPhotos(null)
  184. .pauseOnScroll(false)
  185. .build();
  186. startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY);
  187. }
  188. break;
  189. case R.id.attc_btn_register:
  190. //进行实名认证
  191. List<String> uploadimgpaths3 = new ArrayList<>();
  192. if ("预防接种机构".equals(tvInformationHospital.getText().toString())) {
  193. if (uploadimgpaths1.size() == 0 || uploadimgpaths2.size() == 0) {
  194. toast("请选择营业执照及授权证明");
  195. } else {
  196. uploadimgpaths3.clear();
  197. uploadimgpaths3.addAll(uploadimgpaths1);
  198. uploadimgpaths3.addAll(uploadimgpaths2);
  199. //String user_id = (String) SPUtils.get("USER_ID", "");
  200. if (TextUtils.isEmpty(registerUserId)) {
  201. Log.e("getPresenterattct", "" + uploadimgpaths3.toString());
  202. } else {
  203. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  204. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  205. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  206. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  207. }
  208. }
  209. } else {
  210. if (TextUtils.isEmpty(registerUserId)) {
  211. } else {
  212. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  213. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  214. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  215. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  216. }
  217. }
  218. break;
  219. case R.id.tv_information_hospital:
  220. DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this);
  221. List<String> data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"});
  222. /*List<RoleTypeBean.RoleParen> parentlist = new ArrayList<>();
  223. parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业"));
  224. parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构"));
  225. parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者"));
  226. parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/
  227. DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题")
  228. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  229. @Override
  230. public void onDataSelected(String itemValue) {
  231. if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  232. tvInformationFactory.setText("");
  233. }
  234. tvInformationHospital.setText(itemValue + "");
  235. if ("预防接种机构".equals(itemValue)) {
  236. attcLlLicense.setVisibility(View.VISIBLE);
  237. attcLlProve.setVisibility(View.VISIBLE);
  238. } else {
  239. attcLlLicense.setVisibility(View.GONE);
  240. attcLlProve.setVisibility(View.GONE);
  241. }
  242. }
  243. }).create();
  244. dialog.show();
  245. break;
  246. case R.id.tv_information_factory:
  247. if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  248. toast("请先选择所属类型");
  249. return;
  250. } else {
  251. int roleParentId = getRoleParentId(tvInformationHospital.getText().toString());
  252. List<String> roleType = getRoleType(roleParentId);
  253. DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this);
  254. /*List<String> data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属",
  255. "管理人员", "操作人员","后台管理者"});*/
  256. DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务")
  257. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  258. @Override
  259. public void onDataSelected(String itemValue) {
  260. tvInformationFactory.setText(itemValue + "");
  261. //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show();
  262. }
  263. }).create();
  264. dialog2.show();
  265. }
  266. break;
  267. /*case R.id.download_btn:
  268. //toast("下载");
  269. //下载的图片路径
  270. String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1560345333671&di=3642b27a83162af116af51289ec4d11f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2191520521%2C2689315141%26fm%3D214%26gp%3D0.jpg";
  271. final String fileName = "evvmproveimg.jpg"; //文件名 注意结尾要加后缀
  272. RxHttpUtils
  273. .downloadFile(url)
  274. //.subscribe(new DownloadObserver(fileName,destFileDir) 其中 destFileDir是自定义下载存储路径
  275. .subscribe(new DownloadObserver(fileName, Environment.getExternalStorageDirectory().getPath()) {
  276. //可以通过配置tag用于取消下载请求
  277. @Override
  278. protected String setTag() {
  279. return "download";
  280. }
  281. @Override
  282. protected void onError(String errorMsg) {
  283. toast(errorMsg);
  284. }
  285. @Override
  286. protected void onSuccess(long bytesRead, long contentLength, float progress, boolean done, String filePath) {
  287. btnProveDownload.setText("" + progress + "%");
  288. if (done) {
  289. btnProveDownload.setText("下载\n完成");
  290. toast("下载完成,请上传");
  291. }
  292. }
  293. });
  294. break;*/
  295. }
  296. }
  297. //根据parent名字返回id
  298. private int getRoleParentId(String name) {
  299. if ("医药企业".equals(name))
  300. return 6;
  301. if ("预防接种机构".equals(name))
  302. return 7;
  303. if ("预防接受种者".equals(name))
  304. return 8;
  305. if ("物流公司".equals(name))
  306. return 9;
  307. return 0;
  308. }
  309. //根据id返回字列表
  310. private List<String> getRoleType(int parentId) {
  311. List<String> list = new ArrayList<>();
  312. switch (parentId) {
  313. case 6:
  314. list.clear();
  315. list.add("管理员");
  316. list.add("操作员");
  317. list.add("品控人员");
  318. list.add("生产人员");
  319. list.add("物流人员");
  320. list.add("后台管理员");
  321. return list;
  322. case 7:
  323. list.clear();
  324. list.add("医生");
  325. list.add("管理人员");
  326. list.add("护士");
  327. return list;
  328. case 8:
  329. list.clear();
  330. list.add("受种者本人");
  331. list.add("受种者家属");
  332. return list;
  333. case 9:
  334. list.clear();
  335. list.add("管理人员");
  336. list.add("操作人员");
  337. return list;
  338. default:
  339. return null;
  340. }
  341. }
  342. //根据名字返回id
  343. private int getRoleId(String name) {
  344. if ("超级管理员".equals(name))
  345. return 1;
  346. if ("医生".equals(name))
  347. return 2;
  348. if ("管理员".equals(name))
  349. return 3;
  350. if ("操作员".equals(name))
  351. return 4;
  352. if ("受种着本人".equals(name))
  353. return 5;
  354. if ("医药企业".equals(name))
  355. return 6;
  356. if ("预防接种机构".equals(name))
  357. return 7;
  358. if ("预防接种者".equals(name))
  359. return 8;
  360. if ("物流公司".equals(name))
  361. return 9;
  362. if ("其他".equals(name))
  363. return 10;
  364. if ("品控人员".equals(name))
  365. return 11;
  366. if ("生产人员".equals(name))
  367. return 12;
  368. if ("物流人员".equals(name))
  369. return 13;
  370. if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString()))
  371. return 14;
  372. if ("护士".equals(name))
  373. return 15;
  374. if ("受种者家属".equals(name))
  375. return 16;
  376. if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString()))
  377. return 17;
  378. if ("操作人员".equals(name))
  379. return 18;
  380. if ("后台管理者".equals(name))
  381. return 19;
  382. return 0;
  383. }
  384. @Override
  385. protected AttctPresenter createPresenter() {
  386. return new AttctPresenter();
  387. }
  388. @Override
  389. public void attctError(String msg) {
  390. toast(msg);
  391. }
  392. @Override
  393. public void attctSuccess(VerificationCodeBean data) {
  394. // Log.e("attctSuccessVN",data.getData().toString()+data.getMsg());
  395. toast("注册成功");
  396. Intent in = new Intent(this, LikeActivity.class);
  397. in.putExtra("LikeUserId", "" + Double.valueOf(String.valueOf(data.getData())).intValue());
  398. in.putExtra("LikeRoleId", getRoleId(tvInformationFactory.getText().toString()) + "");
  399. startActivityFinish(in);
  400. }
  401. private List<String> uploadimgpaths1 = new ArrayList<>();
  402. private List<String> uploadimgpaths2 = new ArrayList<>();
  403. @Override
  404. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  405. super.onActivityResult(requestCode, resultCode, data);
  406. if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) {
  407. //营业执照回调
  408. List<String> selectedPhotos = BGAPhotoPickerActivity.getSelectedPhotos(data);
  409. uploadimgpaths1.clear();
  410. uploadimgpaths1.addAll(selectedPhotos);
  411. attcEtImgcount.setText("照片数量:" + uploadimgpaths1.size() + "张");
  412. BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, selectedPhotos.get(0), AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  413. Log.e("uploadimgpaths1", "" + uploadimgpaths1.toString());
  414. } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) {
  415. //授权证明回调
  416. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  417. uploadimgpaths2.clear();
  418. uploadimgpaths2.add(picturePath);
  419. BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  420. Log.e("uploadimgpaths2", "" + uploadimgpaths2.toString());
  421. }
  422. }
  423. }