微信小程序自定义键盘 内部虚拟支付(2)

Page({ /** * 页面的初始数据 */ data: { inputPassword: '', //输入的密码 passwordInputHidden: true,//hidden是true 默认隐藏 pay_type: '',//支付方式 password: 123456,//设置的密码 这里写死 实际开发中后台专门设置一个表存储用户设置的密码 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, pay(e) { //你选择的支付方式 var pay_type = e.currentTarget.dataset.pay_type; var _this = this; if (pay_type == 'weipay') { //此处写入微信支付需要执行的代码不做过多介绍 } else { //内部支付 打开键盘 _this.passwordInputHidden(); } }, inputPassword(e) { //键盘输入的密码 赋值给inputPassword this.data.inputPassword = this.data.inputPassword + e.currentTarget.dataset.key; this.setData({ inputPassword: this.data.inputPassword }); //当输入密码正确时 if (this.data.inputPassword.length == 6 && this.data.password == this.data.inputPassword) { this.passwordInputHidden();//关闭小键盘 } //当输入密码错误时 给个提示 并且把输入的密码清零 if (this.data.inputPassword.length == 6 && this.data.password != this.data.inputPassword) { wx.showModal({ title: "提示", content: "输入密码错误", }) this.setData({ inputPassword: '' }); } }, passwordInputHidden() { this.setData({ passwordInputHidden: !this.data.passwordInputHidden //取反 打开关闭小键盘 }); this.setData({ inputPassword: '' }); }, //删除输入错误的密码 clear() { var index = this.data.inputPassword.length; if (index > 0) { var inputPassword = this.data.inputPassword.substr(0, index - 1); this.setData({ inputPassword: inputPassword }); } }, })

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c167c349b36db8d09d85e81b1770dbe0.html