personalData.vue 5.8 KB

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