H5自定义数字支付键盘

在这里插入图片描述
模板文件

<template>
	<div class="keybraodNum">
		<!-- 支付金额 -->
		<div class="monenyBox">
			<div class="logoBox">
				<div class="image">
					<span class="iconfont icon-icon_A"></span>
				</div>
				<div class="shopName">商家名称</div>
			</div>
			<div class="monenyNum">
				<div class="payMoneny">支付金额</div>

				<div class="content_num">
					<div></div>
					<div v-for="item in inputArray" :key="item" class="content_item">{{moneyNum[item-1]}}</div>
					<div class="blink"></div>
				</div>
			</div>
		</div>
		<!-- 支付方式 -->
		<div class="playSelete">
			<div>
				<section ref="txttype" class="selectPay" :class="brandFold==true?'openActive':''">
					<ul class="payBox">
						<li class="payWay" v-for="(item,index) in payList" @click="seletePay(index,item)">
							<div>
							<span class="iconfont iconMg-r" :class="item.cuIcon"></span>
							<span class="payNames">{{item.name}}</span>
							</div>
							<div>
								<span class="iconfont" :class="payIndex==index?'icon-radio':'icon-RadioButton'"></span>
							</div>
						</li>
					</ul>
				</section>
			</div>
			<div v-if="payList.length > 7 || nomore" v-on:click="changeFoldState" class="open">
				<span>{{brandFold?'更多支付方式':'收起'}}<i class="iconfont" :class="brandFold==false?'icon-shuangjiantoushang':'icon-shuangjiantouxia'"></i></span>
			</div>
		</div>
		 <Tips :isShow="isShow" :TipsText="TipsText" @closeDialogFather="getSonCancel"></Tips>
		<!-- 手机键盘 -->
		<div class="keyboardbox" v-if="brandFold">
			<div class="numkeyboard">
				<div class="num-area">
					<div class="row" v-for="(item,index) in numKeybordList" :key="index">
						<div :class="['item',ite===0?'z':'']" v-for="(ite,idx) in item" 
						  :key="idx" @click="input({num:ite})">{{ite}}</div>
					</div>
				</div>
				<div class="btn-area">
					<div :class="['item','del']"  @click="delNumFun">
						<span class="iconfont icon-yijianshanchu"></span>
					</div>
					<div class="confirem item"  @click="confirm">
						<div>立即</div>
						<div>支付</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

js部分

<script>
	import Tips from "@/components/tips.vue";
	export default {
		data() {
			return {
				inputArray: [1, 2, 3, 4, 5, 6], //输入金额的长度
				numKeybordList: [
					[1, 2, 3],
					[4, 5, 6],
					[7, 8, 9],
					[0, '.']
				],
				moneyNum: '',
				TipsText:'',
				showKeyboard:true,
				nomore: true,
				brandFold: false,
				isBlanced: true,
				show_key:false,
				isShow:false,
				payList: [{
						cuIcon: 'icon-weixinzhifu',
						id: 1,
						name: '微信支付',

					}, {
						cuIcon: 'icon-zhifubao',
						id: 2,
						name: '支付宝支付'
					}, {
						cuIcon: 'icon-py_yinlian',
						id: 3,
						name: '银联支付'
					}, {
						cuIcon: 'icon-yunshanfu',
						id: 4,
						name: '云闪付'
					},
					{
						cuIcon: 'icon-zhifujinge',
						id: 5,
						name: '其他支付'
					}
				],
				payIndex: 0, //默认选中第一个
				payName:'微信支付',
				isBlanced: true //用于取消选中
			};
		},
		mounted() {
			let hei = this.$refs.txttype.clientHeight;
			if (hei > 113) {
				this.brandFold = true
			} else if (hei == 113) {
				this.brandFold = false
				this.nomore = false
			}
		},
		methods: {
			getSonCancel(val){
			 this.isShow=val
			},
			confirm() {
				let exp = /^(([1-9]\d*)|\d)(\.\d{1,2})?$/;
				if(!exp.test(this.moneyNum)){
					this.isShow = true
					this.TipsText = "支付金额格式不对!"
				    return;
				}
				
			},
			delNumFun() {
				if (this.moneyNum.length == 0) return
				this.moneyNum = this.moneyNum.substring(0, this.moneyNum.length - 1)
			},
			input(op) {
				if (this.moneyNum.length <= 6) {
					this.moneyNum += op.num
					if (this.moneyNum.length == 6) {
						this.$emit('getmoneyNum', {
							moneyNum: this.moneyNum
						})

					}
				}

			},
			
			changeFoldState() {
				this.brandFold = !this.brandFold
			},
			seletePay(index, item) {
				this.payName = item.name
				this.isBlanced = !this.isBlanced;
				if (this.payIndex == index) {
					if (!this.isBlanced) {
						this.payIndex = -1;
					} else {
						this.payIndex = index;
					}
				} else {
					this.payIndex = index;
				}
			},
		},
		components:{
			Tips
		}
	}
