mineEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <template>
  2. <view>
  3. <statusBar :item="navBarData"></statusBar>
  4. <view class="editBox">
  5. <view class="edit_avatar">
  6. <view class="edit_title">
  7. <text>头像</text>
  8. </view>
  9. <view class="userAvatar" @click="updateava">
  10. <image :src="userData.avatar"></image>
  11. </view>
  12. </view>
  13. <view class="setName">
  14. <view class="edit_title">
  15. <text>姓名</text>
  16. </view>
  17. <view class="input_details">
  18. <view class="nickname">
  19. <input type="text" style=" text-align: right;" maxlength="10" placeholder="请输入昵称"
  20. placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);"
  21. v-model="userData.username" />
  22. </view>
  23. </view>
  24. </view>
  25. <view class="setPicker">
  26. <picker mode="selector" :range="genderList" :value="userData.sex" @change="handelGender">
  27. <view class="content">
  28. <view class="edit_title">
  29. <text>性别</text>
  30. </view>
  31. <view class="input_details">
  32. <view class="details">
  33. <view class="uni-input text">{{genderList[userData.sex]}}</view>
  34. </view>
  35. <view class="arrow">
  36. <image
  37. src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right_gray.png"
  38. mode="aspectFill"></image>
  39. </view>
  40. </view>
  41. </view>
  42. </picker>
  43. </view>
  44. <view class="setPicker">
  45. <picker mode="selector" :range="schoolList" :value="userData.school" @change="handelSchool">
  46. <view class="content">
  47. <view class="edit_title">
  48. <text>学校</text>
  49. </view>
  50. <view class="input_details">
  51. <view class="details">
  52. <view class="uni-input text">{{userData.school}}</view>
  53. </view>
  54. <view class="arrow">
  55. <image
  56. src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right_gray.png"
  57. mode="aspectFill"></image>
  58. </view>
  59. </view>
  60. </view>
  61. </picker>
  62. </view>
  63. <view class="setPicker">
  64. <picker mode="selector" :range="speList" :value="userData.spe" @change="handelspe">
  65. <view class="content">
  66. <view class="edit_title">
  67. <text>专业</text>
  68. </view>
  69. <view class="input_details">
  70. <view class="details">
  71. <view class="uni-input text">{{userData.spe}}</view>
  72. </view>
  73. <view class="arrow">
  74. <image
  75. src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right_gray.png"
  76. mode="aspectFill"></image>
  77. </view>
  78. </view>
  79. </view>
  80. </picker>
  81. </view>
  82. <view class="setPicker">
  83. <picker mode="selector" :range="rankList" :value="userData.rankl" @change="handelrank">
  84. <view class="content">
  85. <view class="edit_title">
  86. <text>职称</text>
  87. </view>
  88. <view class="input_details">
  89. <view class="details">
  90. <view class="uni-input text">{{userData.rankl}}</view>
  91. </view>
  92. <view class="arrow">
  93. <image
  94. src="https://teacherapi.cocorobo.cn/teaching-file/static//mine/arrow-right_gray.png"
  95. mode="aspectFill"></image>
  96. </view>
  97. </view>
  98. </view>
  99. </picker>
  100. </view>
  101. <view class="setIntro">
  102. <view class="edit_title">
  103. <text>简介</text>
  104. </view>
  105. <view class="input_details">
  106. <view class="selfdomIntro">
  107. <textarea type="text" placeholder="请输入你的个性签名" maxlength="75"
  108. placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);" style="color: black;"
  109. v-model="userData.brief" />
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="btnBox">
  115. <view class="btn">
  116. <button @click="saveInfo">保存修改</button>
  117. <button @click="gotoLogin">退出登录</button>
  118. </view>
  119. </view>
  120. <!-- 弹窗 -->
  121. <view>
  122. <view class="mask" v-show="showPopup" @click="closePopup"></view>
  123. <view class="popup-container" v-show="showPopup">
  124. <view class="popup">
  125. <view class="header">
  126. <text>确认修改</text>
  127. </view>
  128. <view class="footer">
  129. <view class="cancel-btn" @click="closePopup">取消</view>
  130. <view class="confirm-btn" @click="conf">确认</view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. <view>
  136. <view class="popup-container" style="height: 175px;" v-show="showPopupConfirm">
  137. <view class="popup">
  138. <view class="header" style="margin-top: 15px;">
  139. <image src="https://teacherapi.cocorobo.cn/teaching-file/static//gou1.png" mode="aspectFill">
  140. </image>
  141. <text style="margin-bottom: 24px;">修改成功</text>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. </view>
  147. </template>
  148. <script>
  149. export default {
  150. data() {
  151. // const currentDate = this.getDate({
  152. // format: true
  153. // })
  154. return {
  155. navBarData: {
  156. title: '个人资料',
  157. btn: 1
  158. },
  159. // 相别选项
  160. genderList: ['男', '女'],
  161. //学校选项
  162. schoolList: ['深圳信息XX学院', '深圳XX学院', '深圳XX学院'],
  163. //专业选项
  164. speList: ['互联网', '网络通信', '航空', '汽修', '珠宝', '文秘', '设计'],
  165. //职称选项
  166. rankList: ['xx', 'xx', 'xx'],
  167. // 兴趣选项
  168. hobbyList: ['篮球', '编程', '钢琴', '美术', '摄影'],
  169. gender: '男',
  170. school: 'xx学院',
  171. //控制弹窗
  172. showPopup: false,
  173. //修改成功弹窗
  174. showPopupConfirm: false,
  175. // isFirstShow: true,
  176. // 用户信息数据
  177. userData: {
  178. oid: '',
  179. avatar: '', //头像
  180. username: '', //用户名
  181. sex: '', //用户性别
  182. school: '', //学校
  183. spe: '', //专业
  184. rankl: '', //职称
  185. brief: '', //用户简介
  186. }
  187. };
  188. },
  189. // computed: {
  190. // startDate() {
  191. // return this.getDate('start');
  192. // },
  193. // endDate() {
  194. // return this.getDate('end');
  195. // }
  196. // },
  197. methods: {
  198. // 上传图片
  199. updateava() {
  200. let that = this
  201. uni.chooseImage({
  202. count: 1, // 图片数量
  203. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  204. sourceType: ['album', 'camera'], //从相册选择或者拍照
  205. success: (res) => {
  206. const tempFilePaths = res.tempFilePaths[0];
  207. const uploadTask = uni.uploadFile({
  208. url: 'http://139.159.246.165:7006/img', // post请求地址
  209. filePath: tempFilePaths,
  210. name: 'file', // 待确认
  211. header: {
  212. // 不要写这个不然报错
  213. // 'Content-Type': 'multipart/form-data',
  214. },
  215. formData: {
  216. // 携带的用户数据
  217. // userId: that.$store.getters.getUser._id, // 用户ID
  218. },
  219. success: function(res) {
  220. // console.log(res);
  221. that.userData.avatar=res.data
  222. },
  223. fail: function(uploadFileFail) {
  224. console.log('Error:', uploadFileFail.data);
  225. },
  226. complete: () => {
  227. // 接口调用结束的回调函数(调用成功、失败都会执行)
  228. // console.log('Complete:');
  229. }
  230. });
  231. }
  232. });
  233. },
  234. // 获取渲染数据
  235. getData() {
  236. const value = this.$store.state.user.openid;
  237. if (value == '') return
  238. // console.log('????', this.$store.state.user.openid);
  239. this.$request('/selectUserInfo', "POST", {
  240. openid: this.$store.state.user.openid
  241. }).then(res => {
  242. // 假如简介为null
  243. if(!res[0][0].brief){
  244. res[0][0].brief=''
  245. }
  246. // console.log('获取渲染数据', res[0][0]);
  247. this.userData = res[0][0]
  248. })
  249. },
  250. // 取消操作
  251. closePopup() {
  252. this.showPopup = false;
  253. },
  254. // 确认操作
  255. conf() {
  256. this.showPopup = false;
  257. this.showPopupConfirm = true
  258. console.log(' this.userData', this.userData);
  259. this.$request('/updateUserInfo', "POST", this.userData).then(res => {
  260. // console.log('this', this);
  261. this.$request('/selectUserInfo', 'POST', {
  262. oId: this.$store.state.user.openid
  263. }).then(res => {
  264. console.log('获取caozuo', res[0][0]);
  265. this.$store.dispatch('asyncUpdateUser', res[0][0])
  266. })
  267. setTimeout(() => {
  268. this.showPopupConfirm = false
  269. this.getData()
  270. }, 1500)
  271. })
  272. },
  273. // 点击保存修改
  274. saveInfo() {
  275. const value = this.$store.state.user.openid;
  276. if (value == '') return uni.showToast({
  277. title: '未登录',
  278. icon: 'none'
  279. })
  280. if (!this.userData.username) {
  281. return uni.showToast({
  282. title: '昵称不能为空',
  283. icon: 'none'
  284. })
  285. }
  286. this.showPopup = true
  287. },
  288. // 选择用户性别
  289. handelGender(e) {
  290. console.log(e);
  291. this.userData.sex = e.detail.value
  292. },
  293. // 学校
  294. handelSchool(e) {
  295. console.log(e);
  296. this.userData.school = this.schoolList[e.detail.value]
  297. },
  298. // 专业
  299. handelspe(e) {
  300. console.log('handelspe', e);
  301. this.userData.spe = this.speList[e.detail.value]
  302. console.log('???', this.userData.spe);
  303. },
  304. // 职位
  305. handelrank(e) {
  306. console.log(e);
  307. this.userData.rankl = this.rankList[e.detail.value]
  308. },
  309. // 兴趣
  310. handeHobby(e) {
  311. this.userData.tag = e.detail.value
  312. },
  313. // 清除vuex的数据
  314. gotoLogin() {
  315. let user = {
  316. openid: '',
  317. avatar: '', //头像
  318. username: '', //用户名
  319. sex: '', //用户性别
  320. school: '', //学校
  321. spe: '', //专业
  322. rankl: '', //职称
  323. brief: '', //用户简介
  324. }
  325. this.$store.dispatch('asyncUpdateUser', user)
  326. uni.navigateTo({
  327. url: '/pages/login_Wechat/login_Wechat'
  328. })
  329. // 清除本页面数据
  330. this.userData = {}
  331. },
  332. },
  333. onReady() {
  334. console.log(this.$store.state);
  335. this.getData()
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. .mask {
  341. position: fixed;
  342. top: 0;
  343. left: 0;
  344. width: 100%;
  345. height: 100%;
  346. background-color: rgba(0, 0, 0, 0.3);
  347. z-index: 999;
  348. overflow: hidden;
  349. // display: none;
  350. }
  351. .popup-container {
  352. position: fixed;
  353. top: 50%;
  354. left: 50%;
  355. transform: translate(-50%, -50%);
  356. width: 520rpx;
  357. height: 260rpx;
  358. z-index: 1000;
  359. // display: none;
  360. .popup {
  361. width: 100%;
  362. height: 100%;
  363. display: flex;
  364. flex-direction: column;
  365. background-color: #fff;
  366. border-radius: 16rpx;
  367. overflow: hidden;
  368. .header {
  369. flex: 1;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. flex-direction: column;
  374. margin-top: 24px;
  375. font-size: 34rpx;
  376. font-weight: 600;
  377. image {
  378. width: 150rpx;
  379. height: 150rpx;
  380. margin-top: 15px;
  381. margin-bottom: 15px;
  382. }
  383. }
  384. .footer {
  385. width: 100%;
  386. display: flex;
  387. overflow: hidden;
  388. .cancel-btn {
  389. width: 50%;
  390. height: 100rpx;
  391. background-color: #F7F7F7;
  392. color: #000;
  393. font-size: 34rpx;
  394. text-align: center;
  395. border-bottom-left-radius: 16rpx;
  396. line-height: 50px;
  397. }
  398. .confirm-btn {
  399. width: 50%;
  400. height: 100rpx;
  401. background-color: #0081FE;
  402. color: #fff;
  403. font-size: 34rpx;
  404. text-align: center;
  405. line-height: 50px;
  406. }
  407. }
  408. }
  409. }
  410. .edit_title {
  411. display: flex;
  412. align-items: center;
  413. font-size: 32rpx;
  414. }
  415. .editBox {
  416. width: 100%;
  417. // height: 800rpx;
  418. display: flex;
  419. flex-direction: column;
  420. background-color: #fff;
  421. border-top: 1px solid #E7E7E7;
  422. padding: 0 18px;
  423. .edit_avatar {
  424. height: 164rpx;
  425. display: flex;
  426. justify-content: space-between;
  427. .userAvatar {
  428. display: flex;
  429. align-items: center;
  430. image {
  431. width: 120rpx;
  432. height: 120rpx;
  433. }
  434. }
  435. }
  436. .setName {
  437. display: flex;
  438. justify-content: space-between;
  439. height: 92rpx;
  440. border-top: 1px solid #E7E7E7;
  441. .input_details {
  442. display: flex;
  443. align-items: center;
  444. flex-direction: row;
  445. .nickname {
  446. width: 350rpx;
  447. text-align: end;
  448. // padding-right: 10rpx;
  449. // margin-right: 10rpx;
  450. font-size: 28rpx;
  451. color: rgb(153, 153, 153);
  452. }
  453. }
  454. }
  455. .setPicker {
  456. height: 92rpx;
  457. border-top: 1px solid #E7E7E7;
  458. .content {
  459. height: 92rpx;
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. .input_details {
  464. display: flex;
  465. align-items: center;
  466. .details {
  467. display: flex;
  468. flex-direction: row;
  469. .text {
  470. font-size: 28rpx;
  471. color: rgb(153, 153, 153);
  472. }
  473. }
  474. .arrow {
  475. display: flex;
  476. image {
  477. width: 32rpx;
  478. height: 32rpx;
  479. }
  480. }
  481. }
  482. }
  483. }
  484. .setIntro {
  485. display: flex;
  486. flex-direction: column;
  487. justify-content: space-evenly;
  488. height: 230rpx;
  489. border-top: 1px solid #E7E7E7;
  490. .input_details {
  491. display: flex;
  492. align-items: center;
  493. .selfdomIntro {
  494. width: 100%;
  495. height: 120rpx;
  496. textarea {
  497. width: 100%;
  498. height: 120rpx;
  499. font-size: 28rpx;
  500. color: rgb(153, 153, 153);
  501. }
  502. }
  503. }
  504. }
  505. }
  506. .btnBox {
  507. position: absolute;
  508. margin: 0 85rpx;
  509. bottom: 40px;
  510. .btn {
  511. button {
  512. width: 580rpx;
  513. height: 88rpx;
  514. border: none;
  515. border-radius: 100rpx;
  516. border: 1px solid lightgray;
  517. font-size: 36rpx;
  518. display: flex;
  519. justify-content: center;
  520. align-items: center;
  521. color: #545454;
  522. text-align: center;
  523. &:first-child {
  524. background-color: rgb(0, 86, 168);
  525. color: white;
  526. margin-bottom: 24rpx;
  527. }
  528. &::after {
  529. border: none;
  530. }
  531. }
  532. }
  533. }
  534. </style>