set.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="container">
  3. <view class="body">
  4. <!-- 个人头像区域 -->
  5. <view class="body_box">
  6. 个人头像
  7. <view class="box_right" @click="handleClickPhoto">
  8. <img mode="aspectFill" class="img" :src="imgUrl || '../../static/my/portrait.png'" />
  9. <img class="img2" src="../../static/my/right.png" />
  10. </view>
  11. </view>
  12. <!-- 账号名区域 -->
  13. <view class="body_box" @click="handleClickName">
  14. 账号名
  15. <view class="box_right">
  16. <view class="msg">{{ name }}</view>
  17. <img class="img2" src="../../static/my/right.png" />
  18. </view>
  19. </view>
  20. <!-- ID区域 -->
  21. <view class="body_box">
  22. ID
  23. <view class="box_right">
  24. <view class="msg">1925689</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. // 头像
  35. imgUrl: '',
  36. // 账号名
  37. name: ''
  38. }
  39. },
  40. onLoad() {
  41. this.getUserInfo()
  42. },
  43. methods: {
  44. getUserInfo() {
  45. let userInfo = uni.getStorageSync('userInfo')
  46. this.name = userInfo.user_name
  47. this.imgUrl = userInfo.headPhoto
  48. },
  49. // 点击头像图片回调
  50. handleClickPhoto() {
  51. uni.showActionSheet({
  52. itemList: ['更换头像'],
  53. success: (res) => {
  54. if (res.tapIndex === 0) {
  55. this.changeImg()
  56. }
  57. }
  58. })
  59. },
  60. // 更换头像回调
  61. changeImg() {
  62. uni.chooseImage({
  63. count: 1,
  64. sizeType: ['compressed'],
  65. sourceType: ['album'], //从相册选择
  66. success: (res) => {
  67. // console.log(res.tempFilePaths)
  68. this.imgUrl = res.tempFilePaths[0]
  69. }
  70. })
  71. },
  72. // 点击账号名回调
  73. handleClickName() {
  74. uni.showActionSheet({
  75. itemList: ['修改账号名'],
  76. success: (res) => {
  77. if (res.tapIndex === 0) {
  78. this.changeName()
  79. }
  80. }
  81. })
  82. },
  83. // 修改账号名回调
  84. changeName() {
  85. uni.showModal({
  86. title: '请输入账号名',
  87. editable: true,
  88. success: async (res) => {
  89. if (res.confirm) {
  90. if (!res.content) {
  91. uni.showToast({
  92. title: '账号名不能为空',
  93. icon: 'none'
  94. })
  95. setTimeout(() => {
  96. this.changeName()
  97. }, 1500)
  98. } else {
  99. const result = await this.$myRequest({
  100. url: '/mhotel/ampupdateUserInfo.action',
  101. data: {
  102. userId: uni.getStorageSync('userInfo').id,
  103. userName: res.content,
  104. headPhoto: ''
  105. }
  106. })
  107. console.log(result)
  108. }
  109. }
  110. }
  111. })
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .container {
  118. display: flex;
  119. flex-direction: column;
  120. min-height: 100vh;
  121. background-color: #ebeced;
  122. .body {
  123. box-sizing: border-box;
  124. margin-top: 20rpx;
  125. padding: 0 30rpx;
  126. height: calc(100vh - 20rpx);
  127. background-color: #fff;
  128. .body_box {
  129. display: flex;
  130. justify-content: space-between;
  131. align-items: center;
  132. height: 100rpx;
  133. font-size: 28rpx;
  134. border-bottom: 1rpx solid #e6e6e6;
  135. .box_right {
  136. display: flex;
  137. justify-content: flex-end;
  138. align-items: center;
  139. height: 100rpx;
  140. .img {
  141. width: 64rpx;
  142. height: 64rpx;
  143. border-radius: 50%;
  144. }
  145. .img2 {
  146. margin-left: 7rpx;
  147. width: 47rpx;
  148. height: 47rpx;
  149. }
  150. .msg {
  151. color: #808080;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. </style>