editUser.vue 6.6 KB

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