editUser.vue 7.3 KB

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