paymentPwd.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. uni.$emit('setPswSuccess', {success: true})
  69. setTimeout(()=>{
  70. uni.navigateBack({
  71. delta: 1
  72. })
  73. }, 2000)
  74. }else{
  75. uni.showToast({ title: '两次密码不一致请重新输入', icon: 'none' })
  76. this.value = ''
  77. this.showKeyboard = true
  78. }
  79. },
  80. // 取消
  81. cancel(){
  82. this.oPwd = ''
  83. this.tPwd = ''
  84. this.value = ''
  85. this.nowSetp = 1
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="less">
  91. .paymentPwd-container{
  92. width: 100%;
  93. padding: 0 30rpx;
  94. box-sizing: border-box;
  95. background-color: #fff;
  96. .pwd-describe{
  97. display: block;
  98. color: #606266;
  99. padding: 80rpx 0 70rpx;
  100. text-align: center;
  101. }
  102. .btn-con{
  103. display: flex;
  104. justify-content: space-between;
  105. padding-top: 130rpx;
  106. .handle-btn{
  107. display: inline-block;
  108. width: 45%;
  109. margin: 0 auto;
  110. text-align: center;
  111. }
  112. }
  113. }
  114. </style>