add-identity.vue 6.4 KB

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