personalData.vue 6.4 KB

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