index.js 3.7 KB

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