index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view class="bank-manage-container">
  3. <!-- 银行卡列表 -->
  4. <view class="card-list">
  5. <view
  6. v-for="(card, index) in bankCards"
  7. :key="index"
  8. :class="['bank-card', selectedCard?.id === card.id ? 'active' : '']"
  9. @click="selectCard(card)"
  10. >
  11. <view class="card-content">
  12. <view class="bank-info">
  13. <view class="bank-icon">
  14. <!-- <uni-icons
  15. size="30"
  16. customPrefix="iconfont"
  17. class="icon-yinhangqia"
  18. ></uni-icons> -->
  19. <uni-icons
  20. size="35"
  21. :color="card.accountType === 1 ? '#F2CC51' : '#019FE8'"
  22. customPrefix="iconfont"
  23. :class="[
  24. card.accountType === 1 ? 'icon-qianbao' : 'icon-zhifubao',
  25. ]"
  26. ></uni-icons>
  27. </view>
  28. <view class="bank-details">
  29. <view class="bank-name">{{ card.accountType === 1 ? card.bankName : card.accountName }}</view>
  30. <view class="card-number">{{
  31. formatCardNumber(card.accountNumber)
  32. }}</view>
  33. </view>
  34. </view>
  35. <view class="right-box">
  36. <view class="icon-box" @click.stop="editCard(card)">
  37. <uni-icons size="25" color="#fff" type="compose"></uni-icons>
  38. </view>
  39. <view class="icon-box delete" @click.stop="deleteCard(card)">
  40. <uni-icons size="25" color="#fff" type="trash-filled"></uni-icons>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- <view class="card-selected" v-if="selectedCard?.id === card.id">
  45. <text class="check-icon">✓</text>
  46. </view> -->
  47. </view>
  48. </view>
  49. <!-- 新增卡片按钮 -->
  50. <view class="add-card-section">
  51. <button class="add-card-btn" @click="addNewCard">
  52. <text class="add-icon">+</text>
  53. <text class="add-text">新增卡片</text>
  54. </button>
  55. </view>
  56. <up-modal
  57. :show="showDeleteModal"
  58. title="确认删除"
  59. content="确定要删除该银行卡吗?"
  60. :showCancelButton="true"
  61. @confirm="confirmDeleteCard"
  62. @cancel="showDeleteModal = false"
  63. @close="showDeleteModal = false"
  64. />
  65. </view>
  66. </template>
  67. <script setup>
  68. import { ref, reactive } from "vue";
  69. import { onLoad, onShow } from "@dcloudio/uni-app";
  70. import { getAccountList, deleteAccount, saveAccount } from "@/api/user";
  71. const bankCards = ref([]);
  72. const selectedCard = ref();
  73. const isEditing = ref(false);
  74. const currentEditIndex = ref(-1);
  75. const cardForm = reactive({
  76. bankName: "",
  77. cardNumber: "",
  78. holderName: "",
  79. });
  80. const showDeleteModal = ref(false);
  81. const cardToDelete = ref(null);
  82. onShow(() => {
  83. fetchAccountList();
  84. });
  85. async function fetchAccountList() {
  86. try {
  87. const { data } = await getAccountList();
  88. bankCards.value = data;
  89. selectedCard.value = data.find(v => v.isDefault)
  90. console.log('selectedCard', selectedCard.value)
  91. } catch (error) {
  92. console.error("getAccountList", error);
  93. }
  94. }
  95. const formatCardNumber = (cardNumber) => {
  96. // 显示卡号,只显示后4位,其他用*代替
  97. if (cardNumber.length <= 4) return cardNumber;
  98. const lastFour = cardNumber.slice(-4);
  99. return `****${lastFour}`;
  100. };
  101. const selectCard = async (card) => {
  102. const params = {
  103. id: card.id,
  104. isDefault: 1
  105. }
  106. await saveAccount(params)
  107. selectedCard.value = card;
  108. // 可以在这里添加选中卡片的逻辑
  109. uni.showToast({
  110. title: "已设为默认",
  111. icon: "success",
  112. });
  113. };
  114. const editCard = (card) => {
  115. const queryStr = `id=${card.id}&bankName=${card.bankName}&accountNumber=${card.accountNumber}&accountType=${card.accountType}&name=${card.accountName}&isDefault=${card.isDefault}`;
  116. uni.navigateTo({
  117. url: `/pages/users/bank_card_manage/create?${queryStr}`,
  118. });
  119. isEditing.value = true;
  120. currentEditIndex.value = bankCards.value.findIndex((c) => c.id === card.id);
  121. cardForm.bankName = card.bankName;
  122. cardForm.cardNumber = card.cardNumber;
  123. cardForm.holderName = card.holderName;
  124. };
  125. // 修改 deleteCard 方法为弹窗确认
  126. function deleteCard(card) {
  127. cardToDelete.value = card;
  128. showDeleteModal.value = true;
  129. }
  130. // 确认删除
  131. async function confirmDeleteCard() {
  132. if (!cardToDelete.value) return;
  133. try {
  134. await deleteAccount(cardToDelete.value.id);
  135. // 删除成功后刷新列表
  136. fetchAccountList();
  137. uni.showToast({ title: "删除成功", icon: "success" });
  138. } catch (e) {
  139. uni.showToast({ title: "删除失败", icon: "none" });
  140. } finally {
  141. showDeleteModal.value = false;
  142. cardToDelete.value = null;
  143. }
  144. }
  145. const addNewCard = () => {
  146. uni.navigateTo({ url: "/pages/users/bank_card_manage/create" });
  147. isEditing.value = false;
  148. cardForm.bankName = "";
  149. cardForm.cardNumber = "";
  150. cardForm.holderName = "";
  151. };
  152. </script>
  153. <style lang="scss" scoped>
  154. .bank-manage-container {
  155. min-height: 100vh;
  156. background: #F9F7F0;
  157. .card-list {
  158. padding: 30rpx 30rpx 0;
  159. .bank-card {
  160. background: linear-gradient(135deg, #f6b742 0%, #e74c3c 100%);
  161. border-radius: 24rpx;
  162. padding: 40rpx 30rpx;
  163. margin-bottom: 30rpx;
  164. position: relative;
  165. overflow: hidden;
  166. transition: transform 0.2s ease;
  167. border: 3rpx solid #fff;
  168. &.active {
  169. border: 3rpx solid #00c896;
  170. }
  171. &::before {
  172. content: "";
  173. position: absolute;
  174. top: -50%;
  175. right: -30%;
  176. width: 200rpx;
  177. height: 200rpx;
  178. background: rgba(255, 255, 255, 0.1);
  179. border-radius: 50%;
  180. }
  181. .card-content {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. position: relative;
  186. z-index: 2;
  187. .bank-info {
  188. display: flex;
  189. align-items: center;
  190. .bank-icon {
  191. width: 100rpx;
  192. height: 100rpx;
  193. border-radius: 50rpx;
  194. background: rgba(255, 255, 255, 1);
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. margin-right: 24rpx;
  199. .icon {
  200. font-size: 28rpx;
  201. color: #fff;
  202. }
  203. }
  204. .bank-details {
  205. .bank-name {
  206. color: #fff;
  207. font-size: 32rpx;
  208. font-weight: 600;
  209. margin-bottom: 8rpx;
  210. }
  211. .card-number {
  212. color: rgba(255, 255, 255, 0.8);
  213. font-size: 28rpx;
  214. font-weight: 400;
  215. letter-spacing: 2rpx;
  216. }
  217. }
  218. }
  219. .right-box {
  220. display: flex;
  221. align-items: center;
  222. }
  223. .icon-box {
  224. width: 60rpx;
  225. height: 60rpx;
  226. background: rgba(255, 255, 255, 0.2);
  227. border-radius: 12rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. transition: background 0.3s ease;
  232. &.icon-box {
  233. margin-left: 20rpx;
  234. }
  235. &:active {
  236. background: rgba(255, 255, 255, 0.3);
  237. }
  238. .edit-icon {
  239. color: #fff;
  240. font-size: 28rpx;
  241. }
  242. }
  243. }
  244. .card-selected {
  245. position: absolute;
  246. top: 20rpx;
  247. right: 20rpx;
  248. width: 40rpx;
  249. height: 40rpx;
  250. background: #4caf50;
  251. border-radius: 50%;
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. z-index: 3;
  256. .check-icon {
  257. color: #fff;
  258. font-size: 24rpx;
  259. font-weight: 600;
  260. }
  261. }
  262. }
  263. }
  264. .add-card-section {
  265. position: fixed;
  266. bottom: 0;
  267. left: 0;
  268. right: 0;
  269. background-color: #FFF;
  270. padding: 20rpx 30rpx;
  271. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
  272. z-index: 5;
  273. .add-card-btn {
  274. width: 100%;
  275. //background: linear-gradient(135deg, #e9c279 0%, #d4a853 100%);
  276. background: #F8C008;
  277. color: #333;
  278. font-size: 32rpx;
  279. //font-weight: 600;
  280. //padding: 32rpx 0;
  281. height: 88rpx;
  282. line-height: 88rpx;
  283. border-radius: 16rpx;
  284. border: none;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. //box-shadow: 0 6rpx 20rpx rgba(233, 194, 121, 0.3);
  289. //transition: all 0.3s ease;
  290. &:active {
  291. transform: translateY(2rpx);
  292. box-shadow: 0 4rpx 12rpx rgba(233, 194, 121, 0.2);
  293. }
  294. .add-icon {
  295. font-size: 36rpx;
  296. margin-right: 16rpx;
  297. }
  298. .add-text {
  299. font-size: 30rpx;
  300. }
  301. }
  302. }
  303. .modal-overlay {
  304. position: fixed;
  305. top: 0;
  306. left: 0;
  307. right: 0;
  308. bottom: 0;
  309. background: rgba(0, 0, 0, 0.5);
  310. display: flex;
  311. align-items: center;
  312. justify-content: center;
  313. z-index: 1000;
  314. .modal-content {
  315. background: #fff;
  316. border-radius: 24rpx;
  317. width: 600rpx;
  318. max-height: 80vh;
  319. overflow: hidden;
  320. .modal-header {
  321. display: flex;
  322. align-items: center;
  323. justify-content: space-between;
  324. padding: 40rpx 30rpx 20rpx;
  325. border-bottom: 1rpx solid #f0f0f0;
  326. .modal-title {
  327. color: #333;
  328. font-size: 32rpx;
  329. font-weight: 600;
  330. }
  331. .modal-close {
  332. color: #999;
  333. font-size: 48rpx;
  334. font-weight: 300;
  335. line-height: 1;
  336. }
  337. }
  338. .modal-body {
  339. padding: 30rpx;
  340. .form-item {
  341. margin-bottom: 30rpx;
  342. .form-label {
  343. display: block;
  344. color: #333;
  345. font-size: 28rpx;
  346. font-weight: 500;
  347. margin-bottom: 16rpx;
  348. }
  349. .form-input {
  350. width: 100%;
  351. padding: 24rpx;
  352. background: #f8f9fa;
  353. border: 2rpx solid #e9ecef;
  354. border-radius: 12rpx;
  355. font-size: 28rpx;
  356. color: #333;
  357. transition: border-color 0.3s ease;
  358. &:focus {
  359. border-color: #e9c279;
  360. }
  361. &::placeholder {
  362. color: #999;
  363. }
  364. }
  365. }
  366. }
  367. .modal-footer {
  368. display: flex;
  369. padding: 20rpx 30rpx 30rpx;
  370. gap: 20rpx;
  371. .cancel-btn {
  372. flex: 1;
  373. background: #f8f9fa;
  374. color: #666;
  375. font-size: 28rpx;
  376. padding: 24rpx 0;
  377. border-radius: 12rpx;
  378. border: none;
  379. transition: background 0.3s ease;
  380. &:active {
  381. background: #e9ecef;
  382. }
  383. }
  384. .confirm-btn {
  385. flex: 1;
  386. background: linear-gradient(135deg, #e9c279 0%, #d4a853 100%);
  387. color: #fff;
  388. font-size: 28rpx;
  389. padding: 24rpx 0;
  390. border-radius: 12rpx;
  391. border: none;
  392. transition: all 0.3s ease;
  393. &:active {
  394. transform: translateY(1rpx);
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. </style>