index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <view class="ceng"></view>
  4. <view class="update-pop">
  5. <block v-if="updateInfo">
  6. <!-- <image :src="picUrlss+'update_info.png'" class="update-img"></image> -->
  7. <view class="update-tip">完善头像/昵称信息</view>
  8. <button open-type="chooseAvatar" hover-class="none" class="update-avatar" @chooseavatar="uploadAvatar">
  9. <image :src="avatar" class="update-avatars" v-if="avatar"></image>
  10. <image :src="picUrlss + 'upload_avatar.png'" v-else></image>
  11. </button>
  12. <view class="update-form ddflex">
  13. <view class="update-label">昵称</view>
  14. <input type="nickname" v-model="nickName" placeholder="请输入昵称" placeholder-class="update-placeholder" class="update-ipt fflex" @blur="getNickname" />
  15. </view>
  16. <view class="update-btn" @click="updateInfos()">确定</view>
  17. </block>
  18. <block v-if="updateMobile&&!updateInfo">
  19. <image :src="picUrlss+'update_phone.png'" class="update-img"></image>
  20. <view class="update-tip">授权手机号</view>
  21. <button class="update-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即绑定</button>
  22. </block>
  23. <image :src="picUrlss+'update_close.png'" class="update-close" @click="closeUpdate"></image>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. const req = require("../../utils/request.js");
  30. export default {
  31. data() {
  32. return {
  33. picUrlss: req.public.picUrls,
  34. avatar: '',
  35. nickName: ''
  36. };
  37. },
  38. components: {},
  39. props: {
  40. updateInfo: {
  41. type: Boolean,
  42. default: false
  43. },
  44. updateMobile: {
  45. type: Boolean,
  46. default: false
  47. },
  48. },
  49. watch: {},
  50. mounted() {
  51. // console.log('ready');
  52. // console.log('isUpdateInfo==',this.updateInfo)
  53. // console.log('isUpdateMobile==',this.updateMobile)
  54. },
  55. methods: {
  56. uploadAvatar(e) {
  57. uni.showLoading({
  58. title: '头像上传中'
  59. });
  60. req.uploadFile('/api/nocheck/upload', e.detail.avatarUrl, res => {
  61. this.avatar = res.src;
  62. uni.hideLoading();
  63. });
  64. },
  65. getNickname: function(e) {
  66. this.nickName = e.detail.value;
  67. },
  68. updateInfos() {
  69. if (!this.avatar) return req.msg('请上传头像');
  70. console.log('this.nickName>>>>', this.nickName);
  71. if (!this.nickName) return req.msg('请输入昵称');
  72. this.confirm();
  73. },
  74. confirm() {
  75. let that = this;
  76. let d = {
  77. avatar: that.avatar,
  78. nickName: that.nickName
  79. };
  80. // let isShowLoading = false;
  81. // if (!isShowLoading) {
  82. // req.loadIng('中');
  83. // isShowLoading = true;
  84. // }
  85. req.postRequest(
  86. '/api/user/save',
  87. d,
  88. res => {
  89. // if (isShowLoading) {
  90. // uni.hideLoading();
  91. let userInfo = req.getStorage('userInfo');
  92. userInfo.avatar = this.avatar;
  93. userInfo.nickName = this.nickName;
  94. req.setStorage('userInfo', userInfo);
  95. this.$emit('updateInfo', false);
  96. this.closeUpdate();
  97. // isShowLoading = false;
  98. // }
  99. },
  100. true
  101. );
  102. },
  103. getPhoneNumber(e) {
  104. let that = this;
  105. let sessionKey = '';
  106. app.globalData.getCheckSessoin(json => {
  107. sessionKey = json.session_key;
  108. let _params = {
  109. sessionKey: sessionKey,
  110. iv: e.detail.iv,
  111. encryptedData: e.detail.encryptedData
  112. };
  113. if (req.getStorage('pidCode')) {
  114. _params.parentId = req.getStorage('pidCode');
  115. }
  116. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  117. req.postRequest('/api/weixin/mobile', _params, json => {
  118. if (json.mobile) {
  119. var userInfo = req.getStorage('userInfo');
  120. userInfo.mobile = json.mobile;
  121. req.setStorage('userInfo', userInfo);
  122. this.$emit('updateMobile', true);
  123. this.closeUpdate();
  124. }
  125. });
  126. } else {}
  127. });
  128. },
  129. closeUpdate(){
  130. this.$emit('closeUpdate');
  131. },
  132. }
  133. };
  134. </script>
  135. <style>
  136. @import "./index.css";
  137. </style>