821474da03b0e3052fdd8b3556ee8a7b3cf6e67d.svn-base 23 KB

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