12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <template>
- <view class="pages">
- <uni-forms class="form" :value="dataObj" ref="formData" :rules="rules" :border="true"
- label-width="100">
- <uni-forms-item label="新昵称" name="name" :required="true" label-width="100">
- <input :value="dataObj.name" @input="binddata('name',$event.detail.value)"
- class="uni-input" placeholder="请输入新昵称" />
- </uni-forms-item>
- </uni-forms>
- <button class="but" type="default" :loading="loading" :disabled="loading" @tap="changePass">确认</button>
- </view>
- </template>
- <script>
- import {
- updateName,
- } from '@/common/api.js'
- export default {
- data() {
- return {
- dataObj: {
- name: ""
- },
- loading: false,
- rules: {
- name: {
- rules: [{
- required: true,
- errorMessage: '请输入新昵称',
- },
- {
- validateFunction: function(rule, value, data, callback) {
- if (data.name.length > 12) {
- callback('请输入2~12字符长度')
- }
- return true
- }
- }
- ]
- },
- }
- }
- },
- onReady() {
- this.$refs.formData.setRules(this.rules)
- },
- methods: {
- binddata(v, e) {
- this.dataObj[v] = e
- },
- changePass() {
- this.$refs.formData.submit().then(res => {
- this.loading = true
- updateName({
- name:this.dataObj.name,
- userId:this.$store.state.Token
- }).then(res =>{
- console.log(res)
- this.loading = false
- uni.$emit("changeUser",true)
- plus.nativeUI.toast('修改成功')
- setTimeout(() =>{
-
- uni.navigateBack({
-
- })
- },1000)
-
- }).catch(e =>{
- this.loading = false
- })
- }).catch(err => {
- console.log('表单错误信息:', err);
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .form {
- border-bottom: 1px solid #EEEEEE;
- }
- .but {
- width: 600rpx;
- margin-top: 420rpx;
- background-color: #0099FF;
- color: #fff;
- }
- </style>
|