edit.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="container">
  3. <view class="example">
  4. <uni-forms ref="form" :model="user" labelWidth="80px">
  5. <uni-forms-item label="用户昵称" name="nickName">
  6. <uni-easyinput v-model="user.nickName" placeholder="请输入昵称" type="nickname" @blur="nickNameBlur"/>
  7. </uni-forms-item>
  8. <uni-forms-item label="性别" name="sex" required>
  9. <uni-data-checkbox v-model="user.sex" :localdata="sexs" />
  10. </uni-forms-item>
  11. </uni-forms>
  12. <button type="primary" @click="submit" :style="{backgroundColor: themeColor}">提交</button>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. getMiniAppUserInfo,
  19. updateMiniAppUser
  20. } from "@/api/basics/miniAppUser.js"
  21. import storage from '@/utils/storage'
  22. import constant from '@/utils/constant'
  23. export default {
  24. data() {
  25. return {
  26. user: {
  27. nickName: "",
  28. sex: ""
  29. },
  30. sexs: [{
  31. text: '女',
  32. value: "0"
  33. }, {
  34. text: '男',
  35. value: "1"
  36. }],
  37. rules: {
  38. nickName: {
  39. rules: [{
  40. required: true,
  41. errorMessage: '用户昵称不能为空'
  42. }]
  43. }
  44. },
  45. themeColor:getApp().globalData.config.appInfo.themeColor
  46. }
  47. },
  48. onLoad() {
  49. this.getUser()
  50. },
  51. onReady() {
  52. this.$refs.form.setRules(this.rules)
  53. },
  54. methods: {
  55. getUser() {
  56. getMiniAppUserInfo().then(response => {
  57. this.user = response.data
  58. })
  59. },
  60. submit(ref) {
  61. this.$refs.form.validate().then(res => {
  62. updateMiniAppUser(this.user).then(response => {
  63. this.$modal.msgSuccess("修改成功")
  64. })
  65. })
  66. },
  67. nickNameBlur(e){
  68. this.user.nickName = e.detail.value
  69. console.log(e);
  70. }
  71. }
  72. }
  73. </script>
  74. <style lang="scss">
  75. page {
  76. background-color: #ffffff;
  77. }
  78. .example {
  79. padding: 15px;
  80. background-color: #fff;
  81. }
  82. .segmented-control {
  83. margin-bottom: 15px;
  84. }
  85. .button-group {
  86. margin-top: 15px;
  87. display: flex;
  88. justify-content: space-around;
  89. }
  90. .form-item {
  91. display: flex;
  92. align-items: center;
  93. flex: 1;
  94. }
  95. .button {
  96. display: flex;
  97. align-items: center;
  98. height: 35px;
  99. line-height: 35px;
  100. margin-left: 10px;
  101. }
  102. </style>