info.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view :style="vuex_skin">
  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="80"></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 :disabled="!isEdit" v-model="userData.nickName" :placeholder-style="placeholderStyle" :clearable="false"
  13. inputAlign="right" placeholder="请输入昵称">
  14. </u-input>
  15. <text class="cuIcon-right margin-left-10" style="color: #CCCCCC;"></text>
  16. </view>
  17. </view>
  18. <u-line color="#f1f1f1"></u-line>
  19. <view class="flex padding justify-between align-center">
  20. <view class="title">性别</view>
  21. <view class="center">
  22. <u-input disabled @click="showSex" :placeholder-style="placeholderStyle" v-model="userData.sex"
  23. :clearable="false" inputAlign="right" placeholder="性别"></u-input>
  24. <text class="cuIcon-right margin-left-10" style="color: #CCCCCC;"></text>
  25. <u-action-sheet :list="actionSheetList" v-model="sexShow" @click="actionSheetCallback">
  26. </u-action-sheet>
  27. </view>
  28. </view>
  29. <u-line color="#f1f1f1"></u-line>
  30. <view class="flex padding justify-between align-center">
  31. <view class="title">手机号<text class="text-red">*</text></view>
  32. <view class="center">
  33. <u-input disabled v-model="userData.phone" :placeholder-style="placeholderStyle" :clearable="false"
  34. inputAlign="right" placeholder="请填写手机号码"></u-input>
  35. <text class="cuIcon-right margin-left-10" style="color: #CCCCCC;"></text>
  36. </view>
  37. </view>
  38. </view>
  39. <view style="margin-top: 150rpx;" @click="confirm">
  40. <view class="bg-white center text-base" style="width: 100%;height: 90rpx;font-family: PingFang-SC-Medium;">
  41. <text v-if="isEdit">确认修改</text>
  42. <text v-else>退出登录</text>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. placeholderStyle: 'color: #c0c4cc;font-size:26rpx',
  52. isEdit: false,
  53. userData: {},
  54. sexShow: false,
  55. border: true,
  56. show: false,
  57. actionSheetList: [{
  58. text: '男'
  59. },
  60. {
  61. text: '女'
  62. },
  63. {
  64. text: '保密'
  65. }
  66. ],
  67. }
  68. },
  69. onLoad(options) {
  70. this.isEdit = options.edit || false
  71. if (this.isEdit) {
  72. uni.setNavigationBarTitle({
  73. title: "修改资料"
  74. })
  75. }
  76. this.getUserInfo();
  77. },
  78. methods: {
  79. showSex(){
  80. if (this.isEdit) {
  81. this.sexShow=true
  82. return
  83. }
  84. },
  85. getUserInfo() {
  86. this.$api.loginUser.detail({
  87. id: this.vuex_userId
  88. }).then(res => {
  89. this.userData = res.data.data;
  90. })
  91. },
  92. // 点击actionSheet回调
  93. actionSheetCallback(index) {
  94. this.userData.sex = this.actionSheetList[index].text;
  95. },
  96. async upload() {
  97. if (!this.isEdit) {
  98. return false
  99. }
  100. let resp = await this.$mpi.chooseImage()
  101. this.$api.uploadFile(resp[0]).then(res => {
  102. this.userData.avatar = res.data.data.link
  103. })
  104. },
  105. confirm() {
  106. if (this.isEdit) {
  107. this.update()
  108. return
  109. }
  110. this.logout()
  111. },
  112. logout() {
  113. this.$cache.clear()
  114. this.$u.vuex('vuex_userId',null)
  115. this.$u.vuex('vuex_phone',null)
  116. uni.reLaunch({
  117. url: "../mine"
  118. })
  119. },
  120. update() {
  121. if (this.$u.test.isEmpty(this.userData.nickName) || this.$u.test.isEmpty(this.userData.phone)) {
  122. uni.showToast({
  123. icon: "none",
  124. title: "请填写必填信息",
  125. })
  126. return;
  127. } else if (!this.$u.test.mobile(this.userData.phone)) {
  128. uni.showToast({
  129. icon: "none",
  130. title: "请填写正确的手机号",
  131. })
  132. return;
  133. }
  134. let data = {
  135. id: this.userData.id,
  136. nickName: this.userData.nickName,
  137. sex: this.userData.sex,
  138. phone: this.userData.phone,
  139. avatar: this.userData.avatar
  140. }
  141. console.log(data);
  142. this.$api.loginUser.submit(data).then(res => {
  143. this.$dialog.showModalAndBack('修改成功', this.vuex_theme.bgColor)
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .padding {
  151. padding: 30rpx 40rpx;
  152. }
  153. .title {
  154. font-size: 28rpx;
  155. font-family: PingFang-SC-Medium;
  156. color: #060606;
  157. padding-left: 10upx;
  158. }
  159. </style>