index.js 3.6 KB

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