add-bank.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="bank-box">
  3. <en-input label="银行卡" v-model="number" type="number" placeholder="请输入银行卡号" @addRight="showUploadingImg(true)"
  4. right-img="/static/img/new-add/add-bank.png">
  5. <uni-icons class="m-l10" type="camera" size="30" color="#999"></uni-icons>
  6. </en-input>
  7. <en-input label="所属银行" v-model="name" type="text" placeholder="请输入银行名称"></en-input>
  8. <uni-popup ref="popup" :safeArea="false" type="bottom" @change="closePopup">
  9. <view class="popup-block">
  10. <view class="popup-row" @click="uploadingImg(1)">拍照</view>
  11. <view class="popup-row" @click="uploadingImg(2)">从手机里面选择</view>
  12. <view class="popup-row" @click="showUploadingImg(false,0)">取消</view>
  13. </view>
  14. </uni-popup>
  15. </view>
  16. </template>
  17. <script>
  18. import EnInput from "@/components/en-from/en-input/en-input";
  19. import {
  20. getBaiDuImgRecognition
  21. } from "@/api/common";
  22. import txUploadFile from "@/service/txOssSts";
  23. import tools from "@/service/tools";
  24. export default {
  25. name: "add-bank",
  26. components: {
  27. EnInput
  28. },
  29. props: {
  30. bankName: {
  31. default: ''
  32. },
  33. bankNum: {
  34. default: ''
  35. }
  36. },
  37. data() {
  38. return {
  39. number: '',
  40. name: '',
  41. isUploading: false,
  42. }
  43. },
  44. watch: {
  45. 'bankName': function() {
  46. console.log('bankName:' + this.bankName)
  47. if (this.bankName !== this.name) {
  48. this.name = this.bankName
  49. }
  50. },
  51. 'bankNum': function() {
  52. console.log('bankNum:' + this.bankNum)
  53. if (this.bankNum !== this.number) {
  54. this.number = this.bankNum
  55. }
  56. },
  57. 'name': function() {
  58. this.$emit('update:bankName', this.name)
  59. },
  60. 'number': function() {
  61. this.$emit('update:bankNum', this.number)
  62. }
  63. },
  64. mounted() {
  65. this.name = this.bankName
  66. this.number = this.bankNum
  67. },
  68. methods: {
  69. uploadingImg(sourceType) {
  70. uni.chooseMedia({
  71. mediaType: 'image',
  72. count: 1, //默认9
  73. sizeType: "compressed",
  74. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  75. success: (res) => {
  76. if (res.tempFiles.length > 0) {
  77. res.tempFiles.forEach((tempFile) => {
  78. txUploadFile(tempFile.tempFilePath).then((data) => {
  79. if (!data) {
  80. tools.error('图片上传失败')
  81. tools.hideLoading()
  82. } else {
  83. tools.showLoading()
  84. getBaiDuImgRecognition({
  85. 'imgUrl': data.Location,
  86. 'imgType': '2'
  87. }).then((res) => {
  88. tools.hideLoading()
  89. if (res.code === 1) {
  90. this.name = res.data.bank_name;
  91. this.number = res.data
  92. .bank_card_number;
  93. } else {
  94. tools.error('银行卡识别识别')
  95. }
  96. })
  97. }
  98. })
  99. })
  100. this.showUploadingImg(false, 0);
  101. } else {
  102. tools.error("请选择上传的图片")
  103. }
  104. },
  105. });
  106. },
  107. showUploadingImg(showImg, uploadingType) {
  108. if (showImg) {
  109. if (this.isUploading) {
  110. return
  111. }
  112. this.isUploading = true
  113. this.$refs.popup.open("bottom");
  114. } else {
  115. this.$refs.popup.close();
  116. this.isUploading = false
  117. }
  118. },
  119. closePopup(e) {
  120. if (e.show === false) {
  121. this.isUploading = false
  122. }
  123. },
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. @import "@/static/css/wh-common";
  129. </style>