06fb3396a1c058a951952a631b193634e1038105.svn-base 18 KB

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