index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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: 0,
  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. this.setData({
  77. currentTab: e.currentTarget.dataset.current
  78. });
  79. },
  80. bindPickerChange: function (e) {
  81. this.setData({
  82. index: e.detail.value
  83. });
  84. },
  85. subCash: function (e) {
  86. let that = this,
  87. value = e.detail.value;
  88. if (that.data.currentTab == 0) { //银行卡
  89. if (value.name.length == 0) return app.Tips({
  90. title: '请填写持卡人姓名'
  91. });
  92. if (value.cardnum.length == 0) return app.Tips({
  93. title: '请填写卡号'
  94. });
  95. if (that.data.index == 0) return app.Tips({
  96. title: "请选择银行"
  97. });
  98. value.extract_type = 'bank';
  99. value.bankname = that.data.array[that.data.index];
  100. } else if (that.data.currentTab == 1) { //微信
  101. value.extract_type = 'weixin';
  102. if (value.name.length == 0) return app.Tips({
  103. title: '请填写微信号'
  104. });
  105. value.weixin = value.name;
  106. } else if (that.data.currentTab == 2) { //支付宝
  107. value.extract_type = 'alipay';
  108. if (value.name.length == 0) return app.Tips({
  109. title: '请填写账号'
  110. });
  111. value.alipay_code = value.name;
  112. }
  113. if (value.money.length == 0) return app.Tips({
  114. title: '请填写提现金额'
  115. });
  116. if (Number(value.money) > Number(that.data.commissionCount)) return app.Tips({
  117. title: '提现金额不能大于' + that.data.commissionCount
  118. });
  119. extractCash(value).then(res => {
  120. that.getUserInfo();
  121. return app.Tips({
  122. title: res.msg,
  123. icon: 'success'
  124. });
  125. }).catch(err => {
  126. return app.Tips({
  127. title: err
  128. });
  129. });
  130. },
  131. /**
  132. * 生命周期函数--监听页面初次渲染完成
  133. */
  134. onReady: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面显示
  138. */
  139. onShow: function () {
  140. if (app.globalData.isLog && this.data.isClone) {
  141. this.getUserInfo();
  142. this.getUserExtractBank();
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide: function () {
  149. this.setData({
  150. isClone: true
  151. });
  152. },
  153. /**
  154. * 生命周期函数--监听页面卸载
  155. */
  156. onUnload: function () {
  157. },
  158. /**
  159. * 页面相关事件处理函数--监听用户下拉动作
  160. */
  161. onPullDownRefresh: function () {
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom: function () {
  167. },
  168. /**
  169. * 用户点击右上角分享
  170. */
  171. onShareAppMessage: function () {
  172. }
  173. })