set.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. if (res.code === 200) {
  109. uni.showToast({
  110. title: '修改成功',
  111. icon: 'success',
  112. mask: true
  113. })
  114. }
  115. setTimeout(() => {
  116. this.name = res.content
  117. }, 1500)
  118. }
  119. }
  120. }
  121. })
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .container {
  128. display: flex;
  129. flex-direction: column;
  130. min-height: 100vh;
  131. background-color: #ebeced;
  132. .body {
  133. box-sizing: border-box;
  134. margin-top: 20rpx;
  135. padding: 0 30rpx;
  136. height: calc(100vh - 20rpx);
  137. background-color: #fff;
  138. .body_box {
  139. display: flex;
  140. justify-content: space-between;
  141. align-items: center;
  142. height: 100rpx;
  143. font-size: 28rpx;
  144. border-bottom: 1rpx solid #e6e6e6;
  145. .box_right {
  146. display: flex;
  147. justify-content: flex-end;
  148. align-items: center;
  149. height: 100rpx;
  150. .img {
  151. width: 64rpx;
  152. height: 64rpx;
  153. border-radius: 50%;
  154. }
  155. .img2 {
  156. margin-left: 7rpx;
  157. width: 47rpx;
  158. height: 47rpx;
  159. }
  160. .msg {
  161. color: #808080;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>