add-license.vue 3.5 KB

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