index.vue 6.4 KB

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