editUser.vue 6.5 KB

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