add-register.vue 3.7 KB

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