add-identity.vue 6.2 KB

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