add-identity.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. res.tempFiles.forEach((tempFile) => {
  114. txUploadFile(tempFile.tempFilePath).then((data) => {
  115. if (!data) {
  116. tools.error('图片上传失败')
  117. tools.hideLoading()
  118. } else {
  119. if (this.uploadingType === 1) {
  120. tools.showLoading()
  121. //开启身份证照片识别
  122. getBaiDuImgRecognition({
  123. 'imgUrl': data.Location,
  124. 'imgType': '1'
  125. }).then((res) => {
  126. tools.hideLoading()
  127. if (res.code === 1) {
  128. this.identity_one = data.Location;
  129. this.name = res.data.name;
  130. this.id_number = res.data
  131. .id_number;
  132. this.sex = res.data.sex;
  133. this.birthday = res.data.birthday;
  134. this.$emit('update:userName', this
  135. .name)
  136. this.$emit('update:userBirthday',
  137. this.birthday)
  138. this.$emit('update:userSex', this
  139. .sex)
  140. this.$emit('update:idNumber', this
  141. .id_number)
  142. this.$emit('update:identityOne',
  143. this.identity_one)
  144. } else {
  145. tools.error('身份证照片识别失败')
  146. }
  147. })
  148. } else {
  149. tools.showLoading()
  150. //开启身份证照片背面识别
  151. getBaiDuImgRecognition({
  152. 'imgUrl': data.Location,
  153. 'imgType': '4'
  154. }).then((res) => {
  155. tools.hideLoading()
  156. if (res.code === 1) {
  157. this.identity_two = data.Location;
  158. this.identity_validity = res.data
  159. .identity_validity;
  160. this.$emit('update:identityTwo',
  161. this.identity_two)
  162. this.$emit(
  163. 'update:identityValidity',
  164. this.identity_validity)
  165. } else {
  166. tools.error('身份证照片识别失败')
  167. }
  168. })
  169. }
  170. }
  171. })
  172. })
  173. this.showUploadingImg(false, 0);
  174. } else {
  175. tools.error("请选择上传的图片")
  176. }
  177. },
  178. });
  179. },
  180. showUploadingImg(showImg, uploadingType) {
  181. if (showImg) {
  182. if (this.isUploading) {
  183. return
  184. }
  185. this.isUploading = true
  186. this.uploadingType = uploadingType;
  187. this.$refs.popup.open("bottom");
  188. } else {
  189. this.$refs.popup.close();
  190. this.isUploading = false
  191. }
  192. },
  193. closePopup(e) {
  194. if (e.show === false) {
  195. this.isUploading = false
  196. }
  197. },
  198. }
  199. }
  200. </script>
  201. <style scoped lang="scss">
  202. @import "@/static/css/wh-common";
  203. .identity-box {
  204. .identity-title {
  205. padding: 20rpx 0;
  206. font-size: 24rpx;
  207. color: #999;
  208. font-weight: 400;
  209. }
  210. .identity-item {
  211. display: flex;
  212. justify-content: space-between;
  213. padding-bottom: 20rpx;
  214. .item-img {
  215. width: calc(50% - 10rpx);
  216. .img-bg {
  217. padding: 20rpx;
  218. background: #F7F9FE;
  219. border-radius: 20rpx 20rpx 0rpx 0rpx;
  220. }
  221. image {
  222. width: 100%;
  223. height: 165rpx;
  224. border-radius: 6rpx;
  225. }
  226. .img-text {
  227. text-align: center;
  228. color: #ffffff;
  229. font-size: 24rpx;
  230. font-weight: 400;
  231. height: 60rpx;
  232. line-height: 60rpx;
  233. background: #0FB160;
  234. border-radius: 0rpx 0rpx 20rpx 20rpx;
  235. }
  236. }
  237. }
  238. }
  239. </style>