contact.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // import Notify from '../../dist/notify/notify';
  2. const { fetchGraphql } = require('../../../utils/util.js');
  3. const { userbyid, updateuser } = require('../../../config/gql.js');
  4. const app = getApp();
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. },
  11. lifetimes: {
  12. attached() {
  13. fetchGraphql(userbyid, { id: app.globalData.userID }, 'user', 'userbyid', this).then(user => {
  14. this.setData({
  15. phone: user.telephone,
  16. name: user.nickname,
  17. loading: false
  18. })
  19. });
  20. }
  21. },
  22. data: {
  23. loading: true,
  24. phone: '',
  25. name: ''
  26. },
  27. methods: {
  28. phoneInput: function (e) {
  29. this.setData({
  30. phone: e.detail
  31. })
  32. },
  33. nameInput: function (e) {
  34. this.setData({
  35. name: e.detail
  36. })
  37. },
  38. submit: function() {
  39. let {name, phone} = this.data;
  40. if(name && phone) {
  41. fetchGraphql(updateuser,
  42. {
  43. id: app.globalData.userID,
  44. telephone: phone,
  45. nickname: name,
  46. updatedAt: Date.now()
  47. },
  48. null,
  49. 'updateuser',
  50. null
  51. )
  52. .then(user => {
  53. console.log(user);
  54. wx.showToast({
  55. title: '修改成功',
  56. icon: 'success'
  57. });
  58. });
  59. } else {
  60. wx.showToast({
  61. title: '无效的姓名或联系方式',
  62. icon: 'none',
  63. duration: 1000
  64. })
  65. }
  66. },
  67. reset: function() {
  68. this.setData({
  69. name: '',
  70. phone: ''
  71. })
  72. }
  73. }
  74. });