index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="receiving">
  3. <template v-if="Object.keys(receivingInfo).length <= 0">
  4. <view class="empty">
  5. <image class="" src="@/static/image/order/empty.png" />
  6. <text>暂未绑定账户</text>
  7. <view class="btn" @click="navigateTo('/pages_module/bindingCard/index')"
  8. >去绑定</view
  9. >
  10. </view>
  11. </template>
  12. <template v-else>
  13. <view class="receiving-box">
  14. <view class="receiving-title">已绑定账户</view>
  15. <viwe class="receiving-card">
  16. <view class="card-box">
  17. <view class="card-title">
  18. <text>{{ bankName }}</text>
  19. <tui-icon
  20. name="evaluate"
  21. color="#FFFFFF"
  22. :size="20"
  23. @click="goBankCard(1)"
  24. ></tui-icon>
  25. </view>
  26. <view class="card-eye">
  27. <text>{{ cardNumber }}</text>
  28. <template v-if="showEye">
  29. <tui-icon
  30. name="seen"
  31. :size="20"
  32. color="#FFFFFF"
  33. @click="changeIcon(false)"
  34. ></tui-icon>
  35. </template>
  36. <template v-else>
  37. <tui-icon
  38. name="unseen"
  39. :size="20"
  40. color="#FFFFFF"
  41. @click="changeIcon(true)"
  42. ></tui-icon>
  43. </template>
  44. </view>
  45. <view class="card-prople">
  46. <text>持卡人</text>
  47. <text>{{ receivingInfo.cardName }}</text>
  48. </view>
  49. </view>
  50. </viwe>
  51. </view>
  52. </template>
  53. </view>
  54. </template>
  55. <script>
  56. import { getReceiving, getSelect } from "@/config/index.js";
  57. export default {
  58. created() {
  59. this.getBankAll();
  60. },
  61. onShow(){
  62. this.getAccount();
  63. },
  64. data() {
  65. return {
  66. receivingInfo: {},
  67. bankList: [],
  68. cardNumber: "",
  69. // 控制眼睛
  70. showEye: true,
  71. };
  72. },
  73. computed: {
  74. bankName() {
  75. return this.bankList.filter((item) => {
  76. return item.dictId == this.receivingInfo.bank;
  77. })[0]?.dictName;
  78. },
  79. },
  80. methods: {
  81. // 获取收款商户
  82. async getAccount() {
  83. let { data } = await getReceiving({});
  84. this.receivingInfo = data;
  85. if(Object.keys(data).length <= 0) return
  86. // 调用函数返回隐藏的字符
  87. this.cardNumber = this.convert(data.cardNumber, false);
  88. },
  89. // 获取所有银行
  90. async getBankAll() {
  91. let { data } = await getSelect({ dictName: "所属银行" });
  92. this.bankList = data;
  93. },
  94. // 小眼睛切换
  95. changeIcon(flag) {
  96. this.showEye = flag;
  97. this.cardNumber = this.convert(this.receivingInfo.cardNumber);
  98. },
  99. // 转换银行卡符号
  100. convert(str) {
  101. let lastFour = str.slice(-4);
  102. if (this.showEye) {
  103. let maskedStr = `${"*".repeat(str.length - 4)} ${lastFour}`;
  104. let card1 = maskedStr
  105. .split(" ")[0]
  106. .replace(/(.{4})/g, (match) => `${match} `);
  107. let card2 = maskedStr.split(" ")[1];
  108. return `${card1} ${card2}`;
  109. } else {
  110. // 不截取后面四位
  111. let numStr = str.slice(0, str.length - 4);
  112. let card1 = numStr.replace(/(.{4})/g, (match) => `${match} `);
  113. return `${card1} ${lastFour}`;
  114. }
  115. },
  116. // 跳转到编辑银行卡
  117. goBankCard(type) {
  118. uni.navigateTo({
  119. url: `/pages_module/bindingCard/index?type=${type}`,
  120. });
  121. let obj = {...this.receivingInfo};
  122. obj.dictName = this.bankName
  123. // 本地存储银行卡信息
  124. uni.setStorageSync("bankInfo", obj);
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. @import "./index.scss";
  131. </style>