apply.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const App = getApp();
  2. const Dialog = require('../../../components/dialog/dialog');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. is_read: false,
  9. disabled: false,
  10. submsgSetting: {}, // 订阅消息配置
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. let _this = this;
  17. // 获取订阅消息配置
  18. _this.getSubmsgSetting();
  19. },
  20. /**
  21. * 生命周期函数--监听页面显示
  22. */
  23. onShow() {
  24. let _this = this;
  25. // 获取分销商申请状态
  26. _this.getApplyState();
  27. },
  28. /**
  29. * 获取订阅消息配置
  30. */
  31. getSubmsgSetting() {
  32. let _this = this;
  33. App._get('wxapp.submsg/setting', {}, (result) => {
  34. _this.setData({
  35. submsgSetting: result.data.setting
  36. });
  37. });
  38. },
  39. /**
  40. * 获取分销商申请状态
  41. */
  42. getApplyState() {
  43. let _this = this;
  44. App._get('user.dealer/apply', {
  45. referee_id: _this.getRefereeid()
  46. }, (result) => {
  47. let data = result.data;
  48. // 当前是否已经为分销商
  49. if (data.is_dealer) {
  50. wx.redirectTo({
  51. url: '../index/index'
  52. });
  53. }
  54. // 设置当前页面标题
  55. wx.setNavigationBarTitle({
  56. title: data.words.apply.title.value
  57. });
  58. data.isData = true;
  59. _this.setData(data);
  60. });
  61. },
  62. /**
  63. * 显示申请协议
  64. */
  65. toggleApplyLicense() {
  66. Dialog({
  67. title: '申请协议',
  68. message: this.data.license,
  69. selector: '#zan-base-dialog',
  70. isScroll: true, // 滚动
  71. buttons: [{
  72. text: '我已阅读',
  73. color: 'red',
  74. type: 'cash'
  75. }]
  76. }).then(() => {
  77. // console.log('=== dialog resolve ===', 'type: confirm');
  78. });
  79. },
  80. /**
  81. * 已阅读
  82. */
  83. toggleSetRead() {
  84. let _this = this;
  85. _this.setData({
  86. is_read: !this.data.is_read
  87. });
  88. },
  89. /**
  90. * 提交申请
  91. */
  92. onFormSubmit(e) {
  93. let _this = this,
  94. values = e.detail.value;
  95. // 验证姓名
  96. if (!values.name || values.name.length < 1) {
  97. App.showError('请填写姓名');
  98. return false;
  99. }
  100. // 验证手机号
  101. if (!/^\+?\d[\d -]{8,12}\d/.test(values.mobile)) {
  102. App.showError('手机号格式不正确');
  103. return false;
  104. }
  105. // 验证是否阅读协议
  106. if (!_this.data.is_read) {
  107. App.showError('请先阅读分销商申请协议');
  108. return false;
  109. }
  110. // 按钮禁用
  111. _this.setData({
  112. disabled: true
  113. });
  114. // 数据提交
  115. App._post_form('user.dealer.apply/submit', values, () => {
  116. // 获取分销商申请状态
  117. _this.getApplyState();
  118. }, null, () => {
  119. // 解除按钮禁用
  120. _this.setData({
  121. disabled: false
  122. });
  123. });
  124. },
  125. /**
  126. * 去商城逛逛
  127. */
  128. navigationToIndex(e) {
  129. // 跳转到首页
  130. wx.switchTab({
  131. url: '/pages/index/index',
  132. })
  133. },
  134. /**
  135. * 订阅消息通知
  136. */
  137. onSubMsg() {
  138. let _this = this;
  139. let tmplItem = _this.data.submsgSetting.dealer.apply.template_id;
  140. if (tmplItem.length > 0) {
  141. wx.requestSubscribeMessage({
  142. tmplIds: [tmplItem],
  143. success(res) {},
  144. fail(res) {},
  145. complete(res) {},
  146. });
  147. }
  148. },
  149. /**
  150. * 获取推荐人id
  151. */
  152. getRefereeid() {
  153. return wx.getStorageSync('referee_id');
  154. },
  155. })