add-license.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="license-box">
  3. <view class="account-name">
  4. 上传营业执照图片
  5. </view>
  6. <view class="credentials-box" @click="showUploadingImg(true)">
  7. <view class="credentials-img" v-if="identity_one">
  8. <image class="credentials-imgs" :src="identity_one" mode="aspectFill"></image>
  9. </view>
  10. <view class="credentials-img" v-else>
  11. <image class="credentials-imgs" src="/page_task/static/img/scmb.png" mode=""></image>
  12. </view>
  13. </view>
  14. <uni-popup ref="popup" :safeArea="false" type="bottom" @change="closePopup">
  15. <view class="popup-block">
  16. <view class="popup-row" @click="uploadingImg(1)">拍照</view>
  17. <view class="popup-row" @click="uploadingImg(2)">从手机里面选择</view>
  18. <view class="popup-row" @click="showUploadingImg(false,0)">取消</view>
  19. </view>
  20. </uni-popup>
  21. </view>
  22. </template>
  23. <script>
  24. import {getBaiDuImgRecognition} from "@/api/common";
  25. import txUploadFile from "@/service/txOssSts";
  26. import tools from "@/service/tools";
  27. export default {
  28. name: "add-license",
  29. components: {},
  30. props: {
  31. 'value': {
  32. default: '',
  33. },
  34. 'userName': {
  35. default: '',
  36. },
  37. 'idNumber': {
  38. default: '',
  39. }
  40. },
  41. data() {
  42. return {
  43. 'identity_one': '',
  44. 'name': '',
  45. 'id_number': '',
  46. }
  47. },
  48. watch: {
  49. 'identity_one': function () {
  50. this.$emit("input", this.identity_one);
  51. },
  52. 'value': function () {
  53. this.setValue()
  54. },
  55. },
  56. mounted() {
  57. this.setValue()
  58. },
  59. methods: {
  60. setValue() {
  61. console.log(this.value)
  62. this.identity_one = this.value
  63. },
  64. uploadingImg(sourceType) {
  65. uni.chooseMedia({
  66. mediaType: 'image',
  67. count: 1, //默认9
  68. sizeType: "compressed",
  69. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  70. success: (res) => {
  71. if (res.tempFiles.length > 0) {
  72. res.tempFiles.forEach((tempFile) => {
  73. txUploadFile(tempFile.tempFilePath).then((data) => {
  74. if (!data) {
  75. tools.error('图片上传失败')
  76. tools.hideLoading()
  77. } else {
  78. tools.showLoading()
  79. getBaiDuImgRecognition({
  80. 'imgUrl': data.Location,
  81. 'imgType': '3'
  82. }).then((res) => {
  83. tools.hideLoading()
  84. if (res.code === 1) {
  85. this.identity_one = data.Location;
  86. this.name = res.data.name;
  87. this.id_number = res.data.id_number;
  88. this.$emit('update:userName',this.name)
  89. this.$emit('update:idNumber',this.id_number)
  90. } else {
  91. tools.error(res.msg)
  92. }
  93. })
  94. }
  95. })
  96. })
  97. this.showUploadingImg(false, 0);
  98. } else {
  99. tools.error("请选择上传的图片")
  100. }
  101. },
  102. });
  103. },
  104. showUploadingImg(showImg) {
  105. if (showImg) {
  106. if (this.isUploading) {
  107. return
  108. }
  109. this.isUploading = true
  110. this.$refs.popup.open("bottom");
  111. } else {
  112. this.$refs.popup.close();
  113. this.isUploading = false
  114. }
  115. },
  116. closePopup(e) {
  117. if (e.show === false) {
  118. this.isUploading = false
  119. }
  120. },
  121. }
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. @import "@/static/css/wh-common";
  126. .license-box {
  127. .account-name {
  128. font-size: 32rpx;
  129. padding: 16px 0 0 0;
  130. color: #232A35;
  131. }
  132. .credentials-box {
  133. padding: 24rpx 0 0 0;
  134. border-bottom: 1px solid #F0F0F0;
  135. .credentials-img {
  136. width: 160rpx;
  137. height: 160rpx;
  138. margin: 0 16rpx 30rpx 0;
  139. .credentials-imgs {
  140. width: 100%;
  141. height: 100%;
  142. display: block;
  143. }
  144. }
  145. }
  146. }
  147. </style>