paymentPwd.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="paymentPwd-container">
  3. <text class="pwd-describe">{{nowSetp == 1 ? '请设置6位数字支付密码' : nowSetp == 2 ? '请再次输入密码' : ''}}</text>
  4. <view class="sms-item" @tap="showKeyboard=!showKeyboard">
  5. <u-message-input mode="bottomLine" :maxlength="6" v-model="value" :dot-fill="true" :disabled-keyboard="true"></u-message-input>
  6. </view>
  7. <view class="btn-con">
  8. <u-button class="handle-btn" type="info" size="medium" @click="cancel">取消</u-button>
  9. <u-button class="handle-btn" type="primary" size="medium" @click="submit">确定</u-button>
  10. </view>
  11. <!-- 数字键盘 -->
  12. <u-keyboard ref="uKeyboard" :dot-enabled="false" :mask="false" :tooltip="false" v-model="showKeyboard" @change="valChange" @backspace="backspace"></u-keyboard>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. data() {
  18. return {
  19. nowSetp: 1, // 当前第几次设置密码
  20. value: '', //输入的内容
  21. showKeyboard: false, // 是否打开键盘
  22. oPwd: '', // 第一次密码
  23. tPwd: '', // 第二次密码
  24. }
  25. },
  26. onShow() {
  27. },
  28. onLoad() {
  29. //因为此时实例没有挂载完成,需要延迟操作
  30. setTimeout(() => {
  31. this.showKeyboard = true
  32. }, 50)
  33. },
  34. methods:{
  35. // 按键被点击(点击退格键不会触发此事件)
  36. valChange(val) {
  37. // 将每次按键的值拼接到value变量中,注意+=写法
  38. if(this.value.length < 6){
  39. this.value += val
  40. }
  41. },
  42. // 退格键被点击
  43. backspace() {
  44. // 删除value的最后一个字符
  45. if(this.value.length) this.value = this.value.substr(0, this.value.length - 1)
  46. },
  47. // 确定
  48. submit(){
  49. if(!this.value || this.value.length < 6){
  50. uni.showToast({ title: '请输入6位数字支付密码', icon: 'none' })
  51. }else{
  52. if(this.nowSetp == 1){
  53. this.oPwd = this.value
  54. this.value = ''
  55. this.nowSetp++
  56. this.showKeyboard = true
  57. }else if(this.nowSetp == 2){
  58. this.tPwd = this.value
  59. this.checkPwd()
  60. }
  61. }
  62. },
  63. // 密码校验
  64. checkPwd(){
  65. if(this.oPwd == this.tPwd){
  66. // 请求接口
  67. uni.showToast({ title: '支付密码设置成功', icon: 'none' })
  68. setTimeout(()=>{
  69. uni.navigateBack({
  70. delta: 1
  71. })
  72. }, 2000)
  73. }else{
  74. uni.showToast({ title: '两次密码不一致请重新输入', icon: 'none' })
  75. this.value = ''
  76. this.showKeyboard = true
  77. }
  78. },
  79. // 取消
  80. cancel(){
  81. this.oPwd = ''
  82. this.tPwd = ''
  83. this.value = ''
  84. this.nowSetp = 1
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="less">
  90. .paymentPwd-container{
  91. width: 100%;
  92. padding: 0 30rpx;
  93. box-sizing: border-box;
  94. background-color: #fff;
  95. .pwd-describe{
  96. display: block;
  97. color: #606266;
  98. padding: 80rpx 0 70rpx;
  99. text-align: center;
  100. }
  101. .btn-con{
  102. display: flex;
  103. justify-content: space-between;
  104. padding-top: 130rpx;
  105. .handle-btn{
  106. display: inline-block;
  107. width: 45%;
  108. margin: 0 auto;
  109. text-align: center;
  110. }
  111. }
  112. }
  113. </style>