index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. sessionKey:''
  37. };
  38. },
  39. components: {},
  40. props: {
  41. updateInfo: {
  42. type: Boolean,
  43. default: false
  44. },
  45. updateMobile: {
  46. type: Boolean,
  47. default: false
  48. },
  49. },
  50. watch: {},
  51. mounted() {
  52. // console.log('ready');
  53. // console.log('isUpdateInfo==',this.updateInfo)
  54. // console.log('isUpdateMobile==',this.updateMobile)
  55. app.globalData.getCheckSessoin(json => {
  56. this.sessionKey = json.session_key;
  57. });
  58. },
  59. methods: {
  60. uploadAvatar(e) {
  61. uni.showLoading({
  62. title: '头像上传中'
  63. });
  64. req.uploadFile('/api/nocheck/upload', e.detail.avatarUrl, res => {
  65. this.avatar = res.src;
  66. uni.hideLoading();
  67. });
  68. },
  69. getNickname: function(e) {
  70. this.nickName = e.detail.value;
  71. },
  72. updateInfos() {
  73. if (!this.avatar) return req.msg('请上传头像');
  74. console.log('this.nickName>>>>', this.nickName);
  75. if (!this.nickName) return req.msg('请输入昵称');
  76. this.confirm();
  77. },
  78. confirm() {
  79. let that = this;
  80. let d = {
  81. avatar: that.avatar,
  82. nickName: that.nickName
  83. };
  84. // let isShowLoading = false;
  85. // if (!isShowLoading) {
  86. // req.loadIng('中');
  87. // isShowLoading = true;
  88. // }
  89. req.postRequest(
  90. '/api/user/save',
  91. d,
  92. res => {
  93. // if (isShowLoading) {
  94. // uni.hideLoading();
  95. let userInfo = req.getStorage('userInfo');
  96. userInfo.avatar = this.avatar;
  97. userInfo.nickName = this.nickName;
  98. req.setStorage('userInfo', userInfo);
  99. this.$emit('updateInfo', false);
  100. this.closeUpdate();
  101. // isShowLoading = false;
  102. // }
  103. },
  104. true
  105. );
  106. },
  107. getPhoneNumber(e) {
  108. let that = this;
  109. let sessionKey = this.sessionKey;
  110. let _params = {
  111. sessionKey: sessionKey,
  112. iv: e.detail.iv,
  113. encryptedData: e.detail.encryptedData
  114. };
  115. if (req.getStorage('pidCode')) {
  116. _params.parentId = req.getStorage('pidCode');
  117. }
  118. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  119. req.postRequest('/api/weixin/mobile', _params, json => {
  120. if (json.mobile) {
  121. var userInfo = req.getStorage('userInfo');
  122. userInfo.mobile = json.mobile;
  123. req.setStorage('userInfo', userInfo);
  124. this.$emit('updateMobile', true);
  125. this.closeUpdate();
  126. }
  127. });
  128. } else {}
  129. },
  130. closeUpdate(){
  131. this.$emit('closeUpdate');
  132. },
  133. }
  134. };
  135. </script>
  136. <style>
  137. @import "./index.css";
  138. </style>