transfer.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. const app = getApp()
  2. var api = require('../../utils/request');
  3. var util = require('../../utils/util');
  4. var common = require('../../utils/common');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loading: false,
  11. shopping_name:'购物积分',
  12. phone:0,
  13. disabled: false,
  14. countdown: 60,
  15. bank: {
  16. money: 0,
  17. due_money: 0,
  18. lack_money: 0,
  19. income_monney: 0,
  20. shop_money: 0
  21. },
  22. },
  23. /**
  24. * 生命周期函数--监听页面显示
  25. */
  26. onShow: function () {
  27. this.getBank();
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. this.setData({
  34. shopping_name: app.globalData.config.shopping_name
  35. })
  36. },
  37. /**
  38. * 读取我的账单
  39. */
  40. getBank: function () {
  41. let that = this;
  42. api.Get("api/v3/fastshop/bank/index", function (result) {
  43. if (result.code == 200) {
  44. that.setData({ bank: result.data });
  45. }
  46. })
  47. },
  48. /**
  49. * 申请提现
  50. */
  51. onSubmit: function (e) {
  52. let that = this;
  53. var data = e.detail.value;
  54. var isPost = false;
  55. if(util.isNull(data.money)) {
  56. wx.showModal({
  57. content: '转账金额必须填写'
  58. })
  59. } else if (util.isNull(data.safepassword)) {
  60. wx.showModal({
  61. content: '安全密码必须填写'
  62. })
  63. } else if (util.isNull(data.phone)) {
  64. wx.showModal({
  65. content: '手机号必须输入'
  66. })
  67. } else if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(data.phone))) {
  68. wx.showModal({
  69. content: '手机号格式不正确'
  70. })
  71. }else if (util.isNull(data.code)) {
  72. wx.showModal({
  73. content: '验证码必须输入'
  74. })
  75. } else if (!(/^\d{6}$/.test(data.code))) {
  76. wx.showModal({
  77. content: '验证码输入错误'
  78. })
  79. }else {
  80. if (!(/^\d+$/.test(data.money))) {
  81. wx.showModal({
  82. content: '提现金额只能输入整数'
  83. })
  84. } else {
  85. var money = parseInt(data.money);
  86. var bank = this.data.bank;
  87. if (money > bank.due_money || money == 0) {
  88. wx.showModal({
  89. content: '超出允许提现金额'
  90. })
  91. }else{
  92. isPost = true;
  93. }
  94. }
  95. }
  96. //提交数据
  97. if (isPost == true) {
  98. wx.showLoading({title: '提交申请中',mask: true})
  99. var parms = {
  100. money: data.money,
  101. code: data.code,
  102. phone: data.phone,
  103. safepassword: data.safepassword,
  104. }
  105. api.Post('api/v3/fastshop/bank/transfer', parms, function (res) {
  106. wx.hideLoading();
  107. if (res.code == 200) {
  108. wx.showModal({
  109. showCancel: false,title: '友情提示',content: res.msg,
  110. complete: function () {
  111. wx.navigateBack({ delta: 1 })
  112. }
  113. })
  114. }
  115. })
  116. }
  117. },
  118. /**
  119. * 设置输入手机号
  120. */
  121. bindPhone: function (e) {
  122. let that = this;
  123. var phone = e.detail;
  124. var isPost = true;
  125. if (util.isNull(phone)) {
  126. isPost = false;
  127. } else {
  128. if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))) {
  129. isPost = false;
  130. }
  131. }
  132. if (isPost) {
  133. that.setData({
  134. phone: phone
  135. })
  136. }
  137. },
  138. /**
  139. * 读取
  140. */
  141. getSms: function (e) {
  142. let that = this;
  143. var isPost = true;
  144. var phone = that.data.phone;
  145. if (util.isNull(phone)) {
  146. wx.showModal({
  147. content: '手机号必须输入'
  148. })
  149. isPost = false;
  150. } else {
  151. if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone))) {
  152. wx.showModal({
  153. content: '手机号格式不正确'
  154. })
  155. isPost = false;
  156. }
  157. }
  158. if (isPost) {
  159. api.Post('openapi/v1/user/getFriendPhoneCode', { phone: phone, types: 0 }, function (res) {
  160. wx.setStorageSync('session_id', res.data);
  161. wx.showModal({
  162. showCancel: false,
  163. content: '验证码已发送'
  164. })
  165. common.settime(that);
  166. that.setData({
  167. disabled: true
  168. })
  169. })
  170. }
  171. },
  172. })