userinfo.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="userinfo">
  3. <!--头像 + 背景-->
  4. <view class="user-section" :class="'bg-' + themeColor.name">
  5. <image class="bg" :src="userBg"></image>
  6. <!--#ifdef H5-->
  7. <!--h5直接上传头像 @tap="uploadImage"-->
  8. <view class="portrait-box">
  9. <image class="portrait" :src="headImg"></image>
  10. </view>
  11. <!-- #endif -->
  12. <!--#ifndef H5-->
  13. <!--非h5裁剪头像上传-->
  14. <view class="portrait-box">
  15. <avatar canRotate="false" selWidth="200px" selHeight="400upx" @upload="handleUploadFile" :avatarSrc="headImg"
  16. avatarStyle="width: 200upx; height: 200upx; border-radius: 100%; border: 6upx solid #fff;">
  17. </avatar>
  18. </view>
  19. <!-- #endif -->
  20. </view>
  21. <view class="input-content">
  22. <view class="input-item">
  23. <text class="tit">手机号</text>
  24. <input type="number" v-model="user.phonenumber" placeholder="请输入手机号码" />
  25. </view>
  26. <view class="input-item">
  27. <text class="tit">姓 名</text>
  28. <input type="text" v-model="user.nickName" placeholder="请输入您的姓名" />
  29. </view>
  30. <view class="input-item">
  31. <text class="tit">性 别</text>
  32. <radio-group @change="handleGenderChange">
  33. <label class="gender-item" v-for="(item, index) in genders" :key="index">
  34. <radio class="gender-item-radio" :color="themeColor.color" :value="item.value" :checked="item.value === user.sex" />
  35. <text class="gender-item-text">{{ item.name }}</text>
  36. </label>
  37. </radio-group>
  38. </view>
  39. <view class="input-item">
  40. <text class="tit">邮 箱</text>
  41. <input v-model="user.email" placeholder="请输入您的邮箱" />
  42. </view>
  43. <view class="input-item" disabled>
  44. <text class="tit">部 门</text>
  45. <text type="text">{{user.dept.deptName}}</text>
  46. </view>
  47. <button class="confirm-btn" :class="'bg-' + themeColor.name" :disabled="btnLoading" :loading="btnLoading" @tap="toUpdateInfo">
  48. 修改资料
  49. </button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import avatar from '@/components/oa-avatar/oa-avatar';
  55. import moment from '@/common/moment';
  56. import rfPickRegions from '@/components/oa-pick-regions';
  57. export default {
  58. components: {
  59. avatar,
  60. rfPickRegions
  61. },
  62. data() {
  63. return {
  64. user:{},
  65. genders: [
  66. {
  67. value: '0',
  68. name: '男'
  69. },
  70. {
  71. value: '1',
  72. name: '女'
  73. }
  74. ],
  75. date: moment().format('YYYY-MM-DD'),
  76. token: null,
  77. loading: true,
  78. headImg: this.$mAssetsPath.headImg,
  79. userBg: this.$mAssetsPath.userBg,
  80. btnLoading: false
  81. };
  82. },
  83. onShow() {
  84. uni.setNavigationBarColor({
  85. frontColor: '#ffffff',
  86. backgroundColor: this.themeColor.color,
  87. animation: {
  88. duration: 400,
  89. timingFunc: 'easeIn'
  90. }
  91. })
  92. },
  93. onLoad() {
  94. //this.user = this.$store.state.user;
  95. this.user = uni.getStorageSync('user');
  96. this.headImg = this.$mConfig.baseUrl + this.user.avatar;
  97. if(this.headImg){
  98. this.headImg = "../../../static/portrait.png";
  99. }
  100. // this.initData();
  101. },
  102. methods: {
  103. // 获取选择的地区
  104. handleGetRegions(e) {
  105. this.addressData.province_id = e.province_id;
  106. this.addressData.city_id = e.city_id;
  107. this.addressData.area_id = e.area_id;
  108. },
  109. // 上传头像
  110. uploadImage() {
  111. // 从相册选择图片
  112. const _this = this;
  113. uni.chooseImage({
  114. count: 1,
  115. sizeType: ['original', 'compressed'],
  116. sourceType: ['album'],
  117. success: function(res) {
  118. _this.handleUploadFile(res.tempFilePaths);
  119. }
  120. });
  121. },
  122. // 上传头像
  123. handleUploadFile(data) {
  124. this.$mHelper.toast('头像上传中...');
  125. },
  126. // 监听日期更改
  127. bindDateChange(e) {
  128. this.date = e.target.value;
  129. },
  130. // 监听性别更改
  131. handleGenderChange(e) {
  132. this.profileInfo.gender = e.detail.value;
  133. },
  134. // 更新用户信息
  135. async toUpdateInfo() {
  136. var url = this.$mConfig.baseUrl + '/system/user/profile';
  137. var token = this.$preToken + ' ' + this.$store.state.accessToken;
  138. this.$http.request({
  139. url: url,
  140. method: "PUT",
  141. header: {
  142. 'content-type': 'application/json',
  143. 'Authorization': token
  144. },
  145. data: this.user
  146. }).then(r => {
  147. if(r.code=="200"){
  148. this.$mHelper.toast('恭喜您, 资料修改成功!');
  149. }else{
  150. this.$mHelper.toast('资料修改失败,请重试!');
  151. return false;
  152. }
  153. });
  154. },
  155. }
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. page {
  160. background-color: $color-white;
  161. }
  162. .userinfo {
  163. .user-section {
  164. display: flex;
  165. align-items: center;
  166. justify-content: center;
  167. height: 320upx;
  168. padding: 40upx 30upx 0;
  169. overflow: hidden;
  170. position: relative;
  171. .bg {
  172. position: absolute;
  173. left: 0;
  174. top: 0;
  175. width: 100vw;
  176. opacity: 0.84;
  177. }
  178. .portrait-box {
  179. clear: both;
  180. z-index: 2;
  181. }
  182. .portrait {
  183. position: relative;
  184. width: 200upx;
  185. height: 200upx;
  186. border-radius: 50%;
  187. border: 6upx solid #fff;
  188. }
  189. .yticon {
  190. position: absolute;
  191. line-height: 1;
  192. z-index: 5;
  193. font-size: 48upx;
  194. color: #fff;
  195. padding: 4upx 6upx;
  196. border-radius: 6upx;
  197. background: rgba(0, 0, 0, 0.4);
  198. }
  199. .pt-upload-btn {
  200. right: 0;
  201. bottom: 10upx;
  202. }
  203. .bg-upload-btn {
  204. right: 20upx;
  205. bottom: 16upx;
  206. }
  207. }
  208. .input-content {
  209. padding: 40upx 60upx;
  210. .input-item {
  211. display: flex;
  212. padding: 0 30upx;
  213. background: $page-color-light;
  214. height: 80upx;
  215. line-height: 80upx;
  216. border-radius: 4px;
  217. margin-bottom: 30upx;
  218. &:last-child {
  219. margin-bottom: 0;
  220. }
  221. .tit {
  222. width: 100upx;
  223. font-size: $font-sm + 2upx;
  224. color: $font-color-base;
  225. }
  226. input {
  227. width: calc(100% - 100upx);
  228. height: 80upx;
  229. line-height: 80upx;
  230. font-size: $font-base + 2upx;
  231. color: $font-color-dark;
  232. }
  233. .date {
  234. height: 80upx;
  235. line-height: 80upx;
  236. font-size: $font-base + 2upx;
  237. color: $font-color-dark;
  238. }
  239. .gender-item {
  240. margin-right: 20upx;
  241. .gender-item-text {
  242. padding-left: 10upx;
  243. }
  244. radio .wx-radio-input.wx-radio-input-checked {
  245. background: $uni-color-primary;
  246. border-color: $uni-color-primary;
  247. }
  248. }
  249. }
  250. }
  251. }
  252. </style>