index.js 3.6 KB

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