form.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const WXAPI = require('apifm-wxapi')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. /**
  9. * 生命周期函数--监听页面加载
  10. */
  11. onLoad: function (options) {
  12. this.adPosition()
  13. },
  14. /**
  15. * 生命周期函数--监听页面显示
  16. */
  17. onShow: function () {
  18. const _this = this
  19. WXAPI.userDetail(wx.getStorageSync('token')).then(res => {
  20. if (res.code === 0) {
  21. _this.setData({
  22. userDetail: res.data
  23. })
  24. }
  25. })
  26. },
  27. async adPosition() {
  28. const res = await WXAPI.adPosition('fx-top-pic')
  29. if (res.code == 0) {
  30. this.setData({
  31. adPositionFxTopPic: res.data
  32. })
  33. }
  34. },
  35. bindSave(){
  36. const fx_subscribe_ids = wx.getStorageSync('fx_subscribe_ids')
  37. if (fx_subscribe_ids) {
  38. wx.requestSubscribeMessage({
  39. tmplIds: fx_subscribe_ids.split(','),
  40. success(res) {
  41. },
  42. fail(e) {
  43. console.error(e)
  44. },
  45. complete: (e) => {
  46. this.bindSaveDone()
  47. },
  48. })
  49. } else{
  50. this.bindSaveDone()
  51. }
  52. },
  53. bindSaveDone: function () {
  54. const name = this.data.name
  55. const mobile = this.data.mobile
  56. if (!name) {
  57. wx.showToast({
  58. title: '请输入真实姓名',
  59. icon: 'none'
  60. })
  61. return
  62. }
  63. if (!mobile) {
  64. wx.showToast({
  65. title: '请输入手机号码',
  66. icon: 'none'
  67. })
  68. return
  69. }
  70. WXAPI.fxApply(wx.getStorageSync('token'), name, mobile).then(res => {
  71. if (res.code != 0) {
  72. wx.showToast({
  73. title: res.msg,
  74. icon: 'none'
  75. })
  76. return
  77. }
  78. wx.redirectTo({
  79. url: "/packageFx/pages/apply/index"
  80. })
  81. })
  82. },
  83. })