suggestions.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // pages/suggestions/suggestions.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. username: '',
  9. phoneNumber: '',
  10. content: ''
  11. },
  12. bindInput(e) {
  13. const { key } = e.currentTarget.dataset;
  14. const { value } = e.detail;
  15. this.setData({
  16. [key]: value
  17. })
  18. },
  19. submit(e) {
  20. let errorMsg = '';
  21. if (!this.data.username) {
  22. errorMsg = '请输入您的姓名';
  23. } else if (!this.data.phoneNumber) {
  24. errorMsg = '请输入您的联系电话';
  25. } else if (!this.data.content) {
  26. errorMsg = '请输入您的建议';
  27. }
  28. if (errorMsg) {
  29. wx.showToast({
  30. title: errorMsg,
  31. icon: 'none',
  32. duration: 2000
  33. })
  34. return;
  35. }
  36. app.$http.post('/suggest/add', this.data).then(({ status, msg }) => {
  37. if (status === 0) {
  38. wx.showToast({
  39. title: msg,
  40. icon: 'none',
  41. duration: 2000
  42. })
  43. wx.navigateBack({
  44. delta: 1
  45. })
  46. }
  47. })
  48. },
  49. })