index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. app.updateUnread(res.data.notice.toString());
  53. });
  54. },
  55. swichNav: function (e) {
  56. this.setData({ currentTab: e.currentTarget.dataset.current });
  57. },
  58. bindPickerChange: function (e) {
  59. this.setData({ index: e.detail.value });
  60. },
  61. subCash: function (e) {
  62. let that = this, value = e.detail.value;
  63. if (that.data.currentTab == 0){//银行卡
  64. if (value.name.length == 0) return app.Tips({title:'请填写持卡人姓名'});
  65. if (value.cardnum.length == 0) return app.Tips({title:'请填写卡号'});
  66. if (that.data.index == 0) return app.Tips({title:"请选择银行"});
  67. value.extract_type = 'bank';
  68. value.bankname = that.data.array[that.data.index];
  69. } else if (that.data.currentTab == 1) {//微信
  70. value.extract_type = 'weixin';
  71. if (value.name.length == 0) return app.Tips({ title: '请填写微信号' });
  72. value.weixin = value.name;
  73. } else if (that.data.currentTab == 2) {//支付宝
  74. value.extract_type = 'alipay';
  75. if (value.name.length == 0) return app.Tips({title:'请填写账号'});
  76. value.alipay_code = value.name;
  77. }
  78. if (value.money.length == 0) return app.Tips({title:'请填写提现金额'});
  79. if (Number(value.money) > Number(that.data.commissionCount)) return app.Tips({ title: '提现金额不能大于' + that.data.commissionCount});
  80. extractCash(value).then(res=>{
  81. that.getUserInfo();
  82. return app.Tips({ title: res.msg, icon: 'success' });
  83. }).catch(err=>{
  84. return app.Tips({ title: err });
  85. });
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. if(app.globalData.isLog && this.data.isClone){
  97. this.getUserInfo();
  98. this.getUserExtractBank();
  99. }
  100. },
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. this.setData({isClone:true});
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })