personalData.vue 5.9 KB

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