myInfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view>
  3. <view class="bg-white margin-top-20">
  4. <view class="flex padding justify-between align-center" @click="upload">
  5. <view class="title">头像</view>
  6. <u-avatar :src="userData.avatar" size="100"></u-avatar>
  7. </view>
  8. <u-line color="#f1f1f1"></u-line>
  9. <view class="flex padding justify-between align-center">
  10. <view class="title">昵称<text class="text-red">*</text></view>
  11. <view class="center">
  12. <u-input v-model="userData.nickName" :clearable="false" inputAlign="right" placeholder="请输入昵称"></u-input>
  13. <text class="cuIcon-right margin-left-10"></text>
  14. </view>
  15. </view>
  16. <u-line color="#f1f1f1"></u-line>
  17. <view class="flex padding justify-between align-center">
  18. <view class="title">性别</view>
  19. <view class="center" >
  20. <u-input disabled @click="sexShow = true" v-model="sex" :clearable="false" inputAlign="right" placeholder="性别"></u-input>
  21. <text class="cuIcon-right margin-left-10"></text>
  22. <u-action-sheet :list="actionSheetList" v-model="sexShow" @click="actionSheetCallback"></u-action-sheet>
  23. </view>
  24. </view>
  25. <u-line color="#f1f1f1"></u-line>
  26. <view class="flex padding justify-between align-center">
  27. <view class="title">手机号码<text class="text-red">*</text></view>
  28. <view class="center">
  29. <u-input v-model="userData.phone" :clearable="false" inputAlign="right" placeholder="请填写手机号码"></u-input>
  30. <text class="cuIcon-right margin-left-10"></text>
  31. </view>
  32. </view>
  33. <u-line color="#f1f1f1"></u-line>
  34. <view class="flex padding justify-between align-center" @click="calendarShow = true">
  35. <view class="title">生日</view>
  36. <view class="center">
  37. <u-input @click="calendarShow=true" disabled v-model="userData.birth" :clearable="false" inputAlign="right" placeholder="请填写生日"></u-input>
  38. <text class="cuIcon-right margin-left-10"></text>
  39. <u-calendar v-model="calendarShow" mode="date" active-bg-color="#FF9447" @change="change"></u-calendar>
  40. </view>
  41. </view>
  42. <view style="height: 20upx;"></view>
  43. <view class="footer-fixed margin-bottom" style="z-index: 99;">
  44. <u-button :custom-style="customStyle" shape="circle" @click="save">保存</u-button>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. customStyle: {
  54. backgroundColor: '#FF9447',
  55. color: '#ffffff',
  56. margin:"20rpx",
  57. height:"90rpx"
  58. },
  59. userData: {},
  60. sex: '',
  61. sexShow: false,
  62. border: true,
  63. show: false,
  64. actionSheetList: [
  65. {
  66. text: '男'
  67. },
  68. {
  69. text: '女'
  70. },
  71. {
  72. text: '保密'
  73. }
  74. ],
  75. calendarShow: false,
  76. }
  77. },
  78. onLoad() {
  79. this.getUserInfo();
  80. },
  81. methods: {
  82. getUserInfo() {
  83. this.$api.loginUser.detail({id: this.vuex_userId}).then(res => {
  84. this.userData = res.data;
  85. if (this.userData.sex == 1) {
  86. this.sex = '男';
  87. } else if (this.userData.sex == 2) {
  88. this.sex = "女";
  89. } else {
  90. this.sex = "未知";
  91. }
  92. })
  93. },
  94. // 点击actionSheet回调
  95. actionSheetCallback(index) {
  96. this.sex = this.actionSheetList[index].text;
  97. },
  98. change(e) {
  99. this.userData.birth = e.result;
  100. },
  101. async upload() {
  102. let resp = await this.$mpi.chooseImage()
  103. this.$api.uploadFile(resp[0]).then(res=>{
  104. this.userData.avatar = res.data.link
  105. })
  106. },
  107. save() {
  108. if (this.$u.test.isEmpty(this.userData.nickName) || this.$u.test.isEmpty(this.userData.phone)) {
  109. uni.showToast({
  110. icon: "none",
  111. title: "请填写必填信息",
  112. })
  113. return;
  114. } else if (!this.$u.test.mobile(this.userData.phone)) {
  115. uni.showToast({
  116. icon: "none",
  117. title: "请填写正确的手机号",
  118. })
  119. return;
  120. } else {
  121. let data = {
  122. id: this.userData.id,
  123. nickName: this.userData.nickName,
  124. sex: this.sex == '男' ? 1 : this.sex == '女' ? 2 : 0,
  125. phone: this.userData.phone,
  126. birth: this.userData.birth,
  127. avatar: this.userData.avatar
  128. }
  129. this.$api.loginUser.submit(data).then(res => {
  130. this.$dialog.showModal('修改成功',false).then(()=>{
  131. uni.navigateBack({
  132. delta: 1
  133. })
  134. })
  135. })
  136. }
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .title {
  143. font-size: 30upx;
  144. font-weight: bold;
  145. color: #060606;
  146. padding-left: 10upx;
  147. }
  148. </style>