index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // pages/cash-withdrawal/index.js
  2. import {
  3. extractCash,
  4. extractBank,
  5. getUserInfo
  6. } from '../../api/user.js';
  7. const app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. parameter: {
  14. 'navbar': '1',
  15. 'return': '1',
  16. 'title': '提现',
  17. 'color': true,
  18. 'class': '0'
  19. },
  20. navList: [{
  21. 'name': '银行卡',
  22. 'icon': 'icon-yinhangqia'
  23. },
  24. {
  25. 'name': '微信',
  26. 'icon': 'icon-weixin2'
  27. },
  28. {
  29. 'name': '支付宝',
  30. 'icon': 'icon-icon34'
  31. }
  32. ],
  33. currentTab: 1,
  34. index: 0,
  35. array: [], //提现银行
  36. commissionCount: 0.00, //可提现金额
  37. minPrice: 0.0, // 最低提现金额
  38. userInfo: [],
  39. isClone: false
  40. },
  41. onLoadFun: function () {
  42. this.getUserInfo();
  43. this.getUserExtractBank();
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. },
  50. getUserExtractBank: function () {
  51. var that = this;
  52. extractBank().then(res => {
  53. var array = res.data.extractBank;
  54. array.unshift("请选择银行");
  55. that.setData({
  56. array: array,
  57. commissionCount: res.data.commissionCount,
  58. minPrice: res.data.minPrice,
  59. });
  60. });
  61. },
  62. /**
  63. * 获取个人用户信息
  64. */
  65. getUserInfo: function () {
  66. var that = this;
  67. getUserInfo().then(res => {
  68. that.setData({
  69. userInfo: res.data
  70. });
  71. // app.globalData.unread = res.data.notice
  72. app.setUnread(res.data.notice)
  73. });
  74. },
  75. swichNav: function (e) {
  76. if (e.currentTarget.dataset.current != 1) {
  77. wx.showToast({
  78. title: '暂未开放',
  79. image: '',
  80. })
  81. return
  82. }
  83. this.setData({
  84. currentTab: e.currentTarget.dataset.current
  85. });
  86. },
  87. bindPickerChange: function (e) {
  88. this.setData({
  89. index: e.detail.value
  90. });
  91. },
  92. subCash: function (e) {
  93. let that = this,
  94. value = e.detail.value;
  95. if (that.data.currentTab == 0) { //银行卡
  96. if (value.name.length == 0) return app.Tips({
  97. title: '请填写持卡人姓名'
  98. });
  99. if (value.cardnum.length == 0) return app.Tips({
  100. title: '请填写卡号'
  101. });
  102. if (that.data.index == 0) return app.Tips({
  103. title: "请选择银行"
  104. });
  105. value.extract_type = 'bank';
  106. value.bankname = that.data.array[that.data.index];
  107. } else if (that.data.currentTab == 1) { //微信
  108. value.extract_type = 'weixin';
  109. if (value.name.length == 0) return app.Tips({
  110. title: '请填写微信号'
  111. });
  112. value.weixin = value.name;
  113. } else if (that.data.currentTab == 2) { //支付宝
  114. value.extract_type = 'alipay';
  115. if (value.name.length == 0) return app.Tips({
  116. title: '请填写账号'
  117. });
  118. value.alipay_code = value.name;
  119. }
  120. if (value.money.length == 0) return app.Tips({
  121. title: '请填写提现金额'
  122. });
  123. if (Number(value.money) > Number(that.data.commissionCount)) return app.Tips({
  124. title: '提现金额不能大于' + that.data.commissionCount
  125. });
  126. extractCash(value).then(res => {
  127. that.getUserInfo();
  128. return app.Tips({
  129. title: res.msg,
  130. icon: 'success'
  131. });
  132. }).catch(err => {
  133. return app.Tips({
  134. title: err
  135. });
  136. });
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow: function () {
  147. if (app.globalData.isLog && this.data.isClone) {
  148. this.getUserInfo();
  149. this.getUserExtractBank();
  150. }
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. this.setData({
  157. isClone: true
  158. });
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function () {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function () {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function () {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function () {
  179. }
  180. })