userinfo.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="index container">
  3. <nav-header>个人信息</nav-header>
  4. <view class="content">
  5. <view class="row" v-for="(item,index) in list" :key="index" @click="clickitem(item.e)">
  6. <view class="">
  7. {{item.name}}
  8. </view>
  9. <view class="" v-if="item.showimg">
  10. <image :src="item.img || '../../../static/login/logo.png'" mode=""
  11. style="width: 88rpx;height: 88rpx;border-radius: 50%;"></image>
  12. </view>
  13. <view class="" v-else>
  14. {{item.right}}
  15. </view>
  16. <view class="" v-if="item.icon">
  17. <image :src="item.icon" v-if="item.e=='5'" @click="copy(item.right)" mode="widthFix" style="width: 48rpx;"></image>
  18. <image :src="item.icon" v-else mode="widthFix" style="width: 48rpx;"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 修改名称弹出框 -->
  23. <view class="pop_ocy" v-if="show_set_name">
  24. <view class="pop_content">
  25. <u--input placeholder="请输入要修改的昵称" border="surround" v-model="value" :color="'#000'" :maxlength="'12'">
  26. </u--input>
  27. <view class="btn">
  28. <view class="systemBcg" @click="setname">
  29. 修改
  30. </view>
  31. <view class="systemBcg" @click="show_set_name=false">
  32. 取消
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 修改名称弹出框 结束-->
  38. </view>
  39. </template>
  40. <script>
  41. import navHeader from "@/components/my/nav_header.vue"
  42. export default {
  43. components: {
  44. navHeader
  45. },
  46. onShow() {
  47. this.get_user_info()
  48. },
  49. data() {
  50. return {
  51. userinfo: {},
  52. list: [{
  53. name: "头像",
  54. showimg: true,
  55. right: "",
  56. img: "",
  57. e: "1",
  58. icon:'../../../static/my/arrow_right.png'
  59. },
  60. {
  61. name: "昵称",
  62. showimg: false,
  63. right: "",
  64. img: "",
  65. e: "2",
  66. icon:'../../../static/my/arrow_right.png'
  67. },
  68. {
  69. name: "手机号",
  70. showimg: false,
  71. right: "",
  72. img: "",
  73. // e: "4",
  74. // icon:'../../../static/my/arrow_right.png'
  75. },
  76. {
  77. name: "钱包地址",
  78. showimg: false,
  79. right: "",
  80. img: "",
  81. e: "5",
  82. icon:'/static/my/copy2.png',
  83. }
  84. ],
  85. value: "",
  86. show_set_name: false
  87. }
  88. },
  89. methods: {
  90. //当前行数点击事件
  91. clickitem(e) {
  92. if (e == 1) {
  93. this.choosePhoto()
  94. } else if (e == 2) {
  95. this.show_set_name = true
  96. }else if(e == 4){
  97. this.$api.to("/pages/my/userinfo/bindphone/bindphone")
  98. }
  99. },
  100. //获取用户信息
  101. get_user_info() {
  102. this.api.get_user_info()
  103. this.user_info = uni.getStorageSync("user_info")
  104. this.list[0].img = this.user_info.headimg
  105. this.list[1].right = this.user_info.nickname
  106. this.list[2].right = this.user_info.phone
  107. this.list[3].right = this.plusXing(this.user_info.hash,6,6)
  108. // console.log(this.list)
  109. },
  110. plusXing(str, frontLen, endLen) {
  111. if (!str) return
  112. var len = str.length - frontLen - endLen;
  113. var xing = '';
  114. // len
  115. for (var i = 0; i < 6; i++) {
  116. xing += '*';
  117. }
  118. return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
  119. },
  120. copy(val) {
  121. this.$api.setclip(val)
  122. },
  123. //选择图片当头像
  124. choosePhoto() {
  125. var that = this
  126. uni.chooseImage({
  127. count: 1, //最多可以选择的图片张数,默认9
  128. sourceType: ['album'], //album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
  129. sizeType: ['original'], //original 原图,compressed 压缩图,默认二者都有
  130. success(res) {
  131. // 调用上传图片的接口
  132. // this.uploadPhoto(res.tempFilePaths);
  133. // that.list[0].img=res.tempFilePaths[0]
  134. //上传图片
  135. that.$api.upload(res.tempFilePaths[0]).then(res => {
  136. // console.log(res)
  137. //请求设置个人信息借口
  138. that.api.set_user_info("", res).then(res1 => {
  139. if (res1.code == 1) {
  140. uni.showToast({
  141. title: "更换头像成功",
  142. duration:2000
  143. })
  144. // that.get_user_info()
  145. setTimeout(()=> {
  146. that.$api.totabar('/pages/my/my')
  147. },1000)
  148. }
  149. })
  150. })
  151. },
  152. fail() {
  153. console.log('失败', err);
  154. },
  155. complete() {
  156. console.log('结束');
  157. },
  158. })
  159. },
  160. setname() {
  161. //修改个人名称
  162. this.api.set_user_info(this.value, "").then(res1 => {
  163. if (res1.code == 1) {
  164. uni.showToast({
  165. title: "修改名称成功"
  166. })
  167. this.get_user_info()
  168. //关闭弹出层
  169. this.show_set_name = false
  170. //渲染当前名称
  171. this.list[1].right = res1.data.nickname
  172. }
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped>
  179. .index {
  180. box-sizing: border-box;
  181. padding-top: 100rpx;
  182. }
  183. image {
  184. display: block;
  185. }
  186. .content {
  187. margin: 20rpx auto;
  188. }
  189. .row {
  190. display: flex;
  191. width: 710rpx;
  192. height: 110rpx;
  193. margin: 0 auto;
  194. }
  195. .row>view {
  196. align-self: center;
  197. box-sizing: border-box;
  198. margin: 10rpx;
  199. }
  200. .row>view:nth-child(2) {
  201. margin-left: auto;
  202. }
  203. .row>view:nth-child(3) {
  204. /* margin-left: auto; */
  205. }
  206. .btn {
  207. /* width: 710rpx; */
  208. display: flex;
  209. justify-content: space-between;
  210. }
  211. .btn>view {
  212. width: 170rpx;
  213. height: 58rpx;
  214. border-radius: 32rpx;
  215. margin-top: 50rpx;
  216. text-align: center;
  217. line-height: 58rpx;
  218. font-size: 26rpx;
  219. color: #000;
  220. }
  221. .btn>view:last-child {
  222. width: 170rpx;
  223. height: 58rpx;
  224. border-radius: 32rpx;
  225. margin-top: 50rpx;
  226. text-align: center;
  227. line-height: 58rpx;
  228. font-size: 26rpx;
  229. }
  230. .pop_content {
  231. width: 450rpx;
  232. padding: 80rpx 50rpx 40rpx;
  233. border-radius: 20rpx;
  234. background-color: #fff;
  235. }
  236. </style>