1cf2d0e4327207bfc7345d7b2b8a4c336ea83059.svn-base 13 KB

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