PayPasswordAgin.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view :class="['qn-page-' + theme]">
  3. <view class="back-icon" @click="backPage"><u-icon name="close" size="32"></u-icon></view>
  4. <view>
  5. <view class="top-view">
  6. <view class="title">设置支付密码</view>
  7. <view class="desc">请再次填写确认</view>
  8. </view>
  9. <view class="u-flex u-row-center" @click="openKey">
  10. <u-message-input :mask="false" mode="box" :maxlength="6" :dot-fill="true" v-model="password" :disabled-keyboard="true" @finish="finish"></u-message-input>
  11. </view>
  12. <view class="confirm-btn primary-btn" @click="confirm">完成</view>
  13. </view>
  14. <u-keyboard
  15. default=""
  16. ref="uKeyboard"
  17. mode="number"
  18. :mask="false"
  19. :mask-close-able="false"
  20. :dot-enabled="false"
  21. v-model="keyboard_show"
  22. :safe-area-inset-bottom="true"
  23. :tooltip="false"
  24. @change="onChange"
  25. @backspace="onBackspace"
  26. ></u-keyboard>
  27. <u-modal
  28. v-model="model_show"
  29. :show-cancel-button="true"
  30. content="是否要放弃设置支付密码?"
  31. cancel-text="否"
  32. confirm-text="是"
  33. :confirm-color="primaryColor"
  34. @confirm="modelConfirm"
  35. ></u-modal>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. model_show: false,
  43. keyboard_show: true,
  44. password: '',
  45. agin_pwd: ''
  46. };
  47. },
  48. computed: {
  49. userInfo() {
  50. return this.$store.state.userStatus;
  51. }
  52. },
  53. onLoad(options) {
  54. this.agin_pwd = options.password;
  55. },
  56. methods: {
  57. backPage() {
  58. this.model_show = true;
  59. },
  60. openKey() {
  61. this.keyboard_show = true;
  62. },
  63. //按键被点击(不包含退格键被点击)
  64. onChange(val) {
  65. if (this.password.length < 6) {
  66. this.password += val;
  67. }
  68. if (this.password.length >= 6) {
  69. if (this.agin_pwd !== this.password) {
  70. this.password = '';
  71. this.$u.toast('两次密码输入不一致');
  72. } else {
  73. this.keyboard_show = false;
  74. }
  75. }
  76. },
  77. //键盘退格键被点击
  78. onBackspace(e) {
  79. if (this.password.length > 0) {
  80. this.password = this.password.substring(0, this.password.length - 1);
  81. }
  82. },
  83. modelConfirm() {
  84. uni.navigateBack();
  85. },
  86. confirm() {
  87. if (!this.userInfo.payPassword) {
  88. this.$u.api
  89. .addpayPassword({
  90. id: this.userInfo.id,
  91. payPassword: this.password
  92. })
  93. .then(res => {
  94. this.$u.toast('设置成功');
  95. this.$store.commit('commit_userStatus', {
  96. ...this.userInfo,
  97. payPassword: this.password
  98. });
  99. setTimeout(res => {
  100. uni.navigateBack();
  101. }, 2000);
  102. });
  103. } else {
  104. this.$u.api
  105. .updatePayPassword({
  106. id: this.userInfo.id,
  107. payPassword: this.password
  108. })
  109. .then(res => {
  110. this.$u.toast('修改成功');
  111. this.$store.commit('commit_userStatus', {
  112. ...this.userInfo,
  113. payPassword: this.password
  114. });
  115. setTimeout(res => {
  116. uni.navigateBack();
  117. }, 2000);
  118. });
  119. }
  120. },
  121. finish() {
  122. console.log(11111);
  123. }
  124. }
  125. };
  126. </script>
  127. <style>
  128. page {
  129. background-color: #ffffff;
  130. }
  131. </style>
  132. <style lang="scss" scoped>
  133. .top-view {
  134. text-align: center;
  135. padding-top: 300rpx;
  136. .title {
  137. font-size: 32rpx;
  138. font-weight: bold;
  139. padding-bottom: 30rpx;
  140. }
  141. .desc {
  142. padding-bottom: 100rpx;
  143. }
  144. }
  145. .confirm-btn {
  146. width: 680rpx;
  147. margin: 40rpx auto;
  148. color: #ffffff;
  149. background-color: $uni-color-primary;
  150. line-height: 80rpx;
  151. height: 80rpx;
  152. text-align: center;
  153. border-radius: 12rpx;
  154. position: relative;
  155. z-index: 10070;
  156. }
  157. .back-icon {
  158. position: fixed;
  159. top: 100rpx;
  160. left: 40rpx;
  161. z-index: 999999;
  162. }
  163. </style>