add-identity.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="identity-box">
  3. <!-- <view class="identity-title">上传身份证图片 ,图片大小不能超过3M</view>-->
  4. <view class="size-30 sys-weight-600'">身份认证</view>
  5. <view class="size-26 m-t20 m-b30 text-color-999">应监管要求,请先进行身份认证</view>
  6. <view class="identity-item m-t10">
  7. <view class="item-img" @click="showUploadingImg(true,1)">
  8. <view class="img-bg">
  9. <image v-if="identity_one" :src="identity_one" mode="aspectFill"></image>
  10. <image v-else src="@/page_task/static/img/identity-front.png" mode="aspectFill"></image>
  11. </view>
  12. <view class="img-text">身份证正面</view>
  13. </view>
  14. <view class="item-img" @click="showUploadingImg(true,2)">
  15. <view class="img-bg">
  16. <image v-if="identity_two" :src="identity_two" mode="aspectFill"></image>
  17. <image v-else src="@/page_task/static/img/identity-verso.png" mode="aspectFill"></image>
  18. </view>
  19. <view class="img-text">身份证反面</view>
  20. </view>
  21. </view>
  22. <uni-popup ref="popup" :safeArea="false" type="bottom" @change="closePopup">
  23. <view class="popup-block">
  24. <view class="popup-row" @click="uploadingImg(1)">拍照</view>
  25. <view class="popup-row" @click="uploadingImg(2)">从手机里面选择</view>
  26. <view class="popup-row" @click="showUploadingImg(false,0)">取消</view>
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. getBaiDuImgRecognition
  34. } from "@/api/common";
  35. import txUploadFile from "@/service/txOssSts";
  36. import tools from "@/service/tools";
  37. export default {
  38. name: "add-identity",
  39. components: {},
  40. props: {
  41. 'identityOne': {
  42. default: '',
  43. },
  44. 'identityTwo': {
  45. default: '',
  46. },
  47. 'userName': {
  48. default: '',
  49. },
  50. 'userSex': {
  51. default: '',
  52. },
  53. 'identityValidity': {
  54. default: '',
  55. },
  56. 'userBirthday': {
  57. default: '',
  58. },
  59. 'idNumber': {
  60. default: '',
  61. }
  62. },
  63. data() {
  64. return {
  65. identity_one: '',
  66. identity_two: '',
  67. name: '',
  68. id_number: '',
  69. sex: '',
  70. identity_validity: '',
  71. isUploading: false,
  72. }
  73. },
  74. watch: {
  75. 'identityOne': function() {
  76. this.setIdentityOne()
  77. },
  78. 'identityTwo': function() {
  79. this.setIdentityTwo()
  80. }
  81. },
  82. mounted() {
  83. this.setIdentityOne()
  84. this.setIdentityTwo()
  85. },
  86. methods: {
  87. setIdentityOne() {
  88. if (this.identityOne) {
  89. if (this.identityOne !== this.identity_one) {
  90. this.identity_one = this.identityOne
  91. }
  92. }
  93. },
  94. setIdentityTwo() {
  95. if (this.identityTwo) {
  96. if (this.identityTwo !== this.identity_two) {
  97. this.identity_two = this.identityTwo
  98. }
  99. }
  100. },
  101. uploadingImg(sourceType) {
  102. console.log('sourceType:' + sourceType)
  103. uni.chooseMedia({
  104. mediaType: 'image',
  105. count: 1, //默认9
  106. sizeType: "compressed",
  107. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  108. fail: (e) => {
  109. console.log(e)
  110. },
  111. success: (res) => {
  112. if (res.tempFiles.length > 0) {
  113. console.log(res.tempFiles)
  114. res.tempFiles.forEach((tempFile) => {
  115. txUploadFile(tempFile.tempFilePath).then((data) => {
  116. if (!data) {
  117. tools.error('图片上传失败')
  118. tools.hideLoading()
  119. } else {
  120. if (this.uploadingType === 1) {
  121. tools.showLoading()
  122. //开启身份证照片识别
  123. getBaiDuImgRecognition({
  124. 'imgUrl': data.Location,
  125. 'imgType': '1'
  126. }).then((res) => {
  127. tools.hideLoading()
  128. if (res.code === 1) {
  129. this.identity_one = data.Location;
  130. this.name = res.data.name;
  131. this.id_number = res.data
  132. .id_number;
  133. this.sex = res.data.sex;
  134. this.birthday = res.data.birthday;
  135. this.$emit('update:userName', this
  136. .name)
  137. this.$emit('update:userBirthday',
  138. this.birthday)
  139. this.$emit('update:userSex', this
  140. .sex)
  141. this.$emit('update:idNumber', this
  142. .id_number)
  143. this.$emit('update:identityOne',
  144. this.identity_one)
  145. } else {
  146. tools.error('身份证照片识别失败')
  147. }
  148. })
  149. } else {
  150. tools.showLoading()
  151. //开启身份证照片背面识别
  152. getBaiDuImgRecognition({
  153. 'imgUrl': data.Location,
  154. 'imgType': '4'
  155. }).then((res) => {
  156. tools.hideLoading()
  157. if (res.code === 1) {
  158. this.identity_two = data.Location;
  159. this.identity_validity = res.data
  160. .identity_validity;
  161. this.$emit('update:identityTwo',
  162. this.identity_two)
  163. this.$emit(
  164. 'update:identityValidity',
  165. this.identity_validity)
  166. } else {
  167. tools.error('身份证照片识别失败')
  168. }
  169. })
  170. }
  171. }
  172. })
  173. })
  174. this.showUploadingImg(false, 0);
  175. } else {
  176. tools.error("请选择上传的图片")
  177. }
  178. },
  179. });
  180. },
  181. showUploadingImg(showImg, uploadingType) {
  182. if (showImg) {
  183. if (this.isUploading) {
  184. return
  185. }
  186. this.isUploading = true
  187. this.uploadingType = uploadingType;
  188. this.$refs.popup.open("bottom");
  189. } else {
  190. this.$refs.popup.close();
  191. this.isUploading = false
  192. }
  193. },
  194. closePopup(e) {
  195. if (e.show === false) {
  196. this.isUploading = false
  197. }
  198. },
  199. }
  200. }
  201. </script>
  202. <style scoped lang="scss">
  203. @import "@/static/css/wh-common";
  204. .identity-box {
  205. .identity-title {
  206. padding: 20rpx 0;
  207. font-size: 24rpx;
  208. color: #999;
  209. font-weight: 400;
  210. }
  211. .identity-item {
  212. display: flex;
  213. justify-content: space-between;
  214. padding-bottom: 20rpx;
  215. .item-img {
  216. width: calc(50% - 10rpx);
  217. .img-bg {
  218. padding: 20rpx;
  219. background: #F7F9FE;
  220. border-radius: 20rpx 20rpx 0rpx 0rpx;
  221. }
  222. image {
  223. width: 100%;
  224. height: 165rpx;
  225. border-radius: 6rpx;
  226. }
  227. .img-text {
  228. text-align: center;
  229. color: #ffffff;
  230. font-size: 24rpx;
  231. font-weight: 400;
  232. height: 60rpx;
  233. line-height: 60rpx;
  234. background: #0FB160;
  235. border-radius: 0rpx 0rpx 20rpx 20rpx;
  236. }
  237. }
  238. }
  239. }
  240. </style>