addBankcard.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="container">
  3. <JHeader title="添加银行卡" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view class="upload-bank-card">
  5. <view class="image-wrapper">
  6. <view class="uploader" @click="handleUploadImg">{{ uploadBandCard ? '重新上传' : '上传照片' }}</view>
  7. <image v-if="uploadBandCard" class="bank-img" :src="uploadBandCard"></image>
  8. <view v-else class="tip">上传图片银行卡图片自动识别~</view>
  9. </view>
  10. </view>
  11. <view class="addressBack-box">
  12. <view class="consignee-box bor-line-F7F7F7">
  13. <input v-model="username" maxlength="20" class="fs28" placeholder-class="consignee" placeholder="请填写真实姓名" />
  14. </view>
  15. <view class="iphoneNum-box bor-line-F7F7F7">
  16. <input
  17. v-model="phone" type="number" maxlength="11" class="fs28"
  18. placeholder-class="iphoneNum"
  19. placeholder="请填写手机号码"
  20. />
  21. </view>
  22. <view class="consignee-box bor-line-F7F7F7">
  23. <input v-model="bankName" maxlength="20" class="fs28" placeholder-class="consignee" placeholder="请填写银行名称" />
  24. </view>
  25. <view class="cardnum">
  26. <input
  27. v-model="cardNum" type="number" class="fs28" maxlength="20"
  28. placeholder-class="detailAddress"
  29. placeholder="请填写卡号"
  30. />
  31. </view>
  32. </view>
  33. <view v-if="type == 2" class="deleteBankcard-box">
  34. <label class="font-color-C5AA7B" @click="delBankcard">删除银行卡</label>
  35. </view>
  36. <view class="saveAddress-box">
  37. <view v-if="type == 1" class="saveAddress" @click="saveBankcardClick">添加银行卡</view>
  38. <view v-else class="saveAddress" @click="saveBankcardClick">保存</view>
  39. </view>
  40. <tui-toast ref="toast"></tui-toast>
  41. </view>
  42. </template>
  43. <script>
  44. import { getByIdUserBankcardApi, addUserBankcardApi, updateUserBankcardApi, deleteUserBankcardApi } from '../../../api/anotherTFInterface'
  45. import { bankCardAnalysisApi } from '../../../api/community-center'
  46. import { getUserId } from '../../../utils'
  47. import { T_STORAGE_KEY } from '../../../constant'
  48. import { IMG_UPLOAD_URL } from '../../../config'
  49. export default {
  50. name: 'AddBankcard',
  51. data() {
  52. return {
  53. show: false,
  54. type: 1, // 1.添加银行卡 2.编辑银行卡
  55. cardNum: '',
  56. bankcardId: '',
  57. bankCode: '',
  58. bankName: '',
  59. username: '',
  60. phone: '',
  61. id: '',
  62. uploadBandCard: null
  63. }
  64. },
  65. onLoad(options) {
  66. const userInfo = uni.getStorageSync(T_STORAGE_KEY)
  67. if (userInfo) {
  68. this.phone = userInfo.phone
  69. }
  70. if (options.type) {
  71. this.type = options.type
  72. }
  73. if (this.type == 2) {
  74. this.bankcardId = options.id
  75. this.renderBankcard(this.bankcardId)
  76. }
  77. },
  78. methods: {
  79. renderBankcard(bankcardId) {
  80. getByIdUserBankcardApi({ bankId: bankcardId }).then((res) => {
  81. const bankCard = res.data
  82. this.id = bankcardId
  83. this.username = bankCard.name
  84. this.phone = bankCard.phone
  85. this.bankName = bankCard.bankName
  86. this.bankCode = bankCard.bankCode
  87. this.cardNum = bankCard.bankCard
  88. })
  89. },
  90. // 新增或更新银行卡
  91. saveBankcardClick() {
  92. const _ = this
  93. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  94. if (this.username == '') {
  95. uni.showToast({
  96. title: '请输入姓名!',
  97. duration: 2000,
  98. icon: 'none'
  99. })
  100. } else if (this.phone == '') {
  101. uni.showToast({
  102. title: '请输入手机号!',
  103. duration: 2000,
  104. icon: 'none'
  105. })
  106. } else if (!phoneCodeVerification.test(this.phone)) {
  107. uni.showToast({
  108. title: '请输入正确的手机号!',
  109. duration: 2000,
  110. icon: 'none'
  111. })
  112. } else if (this.bankName == '') {
  113. uni.showToast({
  114. title: '请填写银行名称!',
  115. duration: 2000,
  116. icon: 'none'
  117. })
  118. } else if (this.cardNum == '') {
  119. uni.showToast({
  120. title: '请输入卡号!',
  121. duration: 2000,
  122. icon: 'none'
  123. })
  124. } else if (this.cardNum.length != 16 && this.cardNum.length != 19) {
  125. uni.showToast({
  126. title: '请输入正确的卡号!',
  127. duration: 2000,
  128. icon: 'none'
  129. })
  130. } else if (this.type == 1) {
  131. addUserBankcardApi({
  132. name: this.username,
  133. phone: this.phone,
  134. bankName: this.bankName,
  135. bankCard: this.cardNum
  136. }).then((res) => {
  137. uni.showToast({
  138. title: '添加成功',
  139. duration: 2000,
  140. icon: 'none'
  141. })
  142. setTimeout(() => {
  143. uni.navigateBack()
  144. }, 2000)
  145. })
  146. } else {
  147. updateUserBankcardApi({
  148. bankId: this.id,
  149. name: this.username,
  150. phone: this.phone,
  151. bankName: this.bankName,
  152. bankCard: this.cardNum
  153. }).then((res) => {
  154. this.$showToast('操作成功')
  155. setTimeout(() => {
  156. uni.navigateBack()
  157. }, 2000)
  158. })
  159. }
  160. },
  161. // 删除银行卡
  162. delBankcard() {
  163. uni.showModal({
  164. title: '温馨提示',
  165. content: '确认删除该银行卡?',
  166. confirmText: '确定',
  167. cancelText: '取消',
  168. success: (res) => {
  169. if (res.confirm) {
  170. deleteUserBankcardApi({
  171. bankId: this.bankcardId
  172. }).then((res) => {
  173. this.$showToast('删除成功')
  174. setTimeout(() => {
  175. uni.navigateBack()
  176. }, 2000)
  177. })
  178. }
  179. }
  180. })
  181. },
  182. handleUploadImg() {
  183. const _this = this
  184. uni.chooseImage({
  185. success: (chooseImageRes) => {
  186. const imgPath = chooseImageRes.tempFiles[0].path
  187. if (!imgPath) return
  188. uni.showLoading({
  189. title: '上传中...'
  190. })
  191. uni.uploadFile({
  192. url: IMG_UPLOAD_URL,
  193. filePath: imgPath,
  194. name: 'file',
  195. formData: {
  196. userId: getUserId()
  197. },
  198. success: (uploadFileRes) => {
  199. uni.hideLoading()
  200. const imgUrl = JSON.parse(uploadFileRes.data).data.url
  201. _this.uploadBandCard = imgUrl
  202. _this.bankCardAnalysis(imgUrl)
  203. },
  204. fail: (error) => {
  205. uni.hideLoading()
  206. _this.ttoast({
  207. type: 'fail',
  208. title: '图片上传失败',
  209. content: error
  210. })
  211. }
  212. })
  213. },
  214. fail: (fail) => {
  215. console.log(fail)
  216. }
  217. })
  218. },
  219. async bankCardAnalysis(imageUrl) {
  220. if (!imageUrl) {
  221. this.ttoast({
  222. type: 'fail',
  223. title: '银行卡解析失败',
  224. content: '请填写银行卡信息'
  225. })
  226. return
  227. }
  228. try {
  229. uni.showLoading({
  230. title: '银行卡解析中...'
  231. })
  232. const data = await bankCardAnalysisApi({
  233. imageUrl
  234. })
  235. this.bankName = (data.cardName + '').replaceAll(' ', '')
  236. this.cardNum = (data.cardNum + '').replaceAll(' ', '')
  237. } catch (err) {
  238. this.ttoast({
  239. type: 'fail',
  240. title: '银行卡解析失败',
  241. content: '请填写银行卡信息'
  242. })
  243. this.uploadBandCard = ''
  244. } finally {
  245. uni.hideLoading()
  246. }
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="less" scoped>
  252. .container {
  253. background-color: #F7F7F7;
  254. min-height: 100vh;
  255. box-sizing: border-box;
  256. .addressBack-box {
  257. padding: 30upx 30upx;
  258. .consignee-box {
  259. padding-bottom: 36upx;
  260. width: 690upx;
  261. margin-top: 20upx;
  262. .consignee {
  263. color: #999999;
  264. font-size: 28upx;
  265. }
  266. }
  267. .iphoneNum-box {
  268. padding-bottom: 36upx;
  269. width: 690upx;
  270. margin-top: 36upx;
  271. .iphoneNum {
  272. color: #999999;
  273. font-size: 28upx;
  274. }
  275. }
  276. .cardnum {
  277. margin-top: 19px;
  278. }
  279. }
  280. .saveAddress-box {
  281. position: fixed;
  282. bottom: 50upx;
  283. left: 30upx;
  284. .saveAddress {
  285. width: 690upx;
  286. height: 100upx;
  287. color: #FFEBC4;
  288. text-align: center;
  289. line-height: 100upx;
  290. background: #333333;
  291. }
  292. }
  293. .upload-bank-card {
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. width: 670upx;
  298. height: 408upx;
  299. background-color: #F7FBFF;
  300. margin: 30upx auto;
  301. .image-wrapper {
  302. width: 585upx;
  303. height: 375upx;
  304. background-color: #fff;
  305. position: relative;
  306. .bank-img {
  307. width: 100%;
  308. height: 100%;
  309. }
  310. .uploader {
  311. position: absolute;
  312. top: 50%;
  313. left: 50%;
  314. width: 143upx;
  315. height: 143upx;
  316. border-radius: 100px;
  317. background: rgba(4, 3, 33, 0.6);
  318. transform: translate(-50%, -50%);
  319. color: #fff;
  320. font-size: 28upx;
  321. line-height: 143upx;
  322. text-align: center;
  323. transition: all 350ms;
  324. z-index: 10;
  325. &:active {
  326. opacity: 0.8;
  327. }
  328. }
  329. .tip {
  330. font-size: 24upx;
  331. letter-spacing: 0.4em;
  332. margin-top: 300upx;
  333. text-align: center;
  334. color: #ccc;
  335. }
  336. }
  337. }
  338. }
  339. .deleteBankcard-box {
  340. background-color: #FFFFFF;
  341. padding: 30upx 30upx;
  342. margin-top: 20upx;
  343. text-align: center;
  344. }
  345. </style>