personal.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="content">
  3. <view class="cell-group">
  4. <view class="hflex acenter jbetween cell" @click="chooseImg">
  5. <view class="left">头像</view>
  6. <view class="hflex acenter">
  7. <image :src="user.headimg" mode="aspectFill" class="avatar"></image>
  8. <u-icon name="arrow-right" color="#000" size="10"></u-icon>
  9. </view>
  10. </view>
  11. <view class="hflex acenter jbetween cell" @click="setName">
  12. <view class="left">昵称</view>
  13. <view class="hflex acenter">
  14. <view class="right">{{user.nickname}}</view>
  15. <u-icon name="arrow-right" color="#000" size="10"></u-icon>
  16. </view>
  17. </view>
  18. <view class="hflex acenter jbetween cell" @click="setSex">
  19. <view class="left">性别</view>
  20. <view class="hflex acenter">
  21. <view class="right">{{user.base_sex?user.base_sex:''}}</view>
  22. <u-icon name="arrow-right" color="#000" size="10"></u-icon>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="cell-group">
  27. <view class="hflex acenter jbetween cell" @click="toReal">
  28. <view class="left">实名认证</view>
  29. <view class="hflex acenter">
  30. <view class="red" v-if="user.is_auth == 0"></view>
  31. <view class="right">{{user.is_auth?'已实名认证':'未实名认证'}}</view>
  32. <u-icon name="arrow-right" color="#000" size="10"></u-icon>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import $api from '@/static/js/api.js'
  40. var that = ''
  41. export default {
  42. data() {
  43. return {
  44. user: {}
  45. }
  46. },
  47. onLoad() {
  48. that = this
  49. },
  50. onShow() {
  51. that.getUser()
  52. },
  53. methods: {
  54. // 获取个人信息
  55. getUser() {
  56. $api.req({
  57. url: '/data/api.auth.Center/get',
  58. method: 'POST'
  59. }, function(res) {
  60. if(res.code == 1) {
  61. that.user = res.data
  62. }
  63. })
  64. },
  65. // 选择头像
  66. chooseImg() {
  67. uni.chooseImage({
  68. count: 1, //默认9
  69. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  70. sourceType: ['album','camera'], //从相册选择
  71. success: function (res) {
  72. // console.log(JSON.stringify(res.tempFilePaths));
  73. const tempFilePaths = res.tempFilePaths
  74. uni.uploadFile({
  75. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  76. filePath: tempFilePaths[0],
  77. name: 'file',
  78. header: {
  79. 'content-type': 'application/x-www-form-urlencoded',
  80. 'api-token': uni.getStorageSync('token').token?uni.getStorageSync('token').token:'',
  81. 'api-name': 'wxapp'
  82. },
  83. formData: {
  84. 'user': 'test'
  85. },
  86. success: (res) => {
  87. const data = JSON.parse(res.data)
  88. if (data.code == 1) {
  89. that.user.headimg = data.data.url
  90. $api.req({
  91. url: '/data/api.auth.Center/set',
  92. method: 'POST',
  93. data:{
  94. headimg: that.user.headimg,
  95. }
  96. },function(res) {
  97. console.log(res);
  98. let options = {
  99. avatarurl: that.user.headimg,
  100. }
  101. uni.WebIM.conn.updateOwnUserInfo(options).then((res) => {
  102. console.log(res)
  103. })
  104. $api.info(res.info)
  105. })
  106. }
  107. }
  108. });
  109. }
  110. });
  111. },
  112. // 修改
  113. setName() {
  114. $api.jump('/page_shop/pages/setting/bindeMail?type=username')
  115. },
  116. setSex() {
  117. $api.jump('/page_shop/pages/setting/bindeMail?type=sex')
  118. },
  119. // 去实名认证
  120. toReal() {
  121. if(that.user.is_auth == 1) {
  122. $api.jump('/page_shop/pages/setting/realname')
  123. } else {
  124. url = '/page_shop/pages/setting/webview?url=' + encodeURIComponent('https://ship.shipcc.cn/h5/#/?token=' + uni.getStorageSync('token').token)
  125. }
  126. }
  127. },
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .content {
  132. background-color: #f5f5f5;
  133. .cell-group {
  134. width: 100%;
  135. background-color: #fff;
  136. margin-top: 20rpx;
  137. padding: 0 30rpx;
  138. box-sizing: border-box;
  139. .cell {
  140. box-sizing: border-box;
  141. padding: 36rpx 0;
  142. border-bottom: 1rpx solid #f5f5f5;
  143. .left {
  144. font-size: 30rpx;
  145. color: #222;
  146. }
  147. .right {
  148. padding: 0 5rpx;
  149. font-size: 30rpx;
  150. color: #444;
  151. }
  152. .red {
  153. width: 12rpx;
  154. height: 12rpx;
  155. border-radius: 50%;
  156. background-color: #fb3e32;
  157. }
  158. .avatar {
  159. width: 88rpx;
  160. height: 88rpx;
  161. border-radius: 50%;
  162. }
  163. }
  164. .button {
  165. font-size: 36rpx;
  166. color: #506dff;
  167. padding: 20rpx 0;
  168. }
  169. }
  170. }
  171. </style>