index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="page">
  3. <view class="outView">
  4. <form @submit="inputValue">
  5. <view class="flex-row justify-between bordBot">
  6. <view class="key flex-col justify-center ">
  7. <text>头像</text>
  8. </view>
  9. <button class="photoView" open-type="chooseAvatar" @chooseavatar="chooseavatar">
  10. <image class="photoImage" :src="userInfo.selfPhotoUrl || '/static/me/ud4.png'"></image>
  11. </button>
  12. </view>
  13. <view class="flex-row justify-between bordBot">
  14. <view class="key flex-col justify-center ">
  15. <text>昵称</text>
  16. </view>
  17. <view class="nikeName flex-col justify-center">
  18. <input type="nickname" name="nickname" v-model="userInfo.ncikName" placeholder="请输入昵称"/>
  19. </view>
  20. </view>
  21. <view class="flex-row justify-between bordBot">
  22. <view class="key flex-col justify-center ">
  23. <text>会员编号</text>
  24. </view>
  25. <view class="flex-row justify-end groupItemContent">
  26. <text>{{ userInfo.no }}</text>
  27. </view>
  28. </view>
  29. <view class="flex-row justify-between bordBot">
  30. <view class="key flex-col justify-center ">
  31. <text>性别</text>
  32. </view>
  33. <picker class="picker" @change="genderChange" mode='selector' range-key="gender" :value="genderIndex"
  34. :range="genderList">
  35. <view class="flex-row justify-end groupItemContent">
  36. <text v-if="userInfo.sex == 0">男</text>
  37. <text v-else-if="userInfo.sex == 1">女</text>
  38. <text v-else-if="userInfo.sex == 2">未知</text>
  39. <text v-else>请选择性别</text>
  40. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  41. </view>
  42. </picker>
  43. </view>
  44. <view class="flex-row justify-between bordBot">
  45. <view class="key flex-col justify-center ">
  46. <text>生日</text>
  47. </view>
  48. <picker class="picker" :end="endDate" @change="birthdayChange" mode='date' range-key="label">
  49. <view class="flex-row justify-end groupItemContent">
  50. <text>{{ userInfo.birthday || '请选择出生日期' }}</text>
  51. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  52. </view>
  53. </picker>
  54. </view>
  55. <view class="flex-row justify-between bordBot">
  56. <view class="key flex-col justify-center ">
  57. <text>手机号</text>
  58. </view>
  59. <view class="flex-row justify-end groupItemContent" @click="settingTelphone">
  60. <text>{{ userInfo.phone ? userInfo.phone : '绑定手机号' }}</text>
  61. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  62. </view>
  63. </view>
  64. <!-- <view class="flex-row justify-between bordBot" >-->
  65. <!-- <view class="key flex-col justify-center ">-->
  66. <!-- <text>实名认证</text>-->
  67. <!-- </view>-->
  68. <!-- <view class="flex-row justify-end groupItemContent" @click="gotoRealNameAuth">-->
  69. <!-- <text>{{userInfo.isAttestation? '已认证' : '未实名认证,去认证' }}</text>-->
  70. <!-- <u-icon name="arrow-right" color="#666" size="18"></u-icon>-->
  71. <!-- </view>-->
  72. <!-- </view>-->
  73. <button class="updateButton" formType="submit">
  74. <text>保存</text>
  75. </button>
  76. </form>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. export default {
  82. data() {
  83. return {
  84. photoUrl: '',
  85. userInfo: {},
  86. genderIndex: 0,
  87. genderList: [{gender: '男', id: '0'},
  88. {gender: '女', id: '1'},
  89. {gender: '未知', id: '2'}],
  90. };
  91. },
  92. mounted() {
  93. },
  94. onLoad() {
  95. // 用户信息
  96. this.userInfo = uni.getStorageSync('userInfo')
  97. if (this.userInfo.selfPhoto) {
  98. this.getImgUrlByOssId(this.userInfo.selfPhoto)
  99. }
  100. },
  101. onShow() {
  102. this.userInfo.phone = uni.getStorageSync('userInfo').phone
  103. },
  104. computed: {
  105. endDate() {
  106. return this.getDate('end');
  107. }
  108. },
  109. methods: {
  110. getDate(type) {
  111. const date = new Date();
  112. let year = date.getFullYear();
  113. let month = date.getMonth() + 1;
  114. let day = date.getDate();
  115. if (type === 'start') {
  116. year = year - 60;
  117. } else if (type === 'end') {
  118. year = year;
  119. }
  120. month = month > 9 ? month : '0' + month;
  121. day = day > 9 ? day : '0' + day;
  122. return `${year}-${month}-${day}`;
  123. },
  124. settingTelphone() {
  125. uni.navigateTo({
  126. url: '/myPages/setting/setting-telphone'
  127. })
  128. },
  129. inputValue(e) {
  130. console.log('+++++++++++++inputValue+++++++++++', e)
  131. this.userInfo.ncikName = e.detail.value.nickname
  132. this.saveUserInfo()
  133. },
  134. // 选择性别
  135. genderChange(e) {
  136. console.log(e.detail.value)
  137. this.userInfo.sex = e.detail.value
  138. },
  139. //选择的日期
  140. birthdayChange(e) {
  141. console.log(e.detail.value)
  142. this.userInfo.birthday = e.detail.value
  143. },
  144. // 去实名认证
  145. gotoRealNameAuth() {
  146. uni.navigateTo({
  147. url: '/myPages/realNameAuth/index',
  148. })
  149. },
  150. // 保存用户信息
  151. saveUserInfo() {
  152. // 保存数据
  153. this.$api.saveUserInfo(this.userInfo).then((res) => {
  154. console.log(res)
  155. // 刷新用户信息
  156. this.getUserInfo();
  157. uni.showToast({
  158. title: "操作成功"
  159. })
  160. // setTimeout(res=>{
  161. // uni.switchTab({
  162. // url: '/pages/index/index',
  163. // },2000)
  164. // })
  165. }).catch(() => {
  166. uni.showToast({
  167. title: "操作失败"
  168. })
  169. });
  170. },
  171. getUserInfo() {
  172. this.$api.getUserInfo().then(res => {
  173. console.log('++++++++++++获取用户信息++++++++++++++++++', res)
  174. uni.setStorageSync('userInfo', res.data.data)
  175. this.userInfo = res.data.data
  176. if (this.userInfo.selfPhoto) {
  177. this.getImgUrlByOssId(this.userInfo.selfPhoto)
  178. }
  179. })
  180. },
  181. getImgUrlByOssId(Id) {
  182. this.$api.getImage(Id).then(res => {
  183. this.userInfo.selfPhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  184. this.$set(this.userInfo)
  185. });
  186. },
  187. //头像上传
  188. chooseavatar(e) {
  189. let that = this
  190. let avatarUrl = e.detail.avatarUrl
  191. console.log(e.detail.avatarUrl)
  192. uni.uploadFile({
  193. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  194. filePath: avatarUrl,
  195. name: 'file',
  196. header: {
  197. // "Content-Type": "multipart/form-data",
  198. // 'X-Access-Token': uni.getStorageSync('token'),
  199. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  200. },
  201. success: (uploadFileRes) => {
  202. let res = JSON.parse(uploadFileRes.data)
  203. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++', uploadFileRes.data)
  204. that.userInfo.selfPhoto = res.data.ossId
  205. that.userInfo.selfPhotoUrl = res.data.url.replace(/^http:/, "https:")
  206. }
  207. });
  208. },
  209. }
  210. };
  211. </script>
  212. <style lang="scss">
  213. @import '/common/css/common.css';
  214. @import './index.rpx.css';
  215. .logoutButton {
  216. width: 70%;
  217. margin: 0 auto;
  218. margin-top: 60rpx;
  219. height: 80rpx;
  220. line-height: 80rpx;
  221. background: #FFE05C;
  222. border-radius: 40rpx;
  223. text-align: center;
  224. font-size: 32rpx;
  225. color: #333;
  226. font-weight: 500;
  227. }
  228. </style>