my.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="user" hover-class="navigator-hover" @click="popupShow = true">
  3. <view class="profile-photo">
  4. <up-image :show-loading="true" :src="user.profilePhoto" width="120rpx" height="120rpx" />
  5. </view>
  6. <view class="user-info">
  7. <view class="user-name">{{ user.name }}</view>
  8. <view class="user-phone">{{ user.phonenumber }}</view>
  9. </view>
  10. <view class="iconfont icon-shezhi" />
  11. </view>
  12. <up-popup :show="popupShow" mode="right" :customStyle="{
  13. width: '80vw',
  14. padding: '0 20rpx',
  15. background: '#F7F7FF'
  16. }" zIndex="99" @close="close" @open="open">
  17. <view class="change-user">
  18. <view class="title">
  19. 账号信息
  20. </view>
  21. <view class="row" v-show="headportraitLoading">
  22. <view class="label">
  23. 点击更换头像
  24. </view>
  25. <view class="profilePhoto">
  26. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  27. <view class="loading">
  28. <up-loading-icon mode="semicircle" />
  29. </view>
  30. </view>
  31. </view>
  32. <view v-show="!headportraitLoading" hover-class="navigator-hover">
  33. <My_upload ref="upload" custom maxCount="1" @uploadCallback="uploadCallback"
  34. @startUploading="startUploading">
  35. <view class="row" style="width: calc(80vw);">
  36. <view class="label">
  37. 点击更换头像
  38. </view>
  39. <view class="profilePhoto">
  40. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  41. </view>
  42. </view>
  43. </My_upload>
  44. </view>
  45. </view>
  46. </up-popup>
  47. </template>
  48. <script setup>
  49. import { ref, reactive, getCurrentInstance } from 'vue'
  50. const { $Http } = getCurrentInstance().proxy;
  51. import { onLoad } from '@dcloudio/uni-app';
  52. let user = reactive({
  53. name: '',
  54. phonenumber: '',
  55. profilePhoto: "",
  56. attinfos: []
  57. });
  58. onLoad(() => {
  59. getProperty()
  60. getUserMsg()
  61. const userInfo = uni.getStorageSync('userMsg')
  62. user.name = userInfo.name;
  63. user.phonenumber = userInfo.phonenumber;
  64. user.attinfos = userInfo.attinfos;
  65. user.profilePhoto = userInfo.profilePhoto || '/static/image/user.png';
  66. });
  67. let popupShow = ref(true),
  68. headportraitLoading = ref(false);
  69. function close() {
  70. popupShow.value = false
  71. }
  72. // 更换头像
  73. let upload = ref(null);
  74. function startUploading(e) {
  75. headportraitLoading.value = true;
  76. }
  77. function uploadCallback({ attachmentids, fileList }) {
  78. if (fileList.pop().usetype == 'headportrait') return;
  79. $Http.basic({
  80. "classname": "system.attachment.Attachment",
  81. "method": "createFileLink",
  82. content: {
  83. ownertable: "sys_users",
  84. ownerid: uni.getStorageSync('userMsg').userid,
  85. usetype: 'headportrait',
  86. attachmentids,
  87. siteid: uni.getStorageSync("userMsg").siteid
  88. }
  89. }).then(res => {
  90. console.log('跟进记录绑定附件', res)
  91. if (res.code != '1') return uni.showToast({
  92. title: res.msg,
  93. icon: "none"
  94. })
  95. upload.value.deleteFile(user.attinfos.filter(v => v.usetype == 'headportrait')).then(res1 => {
  96. if (res1) {
  97. getUserMsg();
  98. setTimeout(() => {
  99. uni.showToast({
  100. title: '头像更换成功',
  101. icon: 'none'
  102. });
  103. }, 100);
  104. }
  105. })
  106. })
  107. }
  108. function getUserMsg() {
  109. $Http.basic({
  110. "classname": "common.usercenter.usercenter",
  111. "method": "queryUserMsg",
  112. "content": { "nocache": true }
  113. }).then(res => {
  114. console.log("res", res);
  115. if (res.code == 1) {
  116. user.name = res.data.name;
  117. user.phonenumber = res.data.phonenumber;
  118. user.attinfos = res.data.attinfos;
  119. headportraitLoading.value = false;
  120. const headportrait = res.data.attinfos.find(v => v.usetype == 'headportrait');
  121. user.profilePhoto = headportrait ? $Http.getSpecifiedImage(headportrait) : user.profilePhoto;
  122. const userMsg = uni.getStorageSync('userMsg')
  123. uni.setStorageSync('userMsg', Object.assign(userMsg, user))
  124. }
  125. })
  126. }
  127. function getProperty() {
  128. $Http.basic({
  129. id: 2025082115363003,
  130. content: {
  131. sa_customersid: 1
  132. }
  133. }).then(res => {
  134. console.log('个人资产', res);
  135. })
  136. }
  137. </script>
  138. <style lang="less" scoped>
  139. .user {
  140. display: flex;
  141. align-items: center;
  142. width: 100%;
  143. background-color: #fff;
  144. box-sizing: border-box;
  145. padding: 40rpx;
  146. .profile-photo {
  147. width: 120rpx;
  148. height: 120rpx;
  149. border-radius: 50%;
  150. overflow: hidden;
  151. }
  152. .user-info {
  153. flex: 1;
  154. margin-left: 40rpx;
  155. padding-top: 10rpx;
  156. .user-name {
  157. line-height: 42rpx;
  158. font-family: Microsoft YaHei, Microsoft YaHei;
  159. font-size: 32rpx;
  160. color: #333333;
  161. }
  162. .user-phone {
  163. line-height: 38rpx;
  164. font-family: Microsoft YaHei, Microsoft YaHei;
  165. font-size: 28rpx;
  166. color: #999999;
  167. margin-top: 20rpx;
  168. }
  169. }
  170. }
  171. .change-user {
  172. padding-top: 55px;
  173. box-sizing: border-box;
  174. .title {
  175. font-size: 28rpx;
  176. color: #333;
  177. margin-bottom: 30rpx;
  178. padding-left: 20rpx;
  179. }
  180. .row {
  181. width: 100%;
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. background: #fff;
  186. padding: 20rpx 30rpx;
  187. border-radius: 16rpx;
  188. box-sizing: border-box;
  189. .label {
  190. font-size: 28rpx;
  191. color: #666;
  192. }
  193. .profilePhoto {
  194. position: relative;
  195. width: 80rpx;
  196. height: 80rpx;
  197. border-radius: 50%;
  198. overflow: hidden;
  199. .loading {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. width: 100%;
  204. height: 100%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. background: rgba(0, 0, 0, 0.09);
  209. z-index: 1;
  210. }
  211. }
  212. }
  213. }
  214. </style>