jiuyiUniapp/jiuyi2/pages/mine/setting/bankCard.vue

188 lines
3.4 KiB
Vue
Raw Normal View History

2024-12-27 15:03:48 +08:00
<script setup>
// 我的银行卡
2025-02-23 13:32:05 +08:00
import {
ref,
computed,
reactive,
} from 'vue'
import {
useStore
} from 'vuex'
import {
onLoad,
onUnload,
} from '@dcloudio/uni-app'
// 工具库
import util from '@/common/js/util.js'
// api
import api from '@/api/index.js'
// 列表
const list = reactive([])
// 滑动菜单
const options = reactive([{
text: '解绑',
style: {
backgroundColor: '#007aff'
},
cb: (event) => removeBank(event)
}])
onLoad(() => {
// 获取列表
getList()
// 开启监听
addListener()
})
onUnload(() => {
// 关闭监听
removeListener()
})
// 开启监听
function addListener() {
uni.$on('updateBindingBank', () => {
// 获取列表
getList()
})
}
// 关闭监听
function removeListener() {
uni.$off('updateBindingBank')
}
// 获取列表
function getList() {
api.mine.getBankCards({}).then(rs => {
if (rs.code == 200) {
Object.assign(list, rs.data)
list.push({
bankName: "建设银行",
cardHolderName: "商旭",
cardId: "1",
cardNumber: "6217002270031535710",
cardType: "DEBIT",
createTime: null,
delFlag: "0",
isDefault: null,
updateTime: null,
userId: 13,
})
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
}
2024-12-27 15:03:48 +08:00
// 跳转
function link(url) {
uni.navigateTo({
url,
})
}
2025-02-23 13:32:05 +08:00
/**
* 右滑菜单项点击
* @param {Object} event
*/
function handleItem(event, item) {
console.log('event', event, item)
item.cb(item)
}
/**
* 删除银行卡
* @param {Object} item 银行卡信息
*/
function removeBank(item) {
util.alert({
content: '删除后不可恢复,确认删除?',
}).then(rs => {
api.mine.deleteBankCard({
path: [item.cardId],
}).then(rs => {
if (rs.code == 200) {
// 获取列表
getList()
return
}
util.alert({
content: rs.msg,
showCancel: false,
})
})
})
}
2024-12-27 15:03:48 +08:00
</script>
<template>
<view class="app">
<view class="list">
2025-02-23 13:32:05 +08:00
<uni-swipe-action ref="swipeAction">
<view class="card item" v-for="(item,index) in list" :key="index">
<uni-swipe-action-item :right-options="options" @click="handleItem($event,item)">
<view class="main ptb30 plr40">
<view class="name">{{item.bankName}}</view>
<view class="type">
<text v-if="item.cardType == 'DEBIT'">储蓄卡</text>
<text v-else-if="item.cardType == 'CREDIT'">信用卡</text>
</view>
<view class="number">{{item.cardNumber}}</view>
</view>
</uni-swipe-action-item>
</view>
</uni-swipe-action>
2024-12-27 15:03:48 +08:00
2025-02-23 13:32:05 +08:00
<view class="item add rows ptb30 plr40" @click="link('/pages/mine/setting/bankCardAdd')">
2024-12-27 15:03:48 +08:00
<view>添加银行卡</view>
<uni-icons type="right" color="#999" />
</view>
</view>
</view>
</template>
<style lang="scss">
2025-02-23 13:32:05 +08:00
// 列表
2024-12-27 15:03:48 +08:00
.list {
.item {
2025-02-23 13:32:05 +08:00
overflow: hidden;
2024-12-27 15:03:48 +08:00
margin: 20rpx;
border-radius: 25rpx;
}
// 卡片
.card {
background: linear-gradient(130deg, #ff8888 0%, #ff4142 35%, #f65253ff 60%, #ff9999 100%);
color: #fff;
// 名称
.name {
font-size: 36rpx;
font-weight: bold;
}
// 类型
.type {
color: #ffffffcc;
font-size: 26rpx;
}
// 卡号
.number {
letter-spacing: 1rpx;
margin: 30rpx 0;
font-size: 40rpx;
}
}
//
.add {
background: #fff;
// border: 2rpx solid #ff4142;
}
}
</style>