personalData.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="wrap">
  3. <view class="info-wrap">
  4. <view class="avatar-container" @click="editAvart">
  5. <template>
  6. <image v-if="form.accountAvatar" class="avatar" :src="form.accountAvatar" mode="widthFix" @error="ImageError"></image>
  7. <image v-else class="avatar" :src="defaultAvatar" mode="widthFix"></image>
  8. </template>
  9. <view class="edit">编辑</view>
  10. </view>
  11. <uni-list>
  12. <uni-list-item title="帐号名称" :rightText="form.accountName" clickable @click="handle('accountName')" showArrow></uni-list-item>
  13. <uni-list-item title="手机号码" :rightText="form.accountPhone" clickable @click="handle('accountPhone')" showArrow></uni-list-item>
  14. <uni-list-item title="个人姓名" :rightText="form.accountRealName" clickable @click="handle('accountRealName')" showArrow></uni-list-item>
  15. <uni-list-item title="工 号" :rightText="form.accountStaffNo" clickable @click="handle('accountStaffNo')" showArrow></uni-list-item>
  16. <uni-list-item title="介 绍" :rightText="form.accountIntro" clickable @click="handle('accountIntro')" showArrow></uni-list-item>
  17. </uni-list>
  18. <div class="submit-BT" @click="submit">保存</div>
  19. </view>
  20. <uni-popup ref="popup" type="dialog" style="top">
  21. <div class="uni-popup-modal">
  22. <view class="uni-popup-title">请输入修改内容</view>
  23. <div class="uni-popup-content">
  24. <uni-easyinput type="text" v-model="updateValue" trim
  25. @confirm="confirm(updateValue)"
  26. placeholder="请输入内容"></uni-easyinput>
  27. </div>
  28. <div class="handle-wrap">
  29. <div class="cancel bt" @click="close">取消</div>
  30. <div class="confirm bt" @click="confirm(updateValue)">确认</div>
  31. </div>
  32. </div>
  33. </uni-popup>
  34. </view>
  35. </template>
  36. <script>
  37. import { getUserProfile, updateUserProfile } from '@/api/system.js'
  38. import { upload } from '@/api/upload.js'
  39. export default {
  40. data() {
  41. return {
  42. defaultAvatar:require("@/static/images/avatar.png"),
  43. avatar:"",
  44. updateValue:"",
  45. form:{
  46. accountId: undefined,
  47. accountName: '',
  48. accountRealName: '',
  49. accountAvatar: '',
  50. accountPhone: '',
  51. accountStaffNo: '',
  52. accountIntro: ''
  53. }
  54. }
  55. },
  56. onShow() {
  57. this.init();
  58. },
  59. methods: {
  60. init(){
  61. this.getUserProfile();
  62. },
  63. getUserProfile(){
  64. getUserProfile().then((res)=>{
  65. this.form=res.data
  66. })
  67. },
  68. handle(type){
  69. if(type==='avatar'){
  70. this.updateAvatar();
  71. }else{
  72. this.updateValue=this.form[type];
  73. this.type=type;
  74. this.open();
  75. }
  76. },
  77. open() {
  78. this.$refs.popup.open();
  79. },
  80. close() {
  81. this.$refs.popup.close()
  82. },
  83. ImageError(){
  84. this.avatar=this.defaultAvatar
  85. },
  86. editAvart(){
  87. const self=this;
  88. uni.chooseImage({
  89. count: 1,
  90. sizeType: ['original', 'compressed'],
  91. sourceType: ['album',"camera"], //从相册选择
  92. success:(res)=>{
  93. let filePath=res.tempFilePaths[0]
  94. upload({filePath}).then((resq)=>{
  95. var fileResq=JSON.parse(resq)
  96. self.form.accountAvatar=fileResq.data.fileUrl;
  97. })
  98. }
  99. });
  100. },
  101. confirm(value) {
  102. if(isEmpty(value)){
  103. uni.showToast({
  104. icon:"none",
  105. title:'请填写修改内容'
  106. })
  107. return;
  108. }
  109. this.form[this.type]=value
  110. this.updateValue=""
  111. this.close();
  112. },
  113. submit(){
  114. updateUserProfile(this.form).then(()=>{
  115. uni.showToast({
  116. title:"修改成功!",
  117. icon:"none",
  118. duration:1000
  119. })
  120. setTimeout(()=>{
  121. uni.hideToast()
  122. uni.reLaunch({
  123. url:'/pages/myCenter/myCenter'
  124. })
  125. },1000)
  126. })
  127. },
  128. isEmpty(val){
  129. if(val!=="undefined"&&val!==undefined&&val!==""&&val!==null){
  130. return false
  131. }
  132. return true
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .wrap{
  139. .info-wrap{
  140. background-color: #f8f8f8;
  141. padding-top: 36rpx;
  142. .avatar-container{
  143. &{
  144. margin: 0 auto;
  145. width: 156rpx;
  146. height: 156rpx;
  147. background: rgba(255,255,255,0.39);
  148. border: 2rpx solid #707070;
  149. border-radius: 50%;
  150. position: relative;
  151. overflow: hidden;
  152. margin-bottom: 36rpx;
  153. }
  154. .avatar{
  155. width: 156rpx;
  156. height: 156rpx;
  157. border-radius: 50%;
  158. display: block;
  159. }
  160. .edit{
  161. width: 100%;
  162. height: 42rpx;
  163. line-height: 42rpx;
  164. text-align: center;
  165. position: absolute;
  166. bottom: 0;
  167. left: 50%;
  168. transform: translateX(-50%);
  169. font-size: 26rpx;
  170. font-family: PingFang SC;
  171. font-weight: 400;
  172. color: #FFFFFF;
  173. background: rgba(0,0,0,0.6);
  174. }
  175. }
  176. .uni-list-item-custom{
  177. display: flex;
  178. justify-content: space-between;
  179. align-items: center;
  180. padding: 12rpx 15px;
  181. padding-left: 15px;
  182. border-bottom: 1px solid #e7e7e7;
  183. .headline{
  184. font-size: 14px;
  185. color: #3b4144;
  186. overflow: hidden;
  187. }
  188. }
  189. }
  190. .uni-popup-dialog-wrap{
  191. margin-top: -180upx;
  192. }
  193. .submit-BT{
  194. width: 424rpx;
  195. height: 72rpx;
  196. line-height: 72rpx;
  197. text-align: center;
  198. position: fixed;
  199. bottom: 120rpx;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. background:#3D90F4;
  203. border-radius: 42rpx;
  204. font-size: 32rpx;
  205. font-family: PingFang SC;
  206. font-weight: 400;
  207. color: #FFFFFF;
  208. z-index: 999;
  209. }
  210. .uni-popup-modal{
  211. width: 500rpx;
  212. background-color: #fff;
  213. box-shadow: 0 0 6rpx rgba(0,0,0,0.6);
  214. border-radius: 16rpx;
  215. .uni-popup-title{
  216. color: #000;
  217. font-size: 32rpx;
  218. line-height: 1;
  219. text-align: center;
  220. padding: 30rpx 0;
  221. }
  222. .uni-popup-content{
  223. padding: 20rpx 20rpx 80rpx;
  224. }
  225. .handle-wrap{
  226. .bt{
  227. display: inline-block;
  228. width: 50%;
  229. height: 80rpx;
  230. line-height: 60rpx;
  231. color: #333;
  232. font-size: 32rpx;
  233. text-align: center;
  234. &.confirm{
  235. color:#007aff;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. </style>