paypassword.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="main bg-white margin-top padding-tb-sm">
  3. <view class="flex justify-between align-center margin-top-sm padding-lr-sm">
  4. <view class="flex-sub margin-right-sm">
  5. <u-input v-model="password" :type="type" maxlength="6" placeholder="请设置支付密码(6位数字)" :border="border" />
  6. </view>
  7. </view>
  8. <view class="flex justify-between align-center margin-top-sm padding-lr-sm">
  9. <view class="flex-sub margin-right-sm">
  10. <u-input v-model="code" type="number" maxlength="6" placeholder="请输入验证码" :border="border" />
  11. </view>
  12. <u-verification-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-verification-code>
  13. <u-button @click="getCode">{{tips}}</u-button>
  14. </view>
  15. <view class="cu-bar bg-white tabbar" style="position: fixed;bottom: 0;width: 100%;">
  16. <view class="submit" style="background-color: #0B73B9;color: white;" @click="editpwd">
  17. 立即保存
  18. </view>
  19. </view>
  20. <view class="cu-tabbar-height"></view>
  21. <view class="cu-tabbar-height"></view>
  22. <u-no-network></u-no-network>
  23. </view>
  24. </template>
  25. <script>
  26. import store from '@/store'
  27. export default {
  28. onLoad(options) {
  29. this.info = store.getters['getusers']
  30. },
  31. mounted() {
  32. },
  33. data() {
  34. return {
  35. code: '',
  36. type: 'number',
  37. border: true,
  38. tips: '',
  39. seconds: 60,
  40. password: '',
  41. info: ""
  42. }
  43. },
  44. methods: {
  45. codeChange(text) {
  46. this.tips = text;
  47. },
  48. getCode() {
  49. if (this.password.length != 6) {
  50. uni.showToast({
  51. title: "密码最低六位数",
  52. icon: "none"
  53. })
  54. return false
  55. }
  56. if (!this.$util.isNum(this.password)) {
  57. uni.showToast({
  58. title: "密码只能为数字",
  59. icon: "none"
  60. })
  61. return false
  62. }
  63. if (parseInt(this.password) / 100000 < 1) {
  64. uni.showToast({
  65. title: "密码不能以0开头",
  66. icon: "none"
  67. })
  68. return false
  69. }
  70. if (this.$refs.uCode.canGetCode) {
  71. // 模拟向后端请求验证码
  72. uni.showLoading({
  73. title: '正在获取验证码'
  74. })
  75. setTimeout(() => {
  76. uni.hideLoading();
  77. // 这里此提示会被this.start()方法中的提示覆盖
  78. uni.showToast({
  79. title: "验证码已发送",
  80. icon: "none"
  81. })
  82. // 通知验证码组件内部开始倒计时
  83. this.$refs.uCode.start();
  84. }, 2000);
  85. } else {
  86. uni.showToast({
  87. title: "结束后再发送",
  88. icon: "none"
  89. })
  90. }
  91. },
  92. end() {
  93. //倒计时结束
  94. },
  95. start: async function() {
  96. let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
  97. phone: this.info.phone,
  98. type: 3
  99. })
  100. },
  101. editpwd: async function() {
  102. let res = await this.$request.post("/api/v1/user/updatePayPassword", {
  103. verify_code: this.code,
  104. pay_password: this.password
  105. })
  106. if (res.status == 0) {
  107. uni.showToast({
  108. title: "设置成功",
  109. icon: "none",
  110. duration: 1500
  111. })
  112. setTimeout(() => {
  113. uni.navigateBack({
  114. delta: 1
  115. })
  116. }, 1500)
  117. } else {
  118. uni.showToast({
  119. title: res.message,
  120. icon: "none",
  121. duration: 1500
  122. })
  123. }
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss">
  129. page {
  130. background-color: #fff;
  131. }
  132. .main {}
  133. </style>