changephone.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // subpackages/changephone/changephone.js
  2. // import { models, db } from '../../utils/cloudbase.js'
  3. import { getDB, getModels, getCommand, getTempFileURLs, getClient } from '../../utils/cloudbase.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. phone: '',
  10. },
  11. onLoad() {
  12. const userInfo = wx.getStorageSync('userInfo')
  13. this.setData({
  14. phone: userInfo.phone
  15. })
  16. },
  17. // 监听手机号输入框
  18. onPhoneInput(e) {
  19. this.setData({
  20. phone: e.detail.value
  21. });
  22. },
  23. // 确定
  24. async bindingevents() {
  25. let userInfo = wx.getStorageSync('userInfo')
  26. const models = await getModels()
  27. console.log(userInfo._id, this.data.phone, 'userInfo._id');
  28. const { data } = await models.wx_user.update({
  29. data: {
  30. phone: this.data.phone, // 手机号
  31. },
  32. filter: {
  33. where: {
  34. $and: [
  35. {
  36. _id: {
  37. $eq: userInfo._id, // 推荐传入_id数据标识进行操作
  38. },
  39. },
  40. ]
  41. }
  42. },
  43. envType: "prod",
  44. });
  45. if(data.count >= 1) {
  46. // 更新本地缓存里的 userInfo
  47. userInfo.phone = this.data.phone;
  48. wx.setStorageSync('userInfo', userInfo);
  49. wx.showToast({
  50. title: '修改成功',
  51. icon: 'success',
  52. duration: 1500,
  53. success() {
  54. // 延迟一点时间再返回上一页
  55. setTimeout(() => {
  56. wx.navigateBack();
  57. }, 1500);
  58. }
  59. });
  60. } else {
  61. wx.showToast({
  62. title: '修改失败',
  63. icon: 'none',
  64. duration: 1500
  65. });
  66. }
  67. }
  68. })