changeCode.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="wrap">
  3. <view class="user-info">
  4. <view class="b-item">
  5. <view class="s-tit">旧登录码</view>
  6. <input class="s-input" :value="form.oldCode" maxlength="12" @input="onInput" data-field="oldCode" placeholder="必须输入旧的" />
  7. </view>
  8. <view class="b-item">
  9. <view class="s-tit">新登录码</view>
  10. <input class="s-input" :value="form.newCode" maxlength="12" @input="onInput" data-field="newCode" placeholder="字符长度3-12" />
  11. </view>
  12. <view class="b-item">
  13. <view class="s-tit">重复输入</view>
  14. <input class="s-input" :value="form.repeatCode" maxlength="12" @input="onInput" @blur="onBlur" data-field="repeatCode" placeholder="重复新的登录码" />
  15. </view>
  16. </view>
  17. <view class="btn-save" :class="{ disable: disable.submit }" @click="onSave">保存修改</view>
  18. </view>
  19. </template>
  20. <script>
  21. import { changeCode } from '@/service/api/user.js';
  22. import mixinsCommon from '@/mixins/common.js';
  23. import mixinsAuth from '@/mixins/auth.js';
  24. export default {
  25. mixins: [mixinsCommon, mixinsAuth],
  26. data() {
  27. return {
  28. form: {
  29. oldCode: '',
  30. newCode: '',
  31. repeatCode: ''
  32. },
  33. disable: {
  34. submit: false
  35. }
  36. };
  37. },
  38. onLoad() {},
  39. methods: {
  40. onBlur(e) {
  41. console.log('onBlur', e);
  42. const field = e.target.dataset.field;
  43. if (field === 'repeatCode') {
  44. if (this.newCode) {
  45. if (this.repeatCode != this.newCode) {
  46. return this.$logic.showToast('重复输入新的登录码不对');
  47. }
  48. }
  49. }
  50. },
  51. onInput(e) {
  52. console.log('onInput', e);
  53. const field = e.target.dataset.field;
  54. this.form[field] = e.detail.value;
  55. },
  56. onSave() {
  57. if (this.disable.submit) {
  58. return;
  59. }
  60. if (!this.form.oldCode) {
  61. return this.$logic.showToast('旧登录码不能为空');
  62. }
  63. if (!this.form.newCode) {
  64. return this.$logic.showToast('新登录码不能为空');
  65. }
  66. if (this.form.newCode.length < 3) {
  67. return this.$logic.showToast('新登录码长度不能小于3位');
  68. }
  69. if (this.form.repeatCode != this.form.newCode) {
  70. return this.$logic.showToast('重复输入新登录码不对');
  71. }
  72. this.disable.submit = true;
  73. changeCode(this.form.oldCode, this.form.newCode).then(([err, res]) => {
  74. console.log('changeCode', err, res);
  75. this.disable.submit = false;
  76. if (!err) {
  77. this.$logic.showToast('修改成功').then(([err, res]) => {
  78. uni.reLaunch({
  79. url: '/answer_pages/user/mine'
  80. });
  81. });
  82. }
  83. });
  84. }
  85. }
  86. };
  87. </script>
  88. <style lang="scss">
  89. page {
  90. padding-bottom: env(safe-area-inset-bottom);
  91. background: $pq-bg-color;
  92. }
  93. .wrap {
  94. padding: 0 40upx;
  95. }
  96. .user-info {
  97. margin-top: 40upx;
  98. background: #fff;
  99. border-radius: 20upx;
  100. .b-item {
  101. padding: 0 40upx;
  102. border-bottom: 1upx solid $pq-bg-color;
  103. height: 100upx;
  104. display: flex;
  105. align-items: center;
  106. position: relative;
  107. .s-tit {
  108. color: #000000;
  109. font-size: 26upx;
  110. }
  111. .s-input {
  112. flex: 1;
  113. color: #808080;
  114. text-align: right;
  115. font-size: 26upx;
  116. }
  117. }
  118. }
  119. .btn-save {
  120. margin-top: 50upx;
  121. height: 100upx;
  122. line-height: 100upx;
  123. text-align: center;
  124. color: #fff;
  125. font-size: 32upx;
  126. background: #da5650;
  127. border-radius: 50upx;
  128. letter-spacing: 10upx;
  129. }
  130. </style>