4a0516f4363161d7879f3a63c786f5ddf79f2924.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. 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. getPresenter().attct(Integer.parseInt(registerUserId),companyId+""
  219. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  220. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  221. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  222. }
  223. }
  224. } else {
  225. if (TextUtils.isEmpty(registerUserId)) {
  226. } else {
  227. List<String> emptyList = new ArrayList<>();
  228. getPresenter().attct(Integer.parseInt(registerUserId), companyId+""
  229. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  230. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  231. 0, Build.BRAND + " " + Build.MODEL, emptyList);
  232. }
  233. }
  234. break;
  235. case R.id.tv_information_hospital:
  236. DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this);
  237. List<String> data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"});
  238. /*List<RoleTypeBean.RoleParen> parentlist = new ArrayList<>();
  239. parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业"));
  240. parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构"));
  241. parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者"));
  242. parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/
  243. DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题")
  244. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  245. @Override
  246. public void onDataSelected(String itemValue) {
  247. if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  248. tvInformationFactory.setText("");
  249. }
  250. tvInformationHospital.setText(itemValue + "");
  251. if ("预防接种机构".equals(itemValue)) {
  252. attcLlLicense.setVisibility(View.VISIBLE);
  253. attcLlProve.setVisibility(View.VISIBLE);
  254. } else {
  255. attcLlLicense.setVisibility(View.GONE);
  256. attcLlProve.setVisibility(View.GONE);
  257. }
  258. }
  259. }).create();
  260. dialog.show();
  261. break;
  262. case R.id.tv_information_factory:
  263. if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  264. toast("请先选择所属类型");
  265. return;
  266. } else {
  267. int roleParentId = getRoleParentId(tvInformationHospital.getText().toString());
  268. List<String> roleType = getRoleType(roleParentId);
  269. DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this);
  270. /*List<String> data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属",
  271. "管理人员", "操作人员","后台管理者"});*/
  272. DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务")
  273. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  274. @Override
  275. public void onDataSelected(String itemValue) {
  276. tvInformationFactory.setText(itemValue + "");
  277. //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show();
  278. }
  279. }).create();
  280. dialog2.show();
  281. }
  282. break;
  283. case R.id.attc_et_phone:
  284. startActivity(CompanyChooseActivity.class);
  285. break;
  286. /*case R.id.download_btn:
  287. //toast("下载");
  288. //下载的图片路径
  289. 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";
  290. final String fileName = "evvmproveimg.jpg"; //文件名 注意结尾要加后缀
  291. RxHttpUtils
  292. .downloadFile(url)
  293. //.subscribe(new DownloadObserver(fileName,destFileDir) 其中 destFileDir是自定义下载存储路径
  294. .subscribe(new DownloadObserver(fileName, Environment.getExternalStorageDirectory().getPath()) {
  295. //可以通过配置tag用于取消下载请求
  296. @Override
  297. protected String setTag() {
  298. return "download";
  299. }
  300. @Override
  301. protected void onError(String errorMsg) {
  302. toast(errorMsg);
  303. }
  304. @Override
  305. protected void onSuccess(long bytesRead, long contentLength, float progress, boolean done, String filePath) {
  306. btnProveDownload.setText("" + progress + "%");
  307. if (done) {
  308. btnProveDownload.setText("下载\n完成");
  309. toast("下载完成,请上传");
  310. }
  311. }
  312. });
  313. break;*/
  314. }
  315. }
  316. //根据parent名字返回id
  317. private int getRoleParentId(String name) {
  318. if ("医药企业".equals(name))
  319. return 6;
  320. if ("预防接种机构".equals(name))
  321. return 7;
  322. if ("预防接受种者".equals(name))
  323. return 8;
  324. if ("物流公司".equals(name))
  325. return 9;
  326. return 0;
  327. }
  328. @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
  329. public void onEvent(CompanyEvent event) {
  330. attcEtPhone.setText(event.getCompanyName());
  331. tvInformationFactory.setText("");
  332. companyId = event.getCompanyId();
  333. if (event.getType() == 1) {
  334. tvInformationHospital.setText("医药企业");
  335. attcLlLicense.setVisibility(View.GONE);
  336. attcLlProve.setVisibility(View.GONE);
  337. } else if (event.getType() == 2) {
  338. tvInformationHospital.setText("预防接种机构");
  339. attcLlLicense.setVisibility(View.VISIBLE);
  340. attcLlProve.setVisibility(View.VISIBLE);
  341. } else {
  342. }
  343. }
  344. //根据id返回字列表
  345. private List<String> getRoleType(int parentId) {
  346. List<String> list = new ArrayList<>();
  347. switch (parentId) {
  348. case 6:
  349. list.clear();
  350. list.add("管理员");
  351. list.add("操作员");
  352. list.add("品控人员");
  353. list.add("生产人员");
  354. list.add("物流人员");
  355. list.add("后台管理员");
  356. return list;
  357. case 7:
  358. list.clear();
  359. list.add("医生");
  360. list.add("管理人员");
  361. list.add("护士");
  362. return list;
  363. case 8:
  364. list.clear();
  365. list.add("受种者本人");
  366. list.add("受种者家属");
  367. return list;
  368. case 9:
  369. list.clear();
  370. list.add("管理人员");
  371. list.add("操作人员");
  372. return list;
  373. default:
  374. return null;
  375. }
  376. }
  377. //根据名字返回id
  378. private int getRoleId(String name) {
  379. if ("超级管理员".equals(name))
  380. return 1;
  381. if ("医生".equals(name))
  382. return 2;
  383. if ("管理员".equals(name))
  384. return 3;
  385. if ("操作员".equals(name))
  386. return 4;
  387. if ("受种着本人".equals(name))
  388. return 5;
  389. if ("医药企业".equals(name))
  390. return 6;
  391. if ("预防接种机构".equals(name))
  392. return 7;
  393. if ("预防接种者".equals(name))
  394. return 8;
  395. if ("物流公司".equals(name))
  396. return 9;
  397. if ("其他".equals(name))
  398. return 10;
  399. if ("品控人员".equals(name))
  400. return 11;
  401. if ("生产人员".equals(name))
  402. return 12;
  403. if ("物流人员".equals(name))
  404. return 13;
  405. if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString()))
  406. return 14;
  407. if ("护士".equals(name))
  408. return 15;
  409. if ("受种者家属".equals(name))
  410. return 16;
  411. if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString()))
  412. return 17;
  413. if ("操作人员".equals(name))
  414. return 18;
  415. if ("后台管理者".equals(name))
  416. return 19;
  417. return 0;
  418. }
  419. @Override
  420. protected AttctPresenter createPresenter() {
  421. return new AttctPresenter();
  422. }
  423. @Override
  424. public void attctError(String msg) {
  425. toast(msg);
  426. }
  427. @Override
  428. public void attctSuccess(VerificationCodeBean data) {
  429. // Log.e("attctSuccessVN",data.getData().toString()+data.getMsg());
  430. toast("注册成功");
  431. Intent in = new Intent(this, LikeActivity.class);
  432. in.putExtra("LikeUserId", "" + Double.valueOf(String.valueOf(data.getData())).intValue());
  433. in.putExtra("LikeRoleId", getRoleId(tvInformationFactory.getText().toString()) + "");
  434. startActivityFinish(in);
  435. }
  436. private List<String> uploadimgpaths1 = new ArrayList<>();
  437. private List<String> uploadimgpaths2 = new ArrayList<>();
  438. @Override
  439. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  440. super.onActivityResult(requestCode, resultCode, data);
  441. if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) {
  442. //执业执照回调
  443. List<String> selectedPhotos = BGAPhotoPickerActivity.getSelectedPhotos(data);
  444. uploadimgpaths1.clear();
  445. uploadimgpaths1.addAll(selectedPhotos);
  446. //attcEtImgcount.setText("照片数量:" + uploadimgpaths1.size() + "张");
  447. // BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, selectedPhotos.get(0), AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  448. mPhotosSnpl.addMoreData(BGAPhotoPickerActivity.getSelectedPhotos(data));
  449. Log.e("uploadimgpaths1", "" + uploadimgpaths1.toString());
  450. } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) {
  451. //授权证明回调
  452. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  453. uploadimgpaths2.clear();
  454. uploadimgpaths2.add(picturePath);
  455. BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  456. Log.e("uploadimgpaths2", "" + uploadimgpaths2.toString());
  457. }
  458. }
  459. @Override
  460. public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList<String> models) {
  461. Intent photoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  462. .cameraFileDir(takePhotoDir) // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能
  463. .maxChooseCount(mPhotosSnpl.getMaxItemCount() - mPhotosSnpl.getItemCount()) // 图片选择张数的最大值
  464. .selectedPhotos(null) // 当前已选中的图片路径集合
  465. .pauseOnScroll(false) // 滚动列表时是否暂停加载图片
  466. .build();
  467. startActivityForResult(photoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  468. }
  469. @Override
  470. public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
  471. mPhotosSnpl.removeItem(position);
  472. }
  473. @Override
  474. public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
  475. Intent photoPickerPreviewIntent = new BGAPhotoPickerPreviewActivity.IntentBuilder(this)
  476. .previewPhotos(models) // 当前预览的图片路径集合
  477. .selectedPhotos(models) // 当前已选中的图片路径集合
  478. .maxChooseCount(mPhotosSnpl.getMaxItemCount()) // 图片选择张数的最大值
  479. .currentPosition(position) // 当前预览图片的索引
  480. .isFromTakePhoto(false) // 是否是拍完照后跳转过来
  481. .build();
  482. startActivityForResult(photoPickerPreviewIntent, REQUEST_LICENSE_PHOTO_PREVIEW);
  483. }
  484. @Override
  485. public void onNinePhotoItemExchanged(BGASortableNinePhotoLayout sortableNinePhotoLayout, int fromPosition, int toPosition, ArrayList<String> models) {
  486. }
  487. }