edit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view>
  3. <view class="flex padding justify-between align-center">
  4. <view class="title">头像</view>
  5. <u-avatar :src="userData.avatar" size="120"></u-avatar>
  6. </view>
  7. <u-line color="#f1f1f1"></u-line>
  8. <view class="flex padding justify-between align-center">
  9. <view class="title">昵称</view>
  10. <u-input v-model="userData.nickName" :clearable="false" inputAlign="right" placeholder="请输入昵称"></u-input>
  11. </view>
  12. <u-line color="#f1f1f1"></u-line>
  13. <view class="flex padding justify-between align-center">
  14. <view class="title">性别</view>
  15. <view style="width: 200upx;">
  16. <u-input v-model="sex" type="select" :border="border" @click="sexShow = true"></u-input>
  17. <u-action-sheet :list="actionSheetList" v-model="sexShow" @click="actionSheetCallback"></u-action-sheet>
  18. </view>
  19. </view>
  20. <u-line color="#f1f1f1"></u-line>
  21. <view class="flex padding justify-between align-center" @click="calendarShow = true">
  22. <view class="title">生日</view>
  23. <view>{{birthday}}</view>
  24. <u-calendar v-model="calendarShow" mode="date" @change="change"></u-calendar>
  25. </view>
  26. <u-line color="#f1f1f1"></u-line>
  27. <view class="padding">
  28. <view class="title">个人介绍</view>
  29. </view>
  30. <view style="padding: 0 40upx">
  31. <u-input v-model="introduction" type="textarea" :clearable="false" height="140" :autoHeight="false" maxlength="60" placeholder="请输入个人简介" />
  32. </view>
  33. <view class="flex justify-end padding-right-sm padding-bottom-sm text-gray">{{introduction.length}} / 60</view>
  34. <view class="footer-fixed margin-bottom">
  35. <u-button class="custom-style" shape="circle" @click="save">保存</u-button>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. userData: {},
  44. name: 'Daniel Hua',
  45. sex: '',
  46. sexShow: false,
  47. border: true,
  48. show: false,
  49. actionSheetList: [
  50. {
  51. text: '男'
  52. },
  53. {
  54. text: '女'
  55. },
  56. {
  57. text: '保密'
  58. }
  59. ],
  60. calendarShow: false,
  61. birthday: '',
  62. introduction: '',
  63. }
  64. },
  65. onLoad(options) {
  66. this.getUserInfo(options.userId);
  67. },
  68. methods: {
  69. getUserInfo(userId) {
  70. this.$u.api.user.detail({id: userId}).then(res => {
  71. this.userData = res;
  72. if (res.gender == 1) {
  73. this.sex = '男';
  74. } else if (res.gender == 2) {
  75. this.sex = "女";
  76. } else {
  77. this.sex = "未知";
  78. }
  79. })
  80. },
  81. // 点击actionSheet回调
  82. actionSheetCallback(index) {
  83. this.sex = this.actionSheetList[index].text;
  84. },
  85. change(e) {
  86. this.birthday = e.result;
  87. },
  88. save() {
  89. if (this.$u.test.isEmpty(this.introduction) || this.$u.test.isEmpty(this.userData.nickName)) {
  90. uni.showToast({
  91. icon: "none",
  92. title: "请填写个人昵称和个人介绍",
  93. })
  94. return;
  95. } else {
  96. let data = {
  97. id: this.userData.id,
  98. name: this.userData.nickName,
  99. gender: this.sex == '男' ? 1 : this.sex == '女' ? 2 : 0,
  100. birthday: this.birthday,
  101. introduce: this.introduction,
  102. }
  103. this.$u.api.user.submit(data).then(res => {
  104. uni.showToast({
  105. icon: "none",
  106. title: "修改成功",
  107. duration: 2000,
  108. success() {
  109. uni.navigateBack({
  110. delta: 1
  111. })
  112. }
  113. })
  114. })
  115. }
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. page {
  122. background-color: #ffffff;
  123. }
  124. </style>
  125. <style lang="scss" scoped>
  126. .title {
  127. font-size: 30upx;
  128. font-weight: bold;
  129. color: #060606;
  130. padding-left: 10upx;
  131. }
  132. .custom-style {
  133. background-color: #5a3ee7;
  134. color: #ffffff;
  135. width: 600rpx;
  136. }
  137. </style>