bankCard-list.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <script setup lang="ts">
  2. import { ref, computed } from 'vue'
  3. import { getBankcardList } from '@/api/pay'
  4. import { getImageUrl } from '@/utils/imageUtil'
  5. // 响应式状态
  6. const cardList = ref<any[]>([])
  7. const showActions = ref(false)
  8. const actions = ref([{ name: '解绑' }])
  9. const selectedCard = ref<any>(null)
  10. // 静态资源URL
  11. const staticUrl = import.meta.env.VITE_SERVER_BASEURL
  12. // 计算属性
  13. const btnText = computed(() => {
  14. return cardList.value.length === 0 ? '添加' : '更换'
  15. })
  16. // 页面加载
  17. onLoad(() => {
  18. // 可以在这里做一些初始化操作
  19. })
  20. // 页面显示
  21. onShow(() => {
  22. getData()
  23. })
  24. // 获取数据
  25. function getData() {
  26. getBankcardList().then((res: any) => {
  27. if (res.code === 200) {
  28. cardList.value = res.result
  29. }
  30. })
  31. }
  32. // 获取卡片背景样式
  33. function getCardBackground(card: any) {
  34. const cardColor = card.colorValue || '136, 136, 136'
  35. return `linear-gradient(90deg, rgba(${cardColor}, 0.4), rgba(${cardColor}, 0.8)), url(${getImageUrl('@local/vehicle/card-mask.png')}) center/cover no-repeat`
  36. }
  37. // 添加/更换银行卡
  38. function addBankCard() {
  39. if (btnText.value === '更换') {
  40. const cardId = cardList.value[0]?.id
  41. if (cardId) {
  42. uni.navigateTo({
  43. url: `/pages-B/payment/bankCard-edit?type=update&cardId=${cardId}`
  44. })
  45. }
  46. } else {
  47. uni.navigateTo({
  48. url: '/pages-B/payment/bankCard-edit'
  49. })
  50. }
  51. }
  52. // 显示操作菜单
  53. function showCardActions(card: any) {
  54. selectedCard.value = card
  55. showActions.value = true
  56. }
  57. // 选择操作
  58. function onActionSelect(action: { name: string }) {
  59. if (action.name === '解绑') {
  60. uni.showModal({
  61. title: '确认解绑',
  62. content: `您确定要解绑尾号为 ${selectedCard.value?.bankCardNumber?.substring(12)} 的银行卡吗?`,
  63. success: (res) => {
  64. if (res.confirm && selectedCard.value) {
  65. // 调用解绑接口(需要添加)
  66. // netBankcardDel(selectedCard.value.id).then((res) => {
  67. // uni.$u.toast(res.message)
  68. // if (res.code === 200) {
  69. // getData()
  70. // }
  71. // })
  72. uni.$u.toast('解绑功能开发中')
  73. }
  74. }
  75. })
  76. }
  77. showActions.value = false
  78. }
  79. </script>
  80. <template>
  81. <view class="page-container new-content">
  82. <u-navbar title="银行卡" :autoBack="true" :placeholder="true" :border-bottom="false"></u-navbar>
  83. <view class="card-list">
  84. <view class="card-item" v-for="card in cardList" :key="card.id" :style="{ background: getCardBackground(card) }">
  85. <view class="card-header">
  86. <image class="bank-logo" :src="card.bankImage" mode="aspectFit"></image>
  87. <view class="bank-info">
  88. <view class="bank-name">{{ card.bankName }}</view>
  89. <view class="card-type">{{ card.cardType || '储蓄卡' }}</view>
  90. </view>
  91. <!-- <image class="more" :src="getImageUrl('@local/groupMeal/icon_more.png')" @click="showCardActions(card)"></image> -->
  92. </view>
  93. <view class="card-number">
  94. <text>●●●●</text>
  95. <text>●●●●</text>
  96. <text>●●●●</text>
  97. <text class="n">{{ card.bankCardNumber.substring(12) }}</text>
  98. </view>
  99. </view>
  100. <u-empty
  101. text="没有可用的银行卡"
  102. textColor="#333"
  103. v-if="cardList.length === 0"
  104. :icon="`${staticUrl}/static/common/empty15.png`"
  105. >
  106. </u-empty>
  107. </view>
  108. <view class="footer-bar">
  109. <u-button type="primary" @click="addBankCard">{{ btnText }}银行卡</u-button>
  110. </view>
  111. <!-- 操作菜单 -->
  112. <u-action-sheet
  113. description="解除绑定后从银行卡列表中移除,需要重新添加使用"
  114. :round="20"
  115. :actions="actions"
  116. :show="showActions"
  117. :safeAreaInsetBottom="true"
  118. @select="onActionSelect"
  119. @close="showActions = false"
  120. ></u-action-sheet>
  121. </view>
  122. </template>
  123. <style lang="scss" scoped>
  124. .page-container {
  125. background-color: #f8f8fa;
  126. min-height: 100vh;
  127. }
  128. .card-list {
  129. padding: 24rpx;
  130. }
  131. .card-item {
  132. color: #333333;
  133. padding: 28rpx;
  134. margin-bottom: 20rpx;
  135. border-radius: 12rpx;
  136. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.1);
  137. .card-header {
  138. margin-bottom: 40rpx;
  139. position: relative;
  140. display: flex;
  141. align-items: center;
  142. .bank-logo {
  143. width: 80rpx;
  144. height: 80rpx;
  145. border-radius: 12rpx;
  146. background-color: #fff;
  147. }
  148. .bank-info {
  149. flex: 1;
  150. margin-left: 20rpx;
  151. .bank-name {
  152. font-size: 32rpx;
  153. font-weight: 500;
  154. }
  155. .card-type {
  156. font-size: 24rpx;
  157. opacity: 0.8;
  158. }
  159. }
  160. .more {
  161. width: 56rpx;
  162. height: 40rpx;
  163. position: absolute;
  164. top: 0;
  165. right: 0;
  166. }
  167. }
  168. .card-number {
  169. font-size: 14rpx;
  170. letter-spacing: 2rpx;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. .n {
  175. font-size: 36rpx;
  176. font-family: fantasy;
  177. }
  178. }
  179. }
  180. .footer-bar {
  181. ::v-deep .u-button {
  182. width: 100%;
  183. height: 76rpx;
  184. }
  185. }
  186. </style>