index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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/card_page/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. console.log('create')
  147. uni.navigateTo({ url: "/pages/users/card_page/create" });
  148. isEditing.value = false;
  149. cardForm.bankName = "";
  150. cardForm.cardNumber = "";
  151. cardForm.holderName = "";
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .bank-manage-container {
  156. min-height: 100vh;
  157. background: #F9F7F0;
  158. .card-list {
  159. padding: 30rpx 30rpx 0;
  160. .bank-card {
  161. background: linear-gradient(135deg, #f6b742 0%, #e74c3c 100%);
  162. border-radius: 24rpx;
  163. padding: 40rpx 30rpx;
  164. margin-bottom: 30rpx;
  165. position: relative;
  166. overflow: hidden;
  167. transition: transform 0.2s ease;
  168. border: 3rpx solid #fff;
  169. &.active {
  170. border: 3rpx solid #00c896;
  171. }
  172. &::before {
  173. content: "";
  174. position: absolute;
  175. top: -50%;
  176. right: -30%;
  177. width: 200rpx;
  178. height: 200rpx;
  179. background: rgba(255, 255, 255, 0.1);
  180. border-radius: 50%;
  181. }
  182. .card-content {
  183. display: flex;
  184. align-items: center;
  185. justify-content: space-between;
  186. position: relative;
  187. z-index: 2;
  188. .bank-info {
  189. display: flex;
  190. align-items: center;
  191. .bank-icon {
  192. width: 100rpx;
  193. height: 100rpx;
  194. border-radius: 50rpx;
  195. background: rgba(255, 255, 255, 1);
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. margin-right: 24rpx;
  200. .icon {
  201. font-size: 28rpx;
  202. color: #fff;
  203. }
  204. }
  205. .bank-details {
  206. .bank-name {
  207. color: #fff;
  208. font-size: 32rpx;
  209. font-weight: 600;
  210. margin-bottom: 8rpx;
  211. }
  212. .card-number {
  213. color: rgba(255, 255, 255, 0.8);
  214. font-size: 28rpx;
  215. font-weight: 400;
  216. letter-spacing: 2rpx;
  217. }
  218. }
  219. }
  220. .right-box {
  221. display: flex;
  222. align-items: center;
  223. }
  224. .icon-box {
  225. width: 60rpx;
  226. height: 60rpx;
  227. background: rgba(255, 255, 255, 0.2);
  228. border-radius: 12rpx;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. transition: background 0.3s ease;
  233. &.icon-box {
  234. margin-left: 20rpx;
  235. }
  236. &:active {
  237. background: rgba(255, 255, 255, 0.3);
  238. }
  239. .edit-icon {
  240. color: #fff;
  241. font-size: 28rpx;
  242. }
  243. }
  244. }
  245. .card-selected {
  246. position: absolute;
  247. top: 20rpx;
  248. right: 20rpx;
  249. width: 40rpx;
  250. height: 40rpx;
  251. background: #4caf50;
  252. border-radius: 50%;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. z-index: 3;
  257. .check-icon {
  258. color: #fff;
  259. font-size: 24rpx;
  260. font-weight: 600;
  261. }
  262. }
  263. }
  264. }
  265. .add-card-section {
  266. position: fixed;
  267. bottom: 0;
  268. left: 0;
  269. right: 0;
  270. background-color: #FFF;
  271. padding: 20rpx 30rpx;
  272. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
  273. z-index: 5;
  274. .add-card-btn {
  275. width: 100%;
  276. //background: linear-gradient(135deg, #e9c279 0%, #d4a853 100%);
  277. background: #F8C008;
  278. color: #333;
  279. font-size: 32rpx;
  280. //font-weight: 600;
  281. //padding: 32rpx 0;
  282. height: 88rpx;
  283. line-height: 88rpx;
  284. border-radius: 16rpx;
  285. border: none;
  286. display: flex;
  287. align-items: center;
  288. justify-content: center;
  289. //box-shadow: 0 6rpx 20rpx rgba(233, 194, 121, 0.3);
  290. //transition: all 0.3s ease;
  291. &:active {
  292. transform: translateY(2rpx);
  293. box-shadow: 0 4rpx 12rpx rgba(233, 194, 121, 0.2);
  294. }
  295. .add-icon {
  296. font-size: 36rpx;
  297. margin-right: 16rpx;
  298. }
  299. .add-text {
  300. font-size: 30rpx;
  301. }
  302. }
  303. }
  304. .modal-overlay {
  305. position: fixed;
  306. top: 0;
  307. left: 0;
  308. right: 0;
  309. bottom: 0;
  310. background: rgba(0, 0, 0, 0.5);
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. z-index: 1000;
  315. .modal-content {
  316. background: #fff;
  317. border-radius: 24rpx;
  318. width: 600rpx;
  319. max-height: 80vh;
  320. overflow: hidden;
  321. .modal-header {
  322. display: flex;
  323. align-items: center;
  324. justify-content: space-between;
  325. padding: 40rpx 30rpx 20rpx;
  326. border-bottom: 1rpx solid #f0f0f0;
  327. .modal-title {
  328. color: #333;
  329. font-size: 32rpx;
  330. font-weight: 600;
  331. }
  332. .modal-close {
  333. color: #999;
  334. font-size: 48rpx;
  335. font-weight: 300;
  336. line-height: 1;
  337. }
  338. }
  339. .modal-body {
  340. padding: 30rpx;
  341. .form-item {
  342. margin-bottom: 30rpx;
  343. .form-label {
  344. display: block;
  345. color: #333;
  346. font-size: 28rpx;
  347. font-weight: 500;
  348. margin-bottom: 16rpx;
  349. }
  350. .form-input {
  351. width: 100%;
  352. padding: 24rpx;
  353. background: #f8f9fa;
  354. border: 2rpx solid #e9ecef;
  355. border-radius: 12rpx;
  356. font-size: 28rpx;
  357. color: #333;
  358. transition: border-color 0.3s ease;
  359. &:focus {
  360. border-color: #e9c279;
  361. }
  362. &::placeholder {
  363. color: #999;
  364. }
  365. }
  366. }
  367. }
  368. .modal-footer {
  369. display: flex;
  370. padding: 20rpx 30rpx 30rpx;
  371. gap: 20rpx;
  372. .cancel-btn {
  373. flex: 1;
  374. background: #f8f9fa;
  375. color: #666;
  376. font-size: 28rpx;
  377. padding: 24rpx 0;
  378. border-radius: 12rpx;
  379. border: none;
  380. transition: background 0.3s ease;
  381. &:active {
  382. background: #e9ecef;
  383. }
  384. }
  385. .confirm-btn {
  386. flex: 1;
  387. background: linear-gradient(135deg, #e9c279 0%, #d4a853 100%);
  388. color: #fff;
  389. font-size: 28rpx;
  390. padding: 24rpx 0;
  391. border-radius: 12rpx;
  392. border: none;
  393. transition: all 0.3s ease;
  394. &:active {
  395. transform: translateY(1rpx);
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. </style>