index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <view class="wrap">
  5. <view class="user_thumb">
  6. <image class="thumb" :src="userInfo.thumb"></image>
  7. </view>
  8. <view class="user_info">
  9. <view class="item">
  10. <view class="item_l">
  11. <view class="label">昵称</view>
  12. <view class="wenzi">{{ userInfo.nickname }}</view>
  13. </view>
  14. </view>
  15. <view class="item">
  16. <view class="item_l">
  17. <view class="label">手机</view>
  18. <view class="wenzi">{{ userInfo.phone ? userInfo.phone : '未绑定' }}</view>
  19. </view>
  20. <view class="item_r red" @tap="onShowChangePhone">更换手机号</view>
  21. </view>
  22. <view class="item">
  23. <view class="item_l">
  24. <view class="label">性别</view>
  25. <view class="wenzi">{{ userInfo.sex == 0 ? '保密' : userInfo.sex == 1 ? '男' : '女' }}</view>
  26. </view>
  27. </view>
  28. <view class="item">
  29. <view class="item_l">
  30. <view class="label">生日</view>
  31. <view class="wenzi">{{ userInfo.birthday ? userInfo.birthday : '未设置' }}</view>
  32. </view>
  33. <view class="item_r red" @tap="onShowBirthPop">修改</view>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 更换手机号 -->
  38. <van-overlay class-style="background: rgba(0,0,0,.3);" :show="showPhonePop">
  39. <view class="phoneWrap">
  40. <view class="title">更换手机号</view>
  41. <view class="form_wrap">
  42. <view class="form_item">
  43. <view class="item_label">新手机号码</view>
  44. <view class="item_file">
  45. <van-field :value="phone" placeholder="请输入手机号码" :border="false" @change="getPhone" />
  46. <button hover-class="none" class="btn_code" :disabled="codeLoading" :loading="codeLoading" @tap="sendCode">{{ codeBtnName }}</button>
  47. </view>
  48. </view>
  49. <view class="form_item">
  50. <view class="item_label">手机验证码</view>
  51. <view class="item_file">
  52. <van-field :value="code" placeholder="请输入手机验证码" :border="false" @change="getPhoneCode" />
  53. </view>
  54. </view>
  55. </view>
  56. <view class="btns">
  57. <view class="btn cancel" @tap="onCloseChangePhone">取消</view>
  58. <view class="btn" @tap="onConfirmChangePhone">确定</view>
  59. </view>
  60. </view>
  61. </van-overlay>
  62. <!-- 修改生日 -->
  63. <van-popup :show="showBirthPop" position="bottom">
  64. <van-datetime-picker type="date" :value="currentBirth" :max-date="maxDate" :min-date="minDate" @confirm="confirmBirthPop" @cancel="closeBirthPop" />
  65. </van-popup>
  66. </view>
  67. </template>
  68. <script>
  69. // index.js
  70. let myPro = require('../../../utils/wxRequest.js');
  71. let util = require('../../../utils/util.js');
  72. export default {
  73. data() {
  74. return {
  75. userInfo: null,
  76. showPhonePop: false,
  77. codeBtnName: '获取验证码',
  78. delyTime: 60,
  79. // 单位s
  80. codeLoading: false,
  81. showBirthPop: false,
  82. maxDate: new Date().getTime(),
  83. minDate: '',
  84. sex: '',
  85. currentBirth: '',
  86. phone: '',
  87. code: ''
  88. };
  89. },
  90. onLoad: function (options) {
  91. // Do some initialize when page load.
  92. },
  93. onShow: function () {
  94. // Do something when page show.
  95. let that = this; // 生日的可选最小值 当前年份前50年
  96. let minYear = new Date().getFullYear() - 50;
  97. let str = minYear + '-' + '01-01';
  98. that.setData({
  99. minDate: new Date(str).getTime()
  100. }); // 获取用户信息
  101. that.getUrserInfo();
  102. },
  103. onReady: function () {
  104. // Do something when page ready.
  105. },
  106. onHide: function () {
  107. // Do something when page hide.
  108. },
  109. onUnload: function () {
  110. // Do something when page close.
  111. },
  112. onPullDownRefresh: function () {
  113. // Do something when pull down.
  114. },
  115. onReachBottom: function () {
  116. // Do something when page reach bottom.
  117. },
  118. onPageScroll: function () {
  119. // Do something when page scroll
  120. },
  121. onResize: function () {
  122. // Do something when page resize
  123. },
  124. methods: {
  125. // 更改性别 弃用
  126. onChangeSex(event) {
  127. let that = this;
  128. that.setData({
  129. sex: event.detail
  130. });
  131. },
  132. // 获取用户信息
  133. getUrserInfo() {
  134. let that = this;
  135. myPro
  136. .wxRequest('user/v2/userinfo', 'GET', {})
  137. .then((res) => {
  138. that.setData({
  139. userInfo: res.result
  140. }); // 用户之前存过生日
  141. if (res.result.birthday) {
  142. let birthStr = res.result.birthday;
  143. that.setData({
  144. currentBirth: new Date(birthStr.replace(/-/g, '/')).getTime()
  145. });
  146. } else {
  147. that.setData({
  148. currentBirth: new Date().getTime()
  149. });
  150. }
  151. })
  152. .catch((err) => {
  153. console.log('报错信息', err);
  154. uni.showToast({
  155. title: err,
  156. icon: 'none'
  157. });
  158. });
  159. },
  160. // 打开更改手机号弹层
  161. onShowChangePhone() {
  162. let that = this;
  163. that.setData({
  164. showPhonePop: true
  165. });
  166. },
  167. // 关闭
  168. onCloseChangePhone() {
  169. let that = this;
  170. that.setData({
  171. showPhonePop: false
  172. });
  173. },
  174. // 获取输入信息 手机号
  175. getPhone: function (event) {
  176. let that = this;
  177. that.setData({
  178. phone: event.detail
  179. });
  180. },
  181. // 发送验证码
  182. sendCode() {
  183. let that = this;
  184. if (!that.phone || !/^1[3456789]\d{9}$/.test(that.phone)) {
  185. uni.showToast({
  186. title: '手机号有误,请重新填写',
  187. icon: 'none'
  188. });
  189. return;
  190. }
  191. let params = {
  192. phone: that.phone
  193. };
  194. myPro
  195. .wxRequest('user/send/verify-code', 'POST', params)
  196. .then((res) => {
  197. uni.showToast({
  198. title: res.msg,
  199. icon: 'none'
  200. });
  201. that.setData({
  202. codeBtnName: that.delyTime + 's',
  203. delyTime: that.delyTime,
  204. codeLoading: true
  205. });
  206. let s = setInterval(function () {
  207. let dely1 = parseInt(that.delyTime) - 1; // console.log(dely1);
  208. that.setData({
  209. codeBtnName: dely1 + 's',
  210. delyTime: dely1
  211. });
  212. if (dely1 == 0) {
  213. clearInterval(s);
  214. that.setData({
  215. codeBtnName: '获取验证码',
  216. delyTime: that.delyTime,
  217. codeLoading: false
  218. });
  219. }
  220. }, 1000);
  221. })
  222. .catch((err) => {
  223. that.setData({
  224. codeLoading: false
  225. });
  226. console.log('报错信息');
  227. uni.showToast({
  228. title: err,
  229. icon: 'none'
  230. });
  231. });
  232. },
  233. // 获取输入信息 验证码
  234. getPhoneCode: function (event) {
  235. let that = this;
  236. that.setData({
  237. code: event.detail
  238. });
  239. },
  240. // 更改手机号
  241. onConfirmChangePhone() {
  242. let that = this; // return;
  243. if (!that.phone || !/^1[3456789]\d{9}$/.test(that.phone)) {
  244. uni.showToast({
  245. title: '手机号有误,请重新填写',
  246. icon: 'none'
  247. });
  248. return;
  249. }
  250. if (!that.code) {
  251. uni.showToast({
  252. title: '请填写验证码',
  253. icon: 'none'
  254. });
  255. return;
  256. }
  257. let params = {
  258. phone: that.phone,
  259. code: that.code
  260. };
  261. myPro
  262. .wxRequest('user/v2/editphone', 'POST', params)
  263. .then((res) => {
  264. uni.showToast({
  265. title: res.msg,
  266. icon: 'none'
  267. });
  268. that.setData({
  269. showPhonePop: false
  270. }); // 更新用户信息
  271. that.getUrserInfo();
  272. })
  273. .catch((err) => {
  274. console.log('报错信息', err);
  275. uni.showToast({
  276. title: err,
  277. icon: 'none'
  278. });
  279. });
  280. },
  281. // 打开生日弹层
  282. onShowBirthPop() {
  283. let that = this;
  284. that.setData({
  285. showBirthPop: true
  286. });
  287. },
  288. // 关闭生日弹层
  289. closeBirthPop() {
  290. let that = this;
  291. that.setData({
  292. showBirthPop: false
  293. });
  294. },
  295. // 选择生日
  296. confirmBirthPop(event) {
  297. console.log('event===', event);
  298. let that = this;
  299. let selectTime = new Date(event.detail);
  300. let birthStr = util.formatTime(selectTime, 1); // 修改生日
  301. let params = {
  302. birthday: birthStr
  303. };
  304. myPro
  305. .wxRequest('user/v2/editBirthday', 'POST', params)
  306. .then((res) => {
  307. uni.showToast({
  308. title: res.msg,
  309. icon: 'none'
  310. });
  311. that.setData({
  312. showBirthPop: false
  313. }); // 更新用户信息
  314. that.getUrserInfo();
  315. })
  316. .catch((err) => {
  317. console.log('报错信息', err);
  318. uni.showToast({
  319. title: err,
  320. icon: 'none'
  321. });
  322. });
  323. }
  324. }
  325. };
  326. </script>
  327. <style>
  328. /**index.wxss**/
  329. .wrap {
  330. min-height: 100vh;
  331. background: #f6f6f6;
  332. }
  333. .user_thumb {
  334. padding: 30rpx 0 40rpx;
  335. background: #ffffff;
  336. }
  337. .user_thumb .thumb {
  338. width: 150rpx;
  339. height: 150rpx;
  340. border-radius: 50%;
  341. display: block;
  342. margin: 0 auto;
  343. }
  344. .user_info {
  345. margin-top: 20rpx;
  346. padding-left: 30rpx;
  347. background: #ffffff;
  348. }
  349. .user_info .item {
  350. display: flex;
  351. align-items: center;
  352. justify-content: space-between;
  353. padding-right: 30rpx;
  354. min-height: 110rpx;
  355. font-size: 28rpx;
  356. color: #000000;
  357. border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  358. }
  359. .user_info .item:last-child {
  360. border: 0 none;
  361. }
  362. .user_info .item .item_l {
  363. display: flex;
  364. align-items: center;
  365. }
  366. .user_info .item .label {
  367. width: 130rpx;
  368. }
  369. .user_info .item .red {
  370. color: #ed8c17;
  371. }
  372. .btn_wrap {
  373. margin-top: 40rpx;
  374. }
  375. .btn_wrap .btn {
  376. width: 690rpx;
  377. height: 100rpx;
  378. margin: 0 auto;
  379. background: #d54c43;
  380. border-radius: 50rpx;
  381. font-size: 34rpx;
  382. color: #ffffff;
  383. display: flex;
  384. align-items: center;
  385. justify-content: center;
  386. }
  387. /* 改手机号 */
  388. .phoneWrap {
  389. width: 600rpx;
  390. background: #ffffff;
  391. border-radius: 40rpx;
  392. position: absolute;
  393. top: 50%;
  394. left: 50%;
  395. transform: translate(-50%, -50%);
  396. }
  397. .phoneWrap .title {
  398. font-size: 30rpx;
  399. text-align: center;
  400. color: #000000;
  401. padding: 20rpx 0 0;
  402. }
  403. .phoneWrap .btns {
  404. display: flex;
  405. align-items: center;
  406. justify-content: center;
  407. padding: 30rpx 0;
  408. }
  409. .phoneWrap .btns .btn {
  410. flex: 1;
  411. text-align: center;
  412. color: #d54c43;
  413. }
  414. .phoneWrap .btns .btn.cancel {
  415. color: rgba(51, 51, 51, 0.87);
  416. }
  417. .form_wrap {
  418. padding: 0rpx 50rpx 0rpx;
  419. }
  420. .form_item {
  421. font-size: 30rpx;
  422. color: #000000;
  423. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  424. padding-top: 30rpx;
  425. }
  426. .form_item .item_label {
  427. text-align: left;
  428. }
  429. .form_item .item_file {
  430. font-size: 28rpx;
  431. display: flex;
  432. align-items: center;
  433. justify-content: space-between;
  434. }
  435. .form_item .item_file van-field {
  436. flex: 1;
  437. }
  438. .form_item .item_file .van-cell {
  439. padding-left: 0;
  440. background: unset;
  441. }
  442. .btn_code {
  443. width: auto !important;
  444. padding: 0;
  445. margin: 0;
  446. font-size: 26rpx;
  447. color: #d54c43;
  448. background: unset;
  449. line-height: unset;
  450. font-weight: normal;
  451. }
  452. </style>