edit.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <view class="flex padding justify-between align-center" @click="upload">
  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">昵称<text class="text-red">*</text></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">
  22. <view class="title">手机号码<text class="text-red">*</text></view>
  23. <u-input v-model="userData.phone" :clearable="false" inputAlign="right" placeholder="请填写手机号码"></u-input>
  24. </view>
  25. <u-line color="#f1f1f1"></u-line>
  26. <view class="flex padding justify-between align-center" @click="calendarShow = true">
  27. <view class="title">生日</view>
  28. <view>{{userData.birthday}}</view>
  29. <u-calendar v-model="calendarShow" mode="date" @change="change"></u-calendar>
  30. </view>
  31. <u-line color="#f1f1f1"></u-line>
  32. <view class="padding">
  33. <view class="title">个人介绍<text class="text-red">*</text></view>
  34. </view>
  35. <view style="padding: 0 40upx">
  36. <u-input v-model="introduce" type="textarea" :clearable="false" height="140" :autoHeight="false" maxlength="60" placeholder="请输入个人简介" />
  37. </view>
  38. <view class="flex justify-end padding-right-sm padding-bottom-sm text-gray">{{introduce.length}} / 60</view>
  39. <view style="height: 120upx;"></view>
  40. <view class="footer-fixed margin-bottom">
  41. <u-button class="custom-style" shape="circle" @click="save">保存</u-button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. userData: {},
  50. sex: '',
  51. sexShow: false,
  52. border: true,
  53. show: false,
  54. actionSheetList: [
  55. {
  56. text: '男'
  57. },
  58. {
  59. text: '女'
  60. },
  61. {
  62. text: '保密'
  63. }
  64. ],
  65. calendarShow: false,
  66. introduce: '',
  67. }
  68. },
  69. onLoad(options) {
  70. this.getUserInfo(options.userId);
  71. },
  72. methods: {
  73. getUserInfo(userId) {
  74. this.$u.api.user.detail({id: userId}).then(res => {
  75. this.userData = res;
  76. this.introduce = res.introduce;
  77. if (res.gender == 1) {
  78. this.sex = '男';
  79. } else if (res.gender == 2) {
  80. this.sex = "女";
  81. } else {
  82. this.sex = "未知";
  83. }
  84. })
  85. },
  86. // 点击actionSheet回调
  87. actionSheetCallback(index) {
  88. this.sex = this.actionSheetList[index].text;
  89. },
  90. change(e) {
  91. this.userData.birthday = e.result;
  92. },
  93. async upload() {
  94. let res = await this.$mpi.uploadFile()
  95. this.userData.avatar = JSON.parse(res).data;
  96. },
  97. save() {
  98. if (this.$u.test.isEmpty(this.userData.introduce) || this.$u.test.isEmpty(this.userData.nickName) || this.$u.test.isEmpty(this.userData.phone)) {
  99. uni.showToast({
  100. icon: "none",
  101. title: "请填写必填信息",
  102. })
  103. return;
  104. } else if (!this.$u.test.mobile(this.userData.phone)) {
  105. uni.showToast({
  106. icon: "none",
  107. title: "请填写正确的手机号",
  108. })
  109. return;
  110. } else {
  111. let data = {
  112. id: this.userData.id,
  113. nickName: this.userData.nickName,
  114. gender: this.sex == '男' ? 1 : this.sex == '女' ? 2 : 0,
  115. phone: this.userData.phone,
  116. birthday: this.userData.birthday,
  117. introduce: this.introduce,
  118. avatar: this.userData.avatar
  119. }
  120. this.$u.api.user.submit(data).then(res => {
  121. uni.showToast({
  122. icon: "none",
  123. title: "修改成功",
  124. duration: 2000,
  125. success() {
  126. uni.navigateBack({
  127. delta: 1
  128. })
  129. }
  130. })
  131. })
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. page {
  139. background-color: #ffffff;
  140. }
  141. </style>
  142. <style lang="scss" scoped>
  143. .title {
  144. font-size: 30upx;
  145. font-weight: bold;
  146. color: #060606;
  147. padding-left: 10upx;
  148. }
  149. .custom-style {
  150. background-color: #5a3ee7;
  151. color: #ffffff;
  152. width: 600rpx;
  153. }
  154. </style>