profile.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="container">
  3. <u-navbar :is-fixed="false" :border-bottom="false" :is-back="true" back-icon-name="arrow-leftward" title="个人资料"
  4. back-icon-size="35" :background="{ background: '#fff' }" title-color="#000">
  5. <view class="complie" slot="right" @click="submit">完成</view>
  6. </u-navbar>
  7. <view class="content">
  8. <view class="avatar">
  9. <image :src="userInfo.avatar" class="avatar-image" mode=""></image>
  10. <view class="a" @click="handleChooseImg">更换头像</view>
  11. </view>
  12. <view class="form">
  13. <view class="cell">
  14. <view class="name">昵称</view>
  15. <input type="text" placeholder="请输入昵称" v-model="userInfo.nick_name" class="ipt"
  16. placeholder-class="hold" />
  17. </view>
  18. <view class="cell">
  19. <view class="name">生日</view>
  20. <picker mode="date" class="ipt" :class="{ hold: !detail.birthday }"
  21. @change="changeDefaultPicker('birthday', $event)">
  22. <view>{{ detail.birthday || '请选择生日' }}</view>
  23. </picker>
  24. </view>
  25. <view class="cell">
  26. <view class="name">性别</view>
  27. <picker mode="selector" :range="sexPicker" range-key="name" class="ipt"
  28. :class="{ hold: !detail.sex }" @change="changePicker('sex', $event)">
  29. <view>{{ detail.sex === 1?'男':'女' || '请选择性别' }}</view>
  30. </picker>
  31. </view>
  32. <view class="cell">
  33. <view class="name">手机号</view>
  34. <input type="number" placeholder="请填写手机号" v-model="detail.phone" class="ipt"
  35. placeholder-class="hold" />
  36. </view>
  37. <view class="cell">
  38. <view class="name">邮箱</view>
  39. <input v-model="detail.email" class="ipt" placeholder-class="hold" />
  40. </view>
  41. <!--<view class="cell">
  42. <view class="name">国家/地区</view>
  43. <pickRegions :defaultRegion="detail.region" v-model="detail.region"
  44. :class="{ hold: !detail.region, ipt: true }">
  45. <view>{{ detail.region || '请选择国家/地区' }}</view>
  46. </pickRegions>
  47. </view>-->
  48. </view>
  49. </view>
  50. <!-- -->
  51. <view class="back" @click="logout">退出登录</view>
  52. </view>
  53. </template>
  54. <script>
  55. import pickRegions from '@/components/pick-regions/pick-regions.vue';
  56. export default {
  57. components: {
  58. pickRegions
  59. },
  60. data() {
  61. return {
  62. sexPicker: [{
  63. name: '男'
  64. },
  65. {
  66. name: '女'
  67. }
  68. ],
  69. detail: {}
  70. };
  71. },
  72. onLoad() {
  73. this.$u.api.userInfo().then(data => {
  74. console.log(data);
  75. if (data.success) {
  76. this.detail = data.data;
  77. }
  78. }).catch(err => {
  79. console.log(err)
  80. this.$u.func.showToast({
  81. title: err,
  82. })
  83. })
  84. },
  85. methods: {
  86. logout() {
  87. this.$u.func.logout();
  88. },
  89. submit() {
  90. let detail = this.detail
  91. if (!detail.phone && !/^1\d{10}$/.test(detail.phone)) {
  92. return uni.showToast({
  93. title: '请输入正确的手机号',
  94. duration: 2000,
  95. icon: 'none'
  96. });
  97. }
  98. console.log(JSON.stringify(detail));
  99. },
  100. changeDefaultPicker(name, e) {
  101. this.detail[name] = e.detail.value;
  102. },
  103. changePicker(name, e) {
  104. this.detail[name] = this[`${name}Picker`][e.detail.value].name;
  105. },
  106. handleChooseImg() {
  107. let that = this;
  108. uni.chooseImage({
  109. count: 1,
  110. success(e) {
  111. that.detail.avatar = e.tempFilePaths[0];
  112. }
  113. });
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss">
  119. .container {
  120. background-color: #f7f7f7;
  121. min-height: 100vh;
  122. padding: 0 0 200rpx;
  123. overflow: hidden;
  124. }
  125. .complie {
  126. vertical-align: middle;
  127. padding: 10rpx 20rpx;
  128. font-size: 32rpx;
  129. font-family: Source Han Sans CN;
  130. font-weight: 400;
  131. color: #5f88ff;
  132. }
  133. .content {
  134. background-color: #ffffff;
  135. overflow: hidden;
  136. }
  137. .avatar {
  138. margin-top: 30rpx;
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. flex-direction: column;
  143. font-size: 30rpx;
  144. font-family: Source Han Sans CN;
  145. font-weight: 400;
  146. color: #5f88ff;
  147. .avatar-image {
  148. width: 162rpx;
  149. height: 162rpx;
  150. background: #ffffff;
  151. border-radius: 50%;
  152. background-color: #82848a;
  153. margin-bottom: 15rpx;
  154. }
  155. }
  156. .form {
  157. padding: 0 36rpx;
  158. .cell {
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. padding: 40rpx 0;
  163. font-size: 30rpx;
  164. font-family: Source Han Sans CN;
  165. font-weight: bold;
  166. color: #666666;
  167. &:not(:last-of-type) {
  168. border-bottom: 2rpx solid #efefef;
  169. }
  170. .ipt {
  171. flex: 1;
  172. margin-left: 40rpx;
  173. text-align: right;
  174. font-size: 23rpx;
  175. font-family: Source Han Sans CN;
  176. font-weight: bold;
  177. color: #333333;
  178. }
  179. .hold {
  180. font-size: 27rpx;
  181. font-family: Source Han Sans CN;
  182. font-weight: bold;
  183. color: #c8c8ce;
  184. }
  185. }
  186. }
  187. .back {
  188. margin-top: 40rpx;
  189. text-align: center;
  190. height: 109rpx;
  191. background: #ffffff;
  192. font-size: 34rpx;
  193. font-family: Source Han Sans CN;
  194. font-weight: bold;
  195. color: #141414;
  196. line-height: 109rpx;
  197. }
  198. </style>