Changepassword.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="main">
  3. <u--form labelPosition="left" labelWidth='180' :model="model1" :rules="rules" ref="form1">
  4. <u-form-item label="旧登录密码" prop="userInfo.password" borderBottom ref="item1" required>
  5. <u--input v-model="model1.userInfo.password" border="none" clearable placeholder="请输入"></u--input>
  6. </u-form-item>
  7. <u-form-item label="新登录密码" prop="userInfo.newPassword" borderBottom ref="item1" required>
  8. <u--input v-model="model1.userInfo.newPassword" border="none" clearable placeholder="请输入"></u--input>
  9. </u-form-item>
  10. </u-form-item>
  11. <u-form-item label="请再次输入" prop="userInfo.confirmPassword" borderBottom ref="item1" required>
  12. <u--input v-model="model1.userInfo.confirmPassword" border="none" clearable
  13. placeholder="请输入"></u--input>
  14. </u-form-item>
  15. </u--form>
  16. <view class="tijiao">
  17. <u-button type="primary" @click="submit">确定修改</u-button>
  18. </view>
  19. <u-notify ref="uNotify" message=""></u-notify>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. dataForm: {
  27. password: "",
  28. newPassword: "",
  29. confirmPassword: "",
  30. },
  31. model1: {
  32. userInfo: {
  33. password: '',
  34. newPassword: '',
  35. confirmPassword: '',
  36. },
  37. },
  38. rules: {
  39. 'userInfo.password': {
  40. type: 'string',
  41. required: true,
  42. message: '请填写旧登录密码',
  43. trigger: ['blur', 'change']
  44. },
  45. 'userInfo.newPassword': {
  46. type: 'string',
  47. required: true,
  48. message: '请填写新登录密码',
  49. trigger: ['blur', 'change']
  50. },
  51. 'userInfo.confirmPassword': {
  52. type: 'string',
  53. required: true,
  54. message: '请填写新登录密码',
  55. trigger: ['blur', 'change']
  56. },
  57. },
  58. };
  59. },
  60. onReady() {
  61. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  62. this.$refs.form1.setRules(this.rules)
  63. },
  64. methods: {
  65. submit() {
  66. this.$refs.form1.validate().then(res => {
  67. if (this.model1.userInfo.newPassword != this.model1.userInfo.confirmPassword) {
  68. uni.$u.toast('您的新密码不一致,请重新输入')
  69. } else {
  70. //uni.$u.toast('校验通过')
  71. // console.log('111111111111111111',this.model1.userInfo)
  72. let postdata = {
  73. "newPassword": this.model1.userInfo.newPassword,
  74. "password": this.model1.userInfo.password
  75. }
  76. this.$api.put('/user/password', postdata)
  77. .then(res => {
  78. if (res.data.code == 0) {
  79. uni.navigateTo({
  80. url: '/pages/login/login'
  81. })
  82. } else {
  83. this.$refs.uNotify.error(res.data.msg)
  84. }
  85. })
  86. }
  87. }).catch(errors => {
  88. uni.$u.toast('校验失败')
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped>
  95. .u-form{
  96. margin-top:24rpx ;
  97. padding: 32rpx 32rpx 32rpx 40rpx;
  98. background-color: #fff;
  99. }
  100. </style>