// A code block
var foo = 'bar';
<template>
<!-- 我的银行卡 start -->
<view class="container">
<!-- 头部图片 -->
<view class="assetstop">
<image class="asstop" src="/static/common/assetop.png" mode=""></image>
<image class="asstopimg" src="/static/common/my-card.png" mode=""></image>
<image @tap="addBank" class="addBank" src="/static/common/add-bank.png" mode=""></image>
</view>
<!-- 银行卡 start -->
<view class="back">
<view class="box">
<view class="bxre" v-for="(item,index) in list" :key="index">
<view :style="item.txtStyle" class="card" @touchstart="touchS" @touchmove="touchM" :data-index="index" @touchend="touchE">
<view class="top">
<image :src="item.bandLogo" mode="aspectFill"></image>
<view class="right">
<view class="title">{{item.backName}}</view>
<text>储蓄卡</text>
</view>
</view>
<view class="bottom-card">
{{item.backNo}}
</view>
</view>
<view class="del">
<view></view>
<view class="right" @tap="delItem(item.id)">解除绑定</view>
</view>
</view>
</view>
</view>
<!-- 银行卡 end -->
<key-words :show_key="show_key" :show_subTitle='show_subTitle' @closeFuc="closeFuc" @getPassword="getPassword"></key-words>
<!-- 弹窗 start -->
<custom-toast ref="toast" :toastType="1" :totastTitle="'确定解除绑定?'" @sureOperate="sureDelete"></custom-toast>
<!-- 弹窗 end -->
</view>
<!-- 我的银行卡 end -->
</template>
<script>
import keyWords from "@/componets/bian-keywords/index.vue"
import customToast from '@/componets/CustomToast.vue'
export default {
data() {
return {
delBtnWidth: 100,
startX: '',
list: [],
id: '',
show_key: false,
show_subTitle: false,
userid: ""
}
},
onLoad() {
this.userid = uni.getStorageSync('userid')
this.bankList()
},
onShow() {
this.bankList()
},
methods: {
bankList() {
let data = {
userId: this.userid
}
this.$LoadingMsg('获取数据中')
this.$Request.getToken(this.$api.userBackList, data).then(res => {
if (res.code == 0) {
uni.hideLoading()
for (let i in res.data) {
res.data[i].txtStyle = 'left:0px'
}
this.list = res.data
}
})
},
touchS: function(e) {
if (e.touches.length == 1) {
this.startX = e.touches[0].clientX
}
},
touchM: function(e) {
if (e.touches.length == 1) {
var moveX = e.touches[0].clientX;
var disX = this.startX - moveX;
var delBtnWidth = this.delBtnWidth;
var txtStyle = "";
if (disX == 0 || disX < 0) {
txtStyle = "left:0px";
} else if (disX > 0) {
txtStyle = "left:-" + disX + "px";
if (disX >= delBtnWidth) {
txtStyle = "left:-" + delBtnWidth + "px";
}
}
var index = e.currentTarget.dataset.index;
var list = this.list;
console.log(index)
list[index].txtStyle = txtStyle;
this.list = list;
}
},
touchE: function(e) {
if (e.changedTouches.length == 1) {
var endX = e.changedTouches[0].clientX;
var disX = this.startX - endX;
var delBtnWidth = this.delBtnWidth;
var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
var index = e.currentTarget.dataset.index;
var list = this.list;
list[index].txtStyle = txtStyle;
this.list = list
}
},
delItem(id) {
this.id = id
this.$refs.toast.toastPanel();
},
sureDelete() {
let data = {
id: this.id
}
this.$LoadingMsg('正在删除中')
this.$Request.delete(this.$api.delBack, data).then(res => {
if (res.code == 0) {
uni.hideLoading()
this.bankList()
}
})
},
closeFuc() {
this.show_key = false
},
confirm() {
this.show_key = true
},
getPassword(msg) {
console.log(msg)
let data = {
userId: this.userid,
pwd: msg.password
}
this.$LoadingMsg('正在设置密码')
this.$Request.postToken(this.$api.addPwd, data).then(res => {
if (res.code == 0) {
this.show_key = false
setTimeout(function() {
uni.showToast({
title: res.msg,
icon: 'none',
success() {
setTimeout(function() {
uni.navigateTo({
url: "/pages/mine/assets/add-bank"
})
}, 2000)
}
})
}, 0)
}
})
},
addBank() {
let that = this
let data = {
userId: that.userid
}
that.$Request.getToken(this.$api.userHasPwd, data).then(res => {
if (res.code == 0) {
if (res.data == true) {
uni.navigateTo({
url: "/pages/mine/assets/add-bank"
})
} else {
that.show_key = true
}
}
})
}
},
components: {
keyWords,
customToast
}
}
</script>
<style lang="scss">
page {
background: #F8F8F8;
}
.assetstop {
position: relative;
.asstop {
width: 100%;
height: 200rpx;
position: absolute;
}
.asstopimg {
position: absolute;
top: 50rpx;
left: 25rpx;
width: 300rpx;
height: 84rpx;
background-color: #ffffff;
border-radius: 40rpx 40rpx 40px;
}
.addBank {
position: absolute;
top: 50rpx;
right: 50rpx;
width: 50rpx;
height: 50rpx;
}
}
.back {
position: absolute;
top: 150rpx;
background: #FFFFFF;
left: 4%;
width: 92%;
border-radius: 20rpx;
padding-top: 64rpx;
padding-bottom: 80rpx;
.box {
margin: 0 35rpx;
margin-bottom: 20rpx;
.bxre {
position: relative;
.card {
width: 100%;
height: 242rpx;
background-image: linear-gradient(90deg,
#ff5252 0%,
#9a0606 100%);
border-radius: 20rpx;
position: relative;
margin-bottom: 20rpx;
z-index: 999;
.top {
display: flex;
flex-direction: row;
align-items: center;
padding-left: 35rpx;
padding-top: 28rpx;
image {
width: 50rpx;
height: 50rpx;
}
.right {
margin-left: 20rpx;
.title {
font-size: 24rpx;
line-height: 24rpx;
color: #FFFFFF;
}
text {
display: block;
font-size: 20rpx;
line-height: 20rpx;
margin-top: 10rpx;
color: #FFFFFF;
}
}
}
.bottom-card {
position: absolute;
right: 63rpx;
bottom: 52rpx;
color: #FFFFFF;
}
}
.del {
width: 100%;
height: 242rpx;
background-color: #ff4f4f;
border-radius: 20rpx;
position: absolute;
top: 0;
z-index: 99;
text-align: right;
line-height: 242rpx;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.right {
color: #fefefe;
font-size: 28rpx;
margin-right: 40rpx;
}
}
}
}
}
</style>