editUser.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="info-item">
  5. <view class="label">头像</view>
  6. <view class="right">
  7. <image class="head" @tap="chooseImage()" :src="headImg" mode=""></image>
  8. </view>
  9. </view>
  10. <view class="info-item">
  11. <view class="label">姓名</view>
  12. <view class="right">
  13. <input type="text" v-model="nickName" placeholder="请输入姓名" class="input" />
  14. </view>
  15. </view>
  16. <view class="info-item">
  17. <view class="label">性别</view>
  18. <view class="right x-end" style="width:80%;height: 40px;justify-content: end;">
  19. <picker style="width: 100%;text-align: right;" @change="pickerSex" :value="sex" :range="sexPicker">
  20. <view class="picker">
  21. {{sex>-1?sexPicker[sex]:''}}
  22. </view>
  23. </picker>
  24. </view>
  25. </view>
  26. <view class="info-item">
  27. <view class="label">手机号</view>
  28. <view class="right">
  29. <input type="text" v-model="phonenumber" placeholder="请输入手机号" class="input" />
  30. </view>
  31. </view>
  32. </view>
  33. <view class="btn-box">
  34. <view class="sub-btn" @click="submit()">保存修改</view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {setPwd,setHeadImg,setUserInfo,getUserInfo} from '@/api/user.js';
  40. import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
  41. export default {
  42. data() {
  43. return {
  44. nickName:"",
  45. deptName:"",
  46. postNames:"",
  47. phonenumber:"",
  48. email:"",
  49. sexPicker: ['男', '女','未知'],
  50. sex: 0, // 性别
  51. headImg: '/static/images/detault_head.jpg', // 头像,
  52. headImgUrl:'',
  53. }
  54. },
  55. onLoad() {
  56. this.getUserInfo();
  57. },
  58. methods: {
  59. bindUser(data){
  60. var that=this;
  61. that.nickName=data.user.nickName;
  62. that.posts=data.post;
  63. that.phonenumber=data.user.phone;
  64. that.email=data.user.email;
  65. if(data.user.sex!=undefined){
  66. that.sex=data.user.sex;
  67. }
  68. if(data.post!=null&&data.post.length>0){
  69. var postNameStr="";
  70. data.post.forEach( (v,i) => {
  71. postNameStr+=v+",";
  72. },this);
  73. that.postNames=postNameStr.substr(0,postNameStr.length-1);
  74. }
  75. if(!that.$isEmpty(data.user.avatar)){
  76. //this.headImg=uni.getStorageSync('requestPath')+data.user.avatar;
  77. this.headImg=data.user.avatar;
  78. this.headImgUrl=data.user.avatar;
  79. }
  80. },
  81. getUserInfo(){
  82. var data = {};
  83. var that=this;
  84. getUserInfo(data).then(
  85. res => {
  86. that.bindUser(res);
  87. },
  88. rej => {}
  89. );
  90. },
  91. // 性别选择
  92. pickerSex(e) {
  93. this.sex = e.detail.value
  94. },
  95. // 选择照片
  96. async chooseImage() {
  97. // #ifdef APP-PLUS
  98. if(!plus.runtime.isAgreePrivacy()) {
  99. uni.showToast({title: "请同意隐私政策",icon: "none"});
  100. return;
  101. }
  102. let result = await premissionCheck("EXTERNAL_STORAGE");
  103. if(result == 1) {
  104. uni.chooseImage({
  105. count: 1, //默认9
  106. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  107. sourceType: ['album', 'camera'], //从相册选择
  108. success: (res) => {
  109. //this.headImg = res.tempFilePaths[0]
  110. uni.uploadFile({
  111. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  112. filePath: res.tempFilePaths[0],
  113. name: 'file',
  114. formData: {
  115. 'user': 'test' // 上传附带参数
  116. },
  117. success: (uploadFileRes) => {
  118. console.log(uploadFileRes)
  119. // 根据接口具体返回格式 赋值具体对应url
  120. var data=JSON.parse(uploadFileRes.data)
  121. //this.headImg=uni.getStorageSync('requestPath')+data.fileName;
  122. this.headImg=data.url;
  123. this.headImgUrl=data.url;
  124. }
  125. });
  126. }
  127. });
  128. }
  129. // #endif
  130. },
  131. // 预览头像
  132. viewImage() {
  133. uni.previewImage({
  134. urls: this.headImg,
  135. current: this.headImg
  136. });
  137. },
  138. submit(){
  139. if (this.$isEmpty(this.phonenumber)) {
  140. uni.showToast({
  141. title: "请输入手机号",
  142. icon: 'none',
  143. });
  144. return
  145. }
  146. var data = {phone:this.phonenumber,email:this.email,sex:this.sex.toString(),avatar:this.headImgUrl,nickName:this.nickName};
  147. console.log(data);
  148. setUserInfo(data).then(res => {
  149. if(res.code==200){
  150. uni.showToast({
  151. title: '修改成功',
  152. duration: 2000
  153. });
  154. }
  155. else{
  156. uni.showToast({
  157. title: res.msg,
  158. icon: 'none',
  159. });
  160. }
  161. },
  162. rej => {}
  163. );
  164. }
  165. }
  166. }
  167. </script>
  168. <style scoped lang="scss">
  169. .content{
  170. padding-top: 20rpx;
  171. border-top: 1px solid #F5F6FA;
  172. }
  173. .info-item{
  174. height: 104upx;
  175. background: #FFFFFF;
  176. padding: 0 30upx;
  177. display: flex;
  178. align-items: center;
  179. justify-content: space-between;
  180. border-bottom: 1px solid #F5F6FA;
  181. &:last-child{
  182. border-bottom: none;
  183. }
  184. .label{
  185. font-size: 30upx;
  186. font-family: PingFang SC;
  187. font-weight: 400;
  188. color: #0F1826;
  189. }
  190. .right{
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. .text{
  195. font-size: 30upx;
  196. font-family: PingFang SC;
  197. font-weight: 400;
  198. color: #0F1826;
  199. }
  200. .image{
  201. margin-left: 10upx;
  202. width: 30upx;
  203. height: 30upx;
  204. }
  205. .input{
  206. text-align: right;
  207. font-size: 30upx;
  208. font-family: PingFang SC;
  209. font-weight: 400;
  210. color: #0F1826;
  211. }
  212. }
  213. .head{
  214. border-radius: 50%;
  215. width: 80upx;
  216. height: 80upx;
  217. }
  218. .arrow{
  219. width: 30upx;
  220. height: 30upx;
  221. }
  222. .text{
  223. font-size: 30upx;
  224. font-family: PingFang SC;
  225. font-weight: 400;
  226. color: #0F1826;
  227. }
  228. .input{
  229. text-align: right;
  230. font-size: 30upx;
  231. font-family: PingFang SC;
  232. font-weight: 400;
  233. color: #0F1826;
  234. }
  235. &.password{
  236. margin-top: 20upx;
  237. .right{
  238. display: flex;
  239. align-items: center;
  240. .text{
  241. font-size: 30upx;
  242. font-family: PingFang SC;
  243. font-weight: 400;
  244. color: #0F1826;
  245. margin-right: 15upx;
  246. }
  247. }
  248. }
  249. }
  250. .btn-box{
  251. margin-top: 15rpx;
  252. height: 120upx;
  253. padding: 0 30upx;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. .sub-btn{
  258. width: 100%;
  259. height: 88upx;
  260. line-height: 88upx;
  261. text-align: center;
  262. font-size: 30upx;
  263. font-family: PingFang SC;
  264. font-weight: bold;
  265. color: #FFFFFF;
  266. background: #FF5C03;
  267. border-radius: 44upx;
  268. }
  269. }
  270. </style>