set.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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">{{id}}</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. //用户id
  39. id:'',
  40. }
  41. },
  42. onLoad() {
  43. this.getUserInfo()
  44. },
  45. methods: {
  46. getUserInfo() {
  47. let userInfo = uni.getStorageSync('userInfo')
  48. this.name = userInfo.user_name
  49. this.imgUrl = userInfo.headPhoto
  50. this.id=userInfo.id
  51. },
  52. // 点击头像图片回调
  53. handleClickPhoto() {
  54. uni.showActionSheet({
  55. itemList: ['更换头像'],
  56. success: (res) => {
  57. if (res.tapIndex === 0) {
  58. this.changeImg()
  59. }
  60. }
  61. })
  62. },
  63. // 更换头像回调
  64. changeImg() {
  65. uni.chooseImage({
  66. count: 1,
  67. sizeType: ['compressed'],
  68. sourceType: ['album'], //从相册选择
  69. success: async (res) => {
  70. // this.imgUrl = res.tempFilePaths[0]
  71. const result = await this.$myRequest({
  72. url: '/mhotel/ampupdateUserInfo.action',
  73. data: {
  74. userId: this.id,
  75. userName: this.name,
  76. headPhoto: res.tempFilePaths[0]
  77. }
  78. })
  79. if (result.code === 200) {
  80. uni.showToast({
  81. title: '头像修改成功',
  82. icon: 'success',
  83. mask: true
  84. })
  85. setTimeout(() => {
  86. this.getUser()
  87. }, 1500)
  88. }
  89. }
  90. })
  91. },
  92. // 点击账号名回调
  93. handleClickName() {
  94. uni.showActionSheet({
  95. itemList: ['修改账号名'],
  96. success: (res) => {
  97. if (res.tapIndex === 0) {
  98. this.changeName()
  99. }
  100. }
  101. })
  102. },
  103. // 修改账号名回调
  104. changeName() {
  105. uni.showModal({
  106. title: '请输入账号名',
  107. editable: true,
  108. success: async (res) => {
  109. if (res.confirm) {
  110. if (!res.content) {
  111. uni.showToast({
  112. title: '账号名不能为空',
  113. icon: 'none'
  114. })
  115. setTimeout(() => {
  116. this.changeName()
  117. }, 1500)
  118. } else {
  119. const result = await this.$myRequest({
  120. url: '/mhotel/ampupdateUserInfo.action',
  121. data: {
  122. userId: this.id,
  123. userName: res.content,
  124. headPhoto: this.imgUrl
  125. }
  126. })
  127. if (result.code === 200) {
  128. uni.showToast({
  129. title: '账号修改成功',
  130. icon: 'success',
  131. mask: true
  132. })
  133. setTimeout(() => {
  134. this.getUser()
  135. }, 1500)
  136. }
  137. }
  138. }
  139. }
  140. })
  141. },
  142. //获取个人信息
  143. async getUser(){
  144. const res = await this.$myRequest({
  145. url: '/mhotel/ampqueryUsersById.action',
  146. data: {
  147. userId:uni.getStorageSync('userId')
  148. }
  149. })
  150. if (res.code === 200) {
  151. this.name = res.data.user_name
  152. this.imgUrl = res.data.headPhoto
  153. }
  154. },
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .container {
  160. display: flex;
  161. flex-direction: column;
  162. min-height: 100vh;
  163. background-color: #ebeced;
  164. .body {
  165. box-sizing: border-box;
  166. margin-top: 20rpx;
  167. padding: 0 30rpx;
  168. height: calc(100vh - 20rpx);
  169. background-color: #fff;
  170. .body_box {
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. height: 100rpx;
  175. font-size: 28rpx;
  176. border-bottom: 1rpx solid #e6e6e6;
  177. .box_right {
  178. display: flex;
  179. justify-content: flex-end;
  180. align-items: center;
  181. height: 100rpx;
  182. .img {
  183. width: 64rpx;
  184. height: 64rpx;
  185. border-radius: 50%;
  186. }
  187. .img2 {
  188. margin-left: 7rpx;
  189. width: 47rpx;
  190. height: 47rpx;
  191. }
  192. .msg {
  193. color: #808080;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. </style>