apply.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. isData: false,
  8. words: {},
  9. payment: 20,
  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.getDealerWithdraw();
  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. getDealerWithdraw() {
  43. let _this = this;
  44. App._get('user.dealer/withdraw', {}, (result) => {
  45. let data = result.data;
  46. data.isData = true;
  47. // 设置当前页面标题
  48. wx.setNavigationBarTitle({
  49. title: data.words.withdraw_apply.title.value
  50. });
  51. // 默认提现方式
  52. data['payment'] = data.settlement.pay_type[0];
  53. _this.setData(data);
  54. });
  55. },
  56. /**
  57. * 提交申请
  58. */
  59. onFormSubmit(e) {
  60. let _this = this,
  61. values = e.detail.value,
  62. words = _this.data.words.withdraw_apply.words;
  63. // 验证可提现佣金
  64. if (_this.data.dealer.money <= 0) {
  65. App.showError('当前没有' + words.capital.value);
  66. return false;
  67. }
  68. // 验证提现金额
  69. if (!values.money || values.money.length < 1) {
  70. App.showError('请填写' + words.money.value);
  71. return false;
  72. }
  73. // 按钮禁用
  74. _this.setData({
  75. disabled: true
  76. });
  77. // 提现方式
  78. values['pay_type'] = _this.data.payment;
  79. // 数据提交
  80. const onCallback = () => {
  81. App._post_form('user.dealer.withdraw/submit', {
  82. data: JSON.stringify(values)
  83. }, (result) => {
  84. // 提交成功
  85. App.showError(result.msg, () => {
  86. wx.navigateTo({
  87. url: '../list/list',
  88. })
  89. });
  90. }, null, () => {
  91. // 解除按钮禁用
  92. _this.setData({
  93. disabled: false
  94. });
  95. });
  96. };
  97. // 确认是否提交
  98. wx.showModal({
  99. // title: '友情提示',
  100. content: '确定提交提现申请吗?请确认填写无误',
  101. showCancel: true,
  102. success(res) {
  103. if (res.confirm) {
  104. // 请求用户订阅消息
  105. _this._onRequestSubscribeMessage(onCallback);
  106. } else if (res.cancel) {
  107. // 解除按钮禁用
  108. _this.setData({
  109. disabled: false
  110. });
  111. }
  112. }
  113. });
  114. },
  115. /**
  116. * 订阅消息 => [提现通知]
  117. */
  118. _onRequestSubscribeMessage(callback) {
  119. let _this = this,
  120. tmplIds = [],
  121. dealerSubmsg = _this.data.submsgSetting.dealer;
  122. dealerSubmsg.withdraw_01.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_01.template_id);
  123. dealerSubmsg.withdraw_02.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_02.template_id);
  124. if (tmplIds.length == 0) {
  125. callback && callback();
  126. return;
  127. }
  128. wx.requestSubscribeMessage({
  129. tmplIds,
  130. success(res) {},
  131. fail(res) {},
  132. complete(res) {
  133. callback && callback();
  134. },
  135. });
  136. },
  137. /**
  138. * 切换提现方式
  139. */
  140. toggleChecked(e) {
  141. let _this = this;
  142. _this.setData({
  143. payment: e.currentTarget.dataset.payment
  144. });
  145. },
  146. })