add-bank.vue 3.2 KB

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