</script>

css部分

<style lang="scss" scoped>
	.monenyBox {

		margin: 0 auto;
		background-color: #fff;
		padding: 1rem 0.5rem 1rem;

		.logoBox {
			display: flex;
			flex-direction: row;
			align-items: center;

			.image {
				width: 1.5rem;
				height: 1.5rem;

				
			}

			.shopName {
				margin-left: 0.5rem;
				font-size: 0.8rem;
			}
		}

		.monenyNum {
			background-color: #ccc;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 1rem 0.5rem;
			margin-top: 1rem;
			height: 1.5rem;

			.payMoneny {
				font-size: .8rem;
			}

			.content_num {
				display: flex;
				align-items: center;
				flex-direction: row;

				.content_item {
					font-size: 1.3rem;
				}

				.blink {
					animation: 1s blink infinite;
					border: none;
					margin: 0;
					height: 1.2rem;
					width: 2px;
					// position:absolute;
					// left:174px;
					// top:5px;
					z-index: 1;
				}
			}
		}
	}

	// 支付方式
	.playSelete {
		margin: 0.3rem auto;
		background-color: #fff;
		padding: .5rem 0.5rem .5rem;

		.selectPay {

			.payBox {
				padding: 0px;
				margin: 0px;

				.payWay {
					height: 2rem;
					display: flex;
					box-sizing: border-box;
					font-size: .7rem;
					align-items: center;
					justify-content: space-between;
					align-items: center;
					line-height: 2rem;

					.iconMg-r {
						margin-right: 0.1rem;
					}
					.payNames{
						position: relative;
						top:-2px;
					}
					.active {
						color: #1989fa;
					}
				}
			}
		}

		.openActive {
			height: 6rem;
			overflow: hidden;
		}

		.open {
			text-align: center;
			font-size: .7rem;
			color: #1989fa;
		}
	}

	.keyboardbox {
		background-color: #f0f0f0;
		position: fixed;
		bottom: 0px;
		// top:0px;
		left: 0px;
		right: 0px;
		z-index: 100;

		.numkeyboard {
			height: 11rem;
			display: flex;
			background-color: #ebedf0;

			.btn-area {
				width: 5rem;
				height: 11rem;
				display: flex;
				flex-direction: column;
				margin-right: 0.2rem;

				.item {
					width: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-grow: 1;

				}

				.del {
					background-color: #fff;
					color: #000;
					height: 10%;
					border-radius: 0.5rem;
					margin-bottom: 0.32rem;

					&.active {
						background-color: #f1f3f5;
					}
				}

				.confirem {
					background-color: #1989fa;
					color: #FFFFFF;
					height: 6.7rem;
					border-radius: 0.5rem;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					margin-bottom: 0.35rem;

					&.active {
						background-color: #0570db;
					}
				}
			}

			.num-area {
				flex-grow: 1;
				display: flex;
				flex-wrap: wrap;

				.row {
					width: 98.5%;
					height: 25%;
					display: flex;
					// margin-top: 1px;

					.item {
						flex-grow: 1;
						height: 2.4rem;
						display: flex;
						justify-content: center;
						align-items: center;
						background-color: #FFFFFF;
						border-right: 1px solid #ebedf0;
						width: 32.5%;
						font-size: 1rem;
						font-weight: 600;
						border-radius: 0.5rem;
						margin-left: 0.2rem;

						&.active {
							background-color: #ebedf0;
						}

						&.z {
							flex-grow: 2;
							width: 66.66%;
						}

						&.disabled {
							background: #FFFFFF;
							color: #B9B9B9;
						}
					}
				}

			}
		}
	}

	@keyframes blink {
		50% {
			color: #000;
			background: #0570db;
			opacity: .5;
		}
	}
</style>

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值