uniapp 左滑删除详细介绍

// 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, //删除按钮宽度单位(rpx)
				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()
						// this.list = res.data
						for (let i in res.data) {
							res.data[i].txtStyle = 'left:0px'
						}
						this.list = res.data
					}
				})
			},
			touchS: function(e) {
				// console.log('touchS')
				if (e.touches.length == 1) {
					//设置触摸起始点水平方向位置
					this.startX = e.touches[0].clientX
					// console.log(this.startX)
				}
			},
			touchM: function(e) {
				// console.log('touchM')
				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) { //如果移动距离小于等于0,说明向右滑动,文本层位置不变
						txtStyle = "left:0px";
					} else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离
						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;
					// console.log(list[index].txtStyle)
					//更新列表的状态
					this.list = list;
				}
			},
			touchE: function(e) {
				// console.log('touchE')
				if (e.changedTouches.length == 1) {
					//手指移动结束后水平位置
					var endX = e.changedTouches[0].clientX;
					//触摸开始与结束,手指移动的距离
					var disX = this.startX - endX;
					var delBtnWidth = this.delBtnWidth;
					//如果距离小于删除按钮的1/2,不显示删除按钮
					var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
					//获取手指触摸的是哪一项
					var index = e.currentTarget.dataset.index;
					var list = this.list;
					list[index].txtStyle = txtStyle;
					// console.log(list[index].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) {
				//msg:密码   例如:{msg:123456}
				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>


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值