changeEmail.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="pages">
  3. <uni-forms class="form" :value="dataObj" ref="formData" :rules="rules" :border="true"
  4. label-width="100">
  5. <uni-forms-item label="新邮箱" name="email" :required="true" label-width="100">
  6. <input :value="dataObj.email" type="text" @input="binddata('email',$event.detail.value)"
  7. class="uni-input" placeholder="请输入新邮箱" />
  8. </uni-forms-item>
  9. </uni-forms>
  10. <button class="but" type="default" :loading="loading" :disabled="loading" @tap="changePass">确认</button>
  11. </view>
  12. </template>
  13. <script>
  14. import {
  15. updateEmail,
  16. } from '@/common/api.js'
  17. export default {
  18. data() {
  19. return {
  20. dataObj: {
  21. email: ""
  22. },
  23. loading: false,
  24. rules: {
  25. email: {
  26. rules: [{
  27. required: true,
  28. errorMessage: '请输入新邮箱',
  29. },
  30. {
  31. validateFunction: function(rule, value, data, callback) {
  32. var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
  33. if (!reg.test(data.email)) {
  34. callback('请输入正确的邮箱')
  35. }
  36. return true
  37. }
  38. }
  39. ]
  40. },
  41. }
  42. }
  43. },
  44. onReady() {
  45. this.$refs.formData.setRules(this.rules)
  46. },
  47. methods: {
  48. binddata(v, e) {
  49. this.dataObj[v] = e
  50. },
  51. changePass() {
  52. this.$refs.formData.submit().then(res => {
  53. this.loading = true
  54. updateEmail({
  55. email:this.dataObj.email,
  56. userId:this.$store.state.Token
  57. }).then(res =>{
  58. console.log(res)
  59. this.loading = false
  60. uni.$emit("changeUser",true)
  61. plus.nativeUI.toast('修改成功')
  62. setTimeout(() =>{
  63. uni.navigateBack({
  64. })
  65. },1000)
  66. }).catch(e =>{
  67. this.loading = false
  68. })
  69. }).catch(err => {
  70. console.log('表单错误信息:', err);
  71. })
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .form {
  78. border-bottom: 1px solid #EEEEEE;
  79. }
  80. .but {
  81. width: 600rpx;
  82. margin-top: 420rpx;
  83. background-color: #0099FF;
  84. color: #fff;
  85. }
  86. </style>